Skip to content

Commit

Permalink
fix: fix release dist version
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondYuan committed Mar 8, 2021
1 parent fac2696 commit 7066c45
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
"pre-commit": "^1.2.2",
"prettier": "^1.19.1",
"pump": "^3.0.0",
"semver": "^7.3.4",
"style-loader": "^0.23.1",
"terser-webpack-plugin": "^2.3.1",
"ts-import-plugin": "^1.5.5",
Expand Down
17 changes: 17 additions & 0 deletions webpack/getVersion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const semver = require('semver');
const { execSync } = require('child_process');

const branch = process.env.GITHUB_BRANCH || 'refs/heads/master';
const masterCommitsCount = execSync(`git rev-list --count ${branch}`)
.toString()
.trim();

function getVersion(version) {
const currentVersion = semver.parse(version);
if (Array.isArray(currentVersion.prerelease) && currentVersion.prerelease.length > 0) {
return semver.coerce(version).version.replace(/.[0-9]$/, `.${masterCommitsCount}`);
}
return version;
}

module.exports = getVersion;
5 changes: 5 additions & 0 deletions webpack/webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ const ExtensionReloader = require('webpack-extension-reloader');
const tsImportPluginFactory = require('ts-import-plugin');
const WebpackCreateExtensionManifestPlugin = require('webpack-create-extension-manifest-plugin');
const fs = require('fs');
const getVersion = require('./getVersion');

const distFiles = fs.readdirSync(resolve('dist')).filter(o => o !== '.gitkeep');

function resolve(dir) {
return path.join(__dirname, '..', dir);
}

const packageJson = JSON.parse(fs.readFileSync(resolve('package.json'), 'utf8'));

let manifestExtra = {
name: 'Web Clipper',
version: getVersion(packageJson.version),
permissions: [
'activeTab',
'storage',
Expand All @@ -40,6 +44,7 @@ let tool = resolve('src/main/tool.main.chrome.ts');
if (process.env.TARGET_BROWSER === 'Firefox') {
manifestExtra = {
name: 'Web Clipper',
version: getVersion(packageJson.version),
commands: {
'toggle-feature-foo': {
suggested_key: {
Expand Down
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8510,6 +8510,13 @@ semver@^7.3.2:
dependencies:
lru-cache "^6.0.0"

semver@^7.3.4:
version "7.3.4"
resolved "https://registry.npm.taobao.org/semver/download/semver-7.3.4.tgz#27aaa7d2e4ca76452f98d3add093a72c943edc97"
integrity sha1-J6qn0uTKdkUvmNOt0JOnLJQ+3Jc=
dependencies:
lru-cache "^6.0.0"

serialize-javascript@^4.0.0:
version "4.0.0"
resolved "https://registry.npm.taobao.org/serialize-javascript/download/serialize-javascript-4.0.0.tgz#b525e1238489a5ecfc42afacc3fe99e666f4b1aa"
Expand Down

0 comments on commit 7066c45

Please sign in to comment.