Skip to content

Commit

Permalink
feat: ✨ add prebuild configuration
Browse files Browse the repository at this point in the history
override current package.json version with the next version using semantic-release
  • Loading branch information
luthfimasruri committed Mar 25, 2021
1 parent 0b37ea2 commit a0c7c87
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 14 deletions.
50 changes: 44 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"types": "dist/vue-quill.d.ts",
"scripts": {
"lib:dev": " npm run theme:dev && rollup -c rollup.config.ts -w",
"lib:build": "npm run theme:build && rollup -c rollup.config.ts && npm run lib:types",
"lib:prebuild": "npx ts-node prebuild.config.ts",
"lib:build": "npm run theme:build && npm run lib:prebuild && rollup -c rollup.config.ts && npm run lib:types",
"lib:types": "api-extractor run --local --verbose",
"docs:dev": "cd docs && npm run dev",
"docs:build": "cd docs && npm run build",
Expand All @@ -72,7 +73,6 @@
"@types/node": "^14.14.35",
"@types/quill": "^2.0.5",
"csso": "^4.2.0",
"lodash.camelcase": "^4.3.0",
"pascalcase": "^1.0.0",
"quill-delta": "^4.2.2",
"rollup": "^2.42.3",
Expand All @@ -83,6 +83,7 @@
"rollup-plugin-typescript2": "^0.30.0",
"semantic-release": "^17.4.2",
"stylus": "^0.54.8",
"ts-node": "^9.1.1",
"typescript": "^4.2.3"
}
}
}
48 changes: 48 additions & 0 deletions prebuild.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const semanticRelease = require('semantic-release');
const releaserc = require('./.releaserc.json')
const pkg = require('./package.json')

const getNextVersion = async (): Promise<string> => {
try {
const result = await semanticRelease({
// Core options
branches: releaserc.branches,
repositoryUrl: pkg.repository.url,
dryRun: true,
ci: false,
plugins: ['@semantic-release/commit-analyzer']
});

console.log("PROCESS_ENV_CI ---->>>>>>>>>>", process.env.CI);

if (result) {
const { lastRelease, commits, nextRelease } = result;
console.log(`Published ${nextRelease.type} release version ${nextRelease.version} containing ${commits.length} commits.`);
if (lastRelease.version) console.log(`The last release was "${lastRelease.version}".`);
return nextRelease.version
} else {
console.log('No release published.');
}
} catch (err) {
console.error('The automated release failed with %O', err)
}
return ""
}

const fs = require('fs');
const csso = require('csso');
const packageConfigs = async () => {
return {
version: await getNextVersion()
}
}

const prebuildPkg = 'temp/prebuild-package.json'
if (!fs.existsSync("temp")) fs.mkdirSync("temp");
packageConfigs().then((config) => {
const content = JSON.stringify(config)
fs.writeFile(prebuildPkg, content, (err: any) => {
if (err) throw err;
console.log('empty.js created');
})
})
12 changes: 7 additions & 5 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import pascalcase from 'pascalcase'
import copy from 'rollup-plugin-copy'

const pkg = require('./package.json')
const prebuildPkg = require('./temp/prebuild-package.json')
Object.assign(pkg, prebuildPkg)

// get all or any character after '/' in this case 'vue-quill'
const name = pkg.name.match(/[^/]*$/)[0]
// const name = "vue-quill"

function getAuthors(pkg) {
const { contributors, author } = pkg
Expand All @@ -25,10 +27,10 @@ function getAuthors(pkg) {
}

const banner = `/*!
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} ${getAuthors(pkg)}
* @license MIT
*/`
* ${pkg.name} v${pkg.version}
* (c) ${new Date().getFullYear()} ${getAuthors(pkg)}
* @license MIT
*/`

// ensure TS checks only once for each build
let hasTSChecked = false
Expand Down

0 comments on commit a0c7c87

Please sign in to comment.