Skip to content

Commit

Permalink
feat: upgrate release script
Browse files Browse the repository at this point in the history
  • Loading branch information
DiamondYuan committed Jul 3, 2021
1 parent bf89f38 commit b7b771b
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 62 deletions.
58 changes: 0 additions & 58 deletions .github/workflows/release-canary.yml

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"ts-import-plugin": "^1.5.5",
"ts-jest": "^24.0.2",
"ts-loader": "^6.2.1",
"ts-node": "^10.0.0",
"typescript": "^3.7.3",
"url-loader": "^3.0.0",
"webpack": "^4.41.5",
Expand Down
17 changes: 17 additions & 0 deletions script/release.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getBuildOptions } from './utils/get-build-options';
import { TDistType, IReleaseProcessEnv } from './utils/types';

const { isBeta } = require('../webpack/utils/manifest');

(async () => {
const buildEnv = (process.env as unknown) as IReleaseProcessEnv;
const buildOptions = getBuildOptions(buildEnv);
const CurrentDistType: TDistType = isBeta() ? 'Beta' : 'Release';
if (!buildOptions.distType.has(CurrentDistType)) {
process.exit(100);
}
console.log('buildOptions: \n', buildOptions);
for (const iterator of buildOptions.targetBrowser) {
console.log(`Release ${iterator}`);
}
})();
18 changes: 18 additions & 0 deletions script/utils/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IWebpackProcessEnv } from './types';
import { fork } from 'child_process';

export function build({ targetBrowser }) {
const buildScript = require.resolve('../build');
const buildEnv: IWebpackProcessEnv = Object.create(process.env);
buildEnv.NODE_ENV = 'production';
buildEnv.TARGET_BROWSER = targetBrowser;

const cp = fork(buildScript, [], {
env: (buildEnv as unknown) as typeof process.env,
silent: true,
});
cp.stderr.on('data', e => console.log(e.toString()));
return new Promise(r => {
cp.on('message', r);
});
}
29 changes: 29 additions & 0 deletions script/utils/get-build-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IReleaseProcessEnv, IBuildOptions } from './types';

export function getBuildOptions(env: IReleaseProcessEnv): IBuildOptions {
const option: IBuildOptions = {
targetBrowser: new Set(),
publishToStore: false,
distType: new Set(),
};

if (!env.TARGET_BROWSER || !['Chrome', 'Firefox'].includes(env.TARGET_BROWSER)) {
option.targetBrowser.add('Chrome');
option.targetBrowser.add('Firefox');
} else {
option.targetBrowser.add(env.TARGET_BROWSER);
}

if (env.PUBLISH_TO_STORE === 'true') {
option.publishToStore = true;
}

if (!env.DIST_TYPE || !['Beta', 'Release'].includes(env.DIST_TYPE)) {
option.distType.add('Beta');
option.distType.add('Release');
} else {
option.distType.add(env.DIST_TYPE);
}

return option;
}
20 changes: 20 additions & 0 deletions script/utils/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export type TBuildTarget = 'Chrome' | 'Firefox';
export type TDistType = 'Beta' | 'Release';

export interface IReleaseProcessEnv {
TARGET_BROWSER?: TBuildTarget;
PUBLISH_TO_STORE?: 'true';
DIST_TYPE?: TDistType;
}

export interface IWebpackProcessEnv {
TARGET_BROWSER: TBuildTarget;
PUBLISH_TO_STORE?: 'true';
NODE_ENV: 'development' | 'production';
}

export interface IBuildOptions {
targetBrowser: Set<TBuildTarget>;
publishToStore: boolean;
distType: Set<TDistType>;
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"emitDecoratorMetadata": true,
"resolveJsonModule": true,
"experimentalDecorators": true,
"target": "es2018",
"module": "esnext",
"target": "ESNext",
"module": "CommonJS",
"declaration": false,
"noImplicitAny": true,
"strictNullChecks": true,
Expand Down
60 changes: 58 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,26 @@
resolved "https://registry.nlark.com/@shihengtech/hooks/download/@shihengtech/hooks-0.0.7.tgz#24fb7377363a9b8ba225568587559f145602ccfb"
integrity sha1-JPtzdzY6m4uiJVaFh1WfFFYCzPs=

"@tsconfig/node10@^1.0.7":
version "1.0.8"
resolved "https://registry.nlark.com/@tsconfig/node10/download/@tsconfig/node10-1.0.8.tgz?cache=0&sync_timestamp=1623230113943&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40tsconfig%2Fnode10%2Fdownload%2F%40tsconfig%2Fnode10-1.0.8.tgz#c1e4e80d6f964fbecb3359c43bd48b40f7cadad9"
integrity sha1-weToDW+WT77LM1nEO9SLQPfK2tk=

"@tsconfig/node12@^1.0.7":
version "1.0.9"
resolved "https://registry.nlark.com/@tsconfig/node12/download/@tsconfig/node12-1.0.9.tgz#62c1f6dee2ebd9aead80dc3afa56810e58e1a04c"
integrity sha1-YsH23uLr2a6tgNw6+laBDljhoEw=

"@tsconfig/node14@^1.0.0":
version "1.0.1"
resolved "https://registry.nlark.com/@tsconfig/node14/download/@tsconfig/node14-1.0.1.tgz?cache=0&sync_timestamp=1623230139058&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40tsconfig%2Fnode14%2Fdownload%2F%40tsconfig%2Fnode14-1.0.1.tgz#95f2d167ffb9b8d2068b0b235302fafd4df711f2"
integrity sha1-lfLRZ/+5uNIGiwsjUwL6/U33EfI=

"@tsconfig/node16@^1.0.1":
version "1.0.1"
resolved "https://registry.nlark.com/@tsconfig/node16/download/@tsconfig/node16-1.0.1.tgz#a6ca6a9a0ff366af433f42f5f0e124794ff6b8f1"
integrity sha1-pspqmg/zZq9DP0L18OEkeU/2uPE=

"@types/anymatch@*":
version "1.3.1"
resolved "https://registry.nlark.com/@types/anymatch/download/@types/anymatch-1.3.1.tgz#336badc1beecb9dacc38bea2cf32adf627a8421a"
Expand Down Expand Up @@ -1619,6 +1639,11 @@ aproba@^1.1.1:
resolved "https://registry.nlark.com/aproba/download/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a"
integrity sha1-aALmJk79GMeQobDVF/DyYnvyyUo=

arg@^4.1.0:
version "4.1.3"
resolved "https://registry.npm.taobao.org/arg/download/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
integrity sha1-Jp/HrVuOQstjyJbVZmAXJhwUQIk=

argparse@^1.0.7:
version "1.0.10"
resolved "https://registry.nlark.com/argparse/download/argparse-1.0.10.tgz#bcd6791ea5ae09725e17e5ad988134cd40b3d911"
Expand Down Expand Up @@ -2812,6 +2837,11 @@ create-react-class@^15.5.3:
loose-envify "^1.3.1"
object-assign "^4.1.1"

create-require@^1.1.0:
version "1.1.1"
resolved "https://registry.npm.taobao.org/create-require/download/create-require-1.1.1.tgz#c1d7e8f1e5f6cfc9ff65f9cd352d37348756c333"
integrity sha1-wdfo8eX2z8n/ZfnNNS03NIdWwzM=

cross-spawn@^5.0.1:
version "5.1.0"
resolved "https://registry.npm.taobao.org/cross-spawn/download/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
Expand Down Expand Up @@ -3362,6 +3392,11 @@ diff-sequences@^24.9.0:
resolved "https://registry.npm.taobao.org/diff-sequences/download/diff-sequences-24.9.0.tgz#5715d6244e2aa65f48bba0bc972db0b0b11e95b5"
integrity sha1-VxXWJE4qpl9Iu6C8ly2wsLEelbU=

diff@^4.0.1:
version "4.0.2"
resolved "https://registry.npm.taobao.org/diff/download/diff-4.0.2.tgz#60f3aecb89d5fae520c11aa19efc2bb982aade7d"
integrity sha1-YPOuy4nV+uUgwRqhnvwruYKq3n0=

diffie-hellman@^5.0.0:
version "5.0.3"
resolved "https://registry.npm.taobao.org/diffie-hellman/download/diffie-hellman-5.0.3.tgz#40e8ee98f55a2149607146921c63e1ae5f3d2875"
Expand Down Expand Up @@ -6504,7 +6539,7 @@ make-dir@^3.0.2:
dependencies:
semver "^6.0.0"

[email protected]:
[email protected], make-error@^1.1.1:
version "1.3.6"
resolved "https://registry.nlark.com/make-error/download/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2"
integrity sha1-LrLjfqm2fEiR9oShOUeZr0hM96I=
Expand Down Expand Up @@ -9211,7 +9246,7 @@ source-map-resolve@^0.5.0:
source-map-url "^0.4.0"
urix "^0.1.0"

source-map-support@^0.5.6, source-map-support@~0.5.12:
source-map-support@^0.5.17, source-map-support@^0.5.6, source-map-support@~0.5.12:
version "0.5.19"
resolved "https://registry.npm.taobao.org/source-map-support/download/source-map-support-0.5.19.tgz#a98b62f86dcaf4f67399648c085291ab9e8fed61"
integrity sha1-qYti+G3K9PZzmWSMCFKRq56P7WE=
Expand Down Expand Up @@ -9913,6 +9948,22 @@ ts-loader@^6.2.1:
micromatch "^4.0.0"
semver "^6.0.0"

ts-node@^10.0.0:
version "10.0.0"
resolved "https://registry.nlark.com/ts-node/download/ts-node-10.0.0.tgz?cache=0&sync_timestamp=1621798304685&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fts-node%2Fdownload%2Fts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
integrity sha1-BfELmnFrC2JBKa1E8OoF2shLo74=
dependencies:
"@tsconfig/node10" "^1.0.7"
"@tsconfig/node12" "^1.0.7"
"@tsconfig/node14" "^1.0.0"
"@tsconfig/node16" "^1.0.1"
arg "^4.1.0"
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
source-map-support "^0.5.17"
yn "3.1.1"

tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0:
version "1.14.1"
resolved "https://registry.nlark.com/tslib/download/tslib-1.14.1.tgz?cache=0&sync_timestamp=1618847132149&other_urls=https%3A%2F%2Fregistry.nlark.com%2Ftslib%2Fdownload%2Ftslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
Expand Down Expand Up @@ -10753,3 +10804,8 @@ yazl@^2.4.2:
integrity sha1-o9ZdPdZZpbCTeFDoYJ8i//orXDU=
dependencies:
buffer-crc32 "~0.2.3"

[email protected]:
version "3.1.1"
resolved "https://registry.npm.taobao.org/yn/download/yn-3.1.1.tgz#1e87401a09d767c1d5eab26a6e4c185182d2eb50"
integrity sha1-HodAGgnXZ8HV6rJqbkwYUYLS61A=

0 comments on commit b7b771b

Please sign in to comment.