Skip to content

Commit

Permalink
Merge pull request #82 from TeselaGen/publish-beta-versions
Browse files Browse the repository at this point in the history
feat: Add publishing of beta versions
  • Loading branch information
tnrich authored Jul 9, 2024
2 parents c0f5d97 + 0749c05 commit bf8457d
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 46 deletions.
6 changes: 5 additions & 1 deletion packages/bio-parsers/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
}
},
"publish": {
"command": "node tools/scripts/publish.mjs bio-parsers {args.ver} {args.tag}",
"command": "node tools/scripts/publish.mjs bio-parsers latest",
"dependsOn": ["test", "build"]
},
"publish-beta": {
"command": "node tools/scripts/publish.mjs bio-parsers beta",
"dependsOn": ["test", "build"]
},
"test": {
Expand Down
6 changes: 5 additions & 1 deletion packages/bounce-loader/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@
"command": "cd packages/bounce-loader && yarn vitest run --changed --config vite.config.ts"
},
"publish": {
"command": "node tools/scripts/publish.mjs bounce-loader {args.ver} {args.tag}",
"command": "node tools/scripts/publish.mjs bounce-loader latest",
"dependsOn": ["e2e", "build"]
},
"publish-beta": {
"command": "node tools/scripts/publish.mjs bounce-loader beta",
"dependsOn": ["e2e", "build"]
}
}
Expand Down
6 changes: 5 additions & 1 deletion packages/file-utils/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
}
},
"publish": {
"command": "node tools/scripts/publish.mjs file-utils {args.ver} {args.tag}",
"command": "node tools/scripts/publish.mjs file-utils latest",
"dependsOn": ["test", "build"]
},
"publish-beta": {
"command": "node tools/scripts/publish.mjs file-utils beta",
"dependsOn": ["test", "build"]
},
"test": {
Expand Down
6 changes: 5 additions & 1 deletion packages/ove/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
}
},
"publish": {
"command": "node tools/scripts/publish.mjs ove {args.ver} {args.tag}",
"command": "node tools/scripts/publish.mjs ove latest",
"dependsOn": ["test", "build", "build_umd"]
},
"publish-beta": {
"command": "node tools/scripts/publish.mjs ove beta",
"dependsOn": ["test", "build", "build_umd"]
},
"build_umd": {
Expand Down
6 changes: 5 additions & 1 deletion packages/range-utils/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
}
},
"publish": {
"command": "node tools/scripts/publish.mjs range-utils {args.ver} {args.tag}",
"command": "node tools/scripts/publish.mjs range-utils latest",
"dependsOn": ["test", "build"]
},
"publish-beta": {
"command": "node tools/scripts/publish.mjs range-utils beta",
"dependsOn": ["test", "build"]
},
"test": {
Expand Down
6 changes: 5 additions & 1 deletion packages/sequence-utils/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
}
},
"publish": {
"command": "node tools/scripts/publish.mjs sequence-utils {args.ver} {args.tag}",
"command": "node tools/scripts/publish.mjs sequence-utils latest",
"dependsOn": ["test", "build"]
},
"publish-beta": {
"command": "node tools/scripts/publish.mjs sequence-utils beta",
"dependsOn": ["test", "build"]
},
"test": {
Expand Down
6 changes: 5 additions & 1 deletion packages/ui/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
}
},
"publish": {
"command": "node tools/scripts/publish.mjs ui {args.ver} {args.tag}",
"command": "node tools/scripts/publish.mjs ui latest",
"dependsOn": ["test", "build"]
},
"publish-beta": {
"command": "node tools/scripts/publish.mjs ui beta",
"dependsOn": ["test", "build"]
},
"build_simple": {
Expand Down
86 changes: 47 additions & 39 deletions tools/scripts/publish.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ function invariant(condition, message) {
}
}

// Executing publish script: node path/to/publish.mjs {name} --version {version} --tag {tag}
// Executing publish script: node path/to/publish.mjs {name} --tag {tag}
// tag by default is "next". Manually set to beta for beta versions or latest for stable versions.
// Default "tag" to "next" so we won't publish the "latest" tag by accident.
let [, , name, version, tag = "latest"] = process.argv;
let [, , name, tag = "next"] = process.argv;

execSync(`git pull`);
execSync(`yarn auto-changelog -p`);
Expand Down Expand Up @@ -58,51 +59,58 @@ invariant(
project,
`Could not find project "${name}" in the workspace. Is the project.json configured correctly?`
);
const outputPath = project.data?.targets?.build?.options?.outputPath;
// const outputPath = project.data?.targets?.build?.options?.outputPath;
const packagePath = project.data?.root;

if (!tag || tag === "undefined") {
tag = "latest";
}
if (!version || version === "undefined") {
process.chdir(packagePath);
let json = JSON.parse(readFileSync(`package.json`).toString());
version = json.version;
process.chdir(packagePath);
let json = JSON.parse(readFileSync(`package.json`).toString());
let version = json.version;

// Bump the version
if (version.includes("-beta")) {
// If its not a beta version, remove beta version (version was already bumped when creating beta version)
if (tag !== "beta") {
const versionParts = version.split("-beta");
version = versionParts[0];
} else {
// Bump beta version only
const versionParts = version.split(".");
versionParts[3] = Number(versionParts[3]) + 1; // increase beta version
version = versionParts.join(".");
}
} else {
// Update the version
const versionParts = version.split(".");
versionParts[2] = Number(versionParts[2]) + 1; // increase patch version
version = versionParts.join(".");

// Updating the version in "package.json" before publishing
try {
json.version = version;
writeFileSync(`package.json`, JSON.stringify(json, null, 2));
} catch (e) {
console.error(
chalk.bold.red(
`Error writing package.json file from library build output.`
)
);
}
process.chdir(path.resolve(`../../dist/${name}`));
json = JSON.parse(readFileSync(`package.json`).toString());
try {
json.version = version;
// json.type = "commonjs";
delete json.type;
json.license = "MIT";
json.dependencies = { ...deps, ...json.dependencies };
writeFileSync(`package.json`, JSON.stringify(json, null, 2));
} catch (e) {
console.error(
chalk.bold.red(
`Error writing package.json file from library build output.`
)
);
// If its beta, add beta version
if (tag === "beta") {
version = `${version}-beta.1`;
}
} else {
process.chdir(path.resolve("../../", `dist/${name}`));
}

// Updating the version in "package.json" before publishing
try {
json.version = version;
writeFileSync(`package.json`, JSON.stringify(json, null, 2));
} catch (e) {
console.error(
chalk.bold.red(`Error writing package.json file from library build output.`)
);
}
process.chdir(path.resolve(`../../dist/${name}`));
json = JSON.parse(readFileSync(`package.json`).toString());
try {
json.version = version;
// json.type = "commonjs";
delete json.type;
json.license = "MIT";
json.dependencies = { ...deps, ...json.dependencies };
writeFileSync(`package.json`, JSON.stringify(json, null, 2));
} catch (e) {
console.error(
chalk.bold.red(`Error writing package.json file from library build output.`)
);
}

invariant(
Expand Down

0 comments on commit bf8457d

Please sign in to comment.