Skip to content

Commit ee9f973

Browse files
authored
Merge pull request #109 from docsbydoxdox/feature/tools
[feat] Publish tool
2 parents ecf4094 + 9b59b2c commit ee9f973

File tree

3 files changed

+83
-4
lines changed

3 files changed

+83
-4
lines changed

bin/.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
declare module 'parse-cmd-args';

bin/version.js

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env node
2+
3+
import { join } from 'path';
4+
5+
import { readFile, writeFile } from 'fs/promises';
6+
7+
import { inc, parse } from 'semver';
8+
9+
import parseCmdArgs from 'parse-cmd-args';
10+
11+
const { input } = parseCmdArgs(null, {
12+
requireUserInput: true
13+
});
14+
15+
const loadAndParsePackageFile = async path => {
16+
return JSON.parse(await readFile(path, 'utf8'));
17+
};
18+
19+
(async () => {
20+
const { workspaces } = await loadAndParsePackageFile('./package.json');
21+
22+
const versions = (
23+
await Promise.all(
24+
workspaces.map(async workspace => {
25+
const pkg = await loadAndParsePackageFile(
26+
join(workspace, './package.json')
27+
);
28+
29+
const { prerelease } = parse(pkg.version);
30+
31+
const nextVersion = inc(pkg.version, input, prerelease[0]);
32+
33+
await writeFile(
34+
join(workspace, './package.json'),
35+
`${JSON.stringify(
36+
{ ...pkg, version: nextVersion },
37+
null,
38+
2
39+
)}\n`
40+
);
41+
42+
return {
43+
name: pkg.name,
44+
version: nextVersion
45+
};
46+
})
47+
)
48+
).reduce((all, workspace) => ({ ...all, [workspace.name]: workspace }), {});
49+
50+
await Promise.all(
51+
workspaces.map(async workspace => {
52+
const pkg = await loadAndParsePackageFile(
53+
join(workspace, './package.json')
54+
);
55+
56+
['dependencies', 'peerDependencies', 'devDependencies'].map(
57+
type => {
58+
if (pkg[type]) {
59+
Object.keys(pkg[type]).map(dependency => {
60+
if (Object.keys(versions).includes(dependency)) {
61+
pkg[type][dependency] =
62+
versions[dependency].version;
63+
}
64+
});
65+
}
66+
}
67+
);
68+
69+
await writeFile(
70+
join(workspace, './package.json'),
71+
`${JSON.stringify(pkg, null, 2)}\n`
72+
);
73+
})
74+
);
75+
76+
console.log(versions);
77+
})();

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "doxdox-workspace",
33
"version": "4.0.0-preview.1",
4+
"type": "module",
45
"workspaces": [
56
"./packages/doxdox-core",
67
"./packages/doxdox-parser-jsdoc",
@@ -21,10 +22,10 @@
2122
"prettier-fix": "npx prettier@2 --write \"packages/**/*.ts\"",
2223
"ncu": "npm exec --workspaces -- npx npm-check-updates@12",
2324
"ncu-upgrade": "npm exec --workspaces -- npx npm-check-updates@12 -u",
24-
"publish-prerelease": "npm version prerelease --workspaces --no-git-tag-version --include-workspace-root --preid preview",
25-
"publish-patch": "npm version patch --workspaces --no-git-tag-version --include-workspace-root",
26-
"publish-minor": "npm version minor --workspaces --no-git-tag-version --include-workspace-root",
27-
"publish-major": "npm version major --workspaces --no-git-tag-version --include-workspace-root",
25+
"publish-prerelease": "npm version prerelease",
26+
"publish-patch": "./bin/version.js patch",
27+
"publish-minor": "./bin/version.js minor",
28+
"publish-major": "./bin/version.js major",
2829
"publish-preview": "npm publish --dry-run --workspaces",
2930
"debug-link": "npm run link --workspaces --if-present"
3031
},

0 commit comments

Comments
 (0)