genezio
Version:
Command line utility to interact with Genezio infrastructure.
38 lines (37 loc) • 1.33 kB
JavaScript
import path from "path";
import fs from "fs";
function getRandomSemVer() {
const major = Math.floor(Math.random() * 10); // Random major version between 0 and 9
const minor = Math.floor(Math.random() * 10); // Random minor version between 0 and 9
const patch = Math.floor(Math.random() * 10); // Random patch version between 0 and 9
return `${major}.${minor}.${patch}-local`;
}
export const getPackageJsonSdkGenerator = (packageName, version, sdkPath) => {
// check if package.json exists at sdkPath
const packageJsonPath = path.join(sdkPath, "package.json");
let packageJsonStr;
if (fs.existsSync(packageJsonPath)) {
// get package.json
packageJsonStr = fs.readFileSync(packageJsonPath, "utf8");
}
else {
packageJsonStr = getNodeModulePackageJson(packageName, version);
}
const packageJson = JSON.parse(packageJsonStr);
packageJson.main = "./cjs/index.js";
packageJson.module = "./esm/index.js";
return JSON.stringify(packageJson, null, 2);
};
export const getNodeModulePackageJson = (packageName, version) => `{
"name": "${packageName}",
"version": "${version || getRandomSemVer()}",
"bundleDependencies": [
"genezio-remote"
],
"description": "",
"main": "./lib/index.js",
"dependencies": {
"genezio-remote": "1.0.0"
}
}
`;