Skip to content

Commit a0c7c87

Browse files
committed
feat: ✨ add prebuild configuration
override current package.json version with the next version using semantic-release
1 parent 0b37ea2 commit a0c7c87

File tree

4 files changed

+103
-14
lines changed

4 files changed

+103
-14
lines changed

package-lock.json

Lines changed: 44 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@
5151
"types": "dist/vue-quill.d.ts",
5252
"scripts": {
5353
"lib:dev": " npm run theme:dev && rollup -c rollup.config.ts -w",
54-
"lib:build": "npm run theme:build && rollup -c rollup.config.ts && npm run lib:types",
54+
"lib:prebuild": "npx ts-node prebuild.config.ts",
55+
"lib:build": "npm run theme:build && npm run lib:prebuild && rollup -c rollup.config.ts && npm run lib:types",
5556
"lib:types": "api-extractor run --local --verbose",
5657
"docs:dev": "cd docs && npm run dev",
5758
"docs:build": "cd docs && npm run build",
@@ -72,7 +73,6 @@
7273
"@types/node": "^14.14.35",
7374
"@types/quill": "^2.0.5",
7475
"csso": "^4.2.0",
75-
"lodash.camelcase": "^4.3.0",
7676
"pascalcase": "^1.0.0",
7777
"quill-delta": "^4.2.2",
7878
"rollup": "^2.42.3",
@@ -83,6 +83,7 @@
8383
"rollup-plugin-typescript2": "^0.30.0",
8484
"semantic-release": "^17.4.2",
8585
"stylus": "^0.54.8",
86+
"ts-node": "^9.1.1",
8687
"typescript": "^4.2.3"
8788
}
88-
}
89+
}

prebuild.config.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const semanticRelease = require('semantic-release');
2+
const releaserc = require('./.releaserc.json')
3+
const pkg = require('./package.json')
4+
5+
const getNextVersion = async (): Promise<string> => {
6+
try {
7+
const result = await semanticRelease({
8+
// Core options
9+
branches: releaserc.branches,
10+
repositoryUrl: pkg.repository.url,
11+
dryRun: true,
12+
ci: false,
13+
plugins: ['@semantic-release/commit-analyzer']
14+
});
15+
16+
console.log("PROCESS_ENV_CI ---->>>>>>>>>>", process.env.CI);
17+
18+
if (result) {
19+
const { lastRelease, commits, nextRelease } = result;
20+
console.log(`Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.`);
21+
if (lastRelease.version) console.log(`The last release was "${lastRelease.version}".`);
22+
return nextRelease.version
23+
} else {
24+
console.log('No release published.');
25+
}
26+
} catch (err) {
27+
console.error('The automated release failed with %O', err)
28+
}
29+
return ""
30+
}
31+
32+
const fs = require('fs');
33+
const csso = require('csso');
34+
const packageConfigs = async () => {
35+
return {
36+
version: await getNextVersion()
37+
}
38+
}
39+
40+
const prebuildPkg = 'temp/prebuild-package.json'
41+
if (!fs.existsSync("temp")) fs.mkdirSync("temp");
42+
packageConfigs().then((config) => {
43+
const content = JSON.stringify(config)
44+
fs.writeFile(prebuildPkg, content, (err: any) => {
45+
if (err) throw err;
46+
console.log('empty.js created');
47+
})
48+
})

rollup.config.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ import pascalcase from 'pascalcase'
77
import copy from 'rollup-plugin-copy'
88

99
const pkg = require('./package.json')
10+
const prebuildPkg = require('./temp/prebuild-package.json')
11+
Object.assign(pkg, prebuildPkg)
12+
1013
// get all or any character after '/' in this case 'vue-quill'
1114
const name = pkg.name.match(/[^/]*$/)[0]
12-
// const name = "vue-quill"
1315

1416
function getAuthors(pkg) {
1517
const { contributors, author } = pkg
@@ -25,10 +27,10 @@ function getAuthors(pkg) {
2527
}
2628

2729
const banner = `/*!
28-
* ${pkg.name} v${pkg.version}
29-
* (c) ${new Date().getFullYear()} ${getAuthors(pkg)}
30-
* @license MIT
31-
*/`
30+
* ${pkg.name} v${pkg.version}
31+
* (c) ${new Date().getFullYear()} ${getAuthors(pkg)}
32+
* @license MIT
33+
*/`
3234

3335
// ensure TS checks only once for each build
3436
let hasTSChecked = false

0 commit comments

Comments
 (0)