@plugin-light/cli 1.0.2 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,79 @@
1
+ const { execSync } = require('child_process');
2
+
3
+
4
+ const { insertDocChangeLog } = require('t-comm');
5
+
6
+ const {
7
+ genPureReleaseDir,
8
+ copyReadme,
9
+ } = require('./utils/prepare');
10
+ const {
11
+ release,
12
+ } = require('./utils/release');
13
+ const {
14
+ changeVersion,
15
+ } = require('./utils/version');
16
+
17
+
18
+ function preCommit(config) {
19
+ const {
20
+ PROJECT_ROOT,
21
+ PATH_MAP,
22
+ TO_DELETE_FILES,
23
+ } = config;
24
+
25
+ if (!PROJECT_ROOT
26
+ || !PATH_MAP
27
+ || !TO_DELETE_FILES
28
+ || !PATH_MAP.ROOT_PACKAGE_JSON
29
+ || !PATH_MAP.PACKAGE_JSON
30
+ || !PATH_MAP.TARGET_ROOT
31
+ || !PATH_MAP.TARGET_PACKAGES
32
+ || !PATH_MAP.SOURCE_PACKAGES
33
+ || !PATH_MAP.SOURCE_README
34
+ || !PATH_MAP.TARGET_README
35
+ || !PATH_MAP.SOURCE_CHANGELOG
36
+ || !PATH_MAP.TARGET_CHANGELOG
37
+ || !PATH_MAP.DOC_TARGET_CHANGELOG
38
+ ) {
39
+ throw new Error('config is not complete');
40
+ }
41
+
42
+ const version = changeVersion({
43
+ rootPackageJson: PATH_MAP.ROOT_PACKAGE_JSON,
44
+ packageJson: PATH_MAP.PACKAGE_JSON,
45
+ });
46
+
47
+ genPureReleaseDir({
48
+ targetRoot: PATH_MAP.TARGET_ROOT,
49
+ targetPackages: PATH_MAP.TARGET_PACKAGES,
50
+ sourcePackages: PATH_MAP.SOURCE_PACKAGES,
51
+ toDeleteFiles: TO_DELETE_FILES,
52
+ });
53
+ copyReadme({
54
+ sourceReadme: PATH_MAP.SOURCE_README,
55
+ targetReadme: PATH_MAP.TARGET_README,
56
+ sourceChangelog: PATH_MAP.SOURCE_CHANGELOG,
57
+ targetChangelog: PATH_MAP.TARGET_CHANGELOG,
58
+ });
59
+ insertDocChangeLog({
60
+ changelogPath: PATH_MAP.SOURCE_CHANGELOG,
61
+ docChangelogPath: PATH_MAP.DOC_TARGET_CHANGELOG,
62
+ packageJsonPath: PATH_MAP.PACKAGE_JSON,
63
+ });
64
+
65
+ execSync('git add .', {
66
+ stdio: 'inherit',
67
+ cwd: PROJECT_ROOT,
68
+ });
69
+
70
+ release({
71
+ version,
72
+ targetPackages: PATH_MAP.TARGET_PACKAGES,
73
+ });
74
+ }
75
+
76
+
77
+ module.exports = {
78
+ preCommit,
79
+ };
@@ -0,0 +1,40 @@
1
+ const {
2
+ genPureReleaseDir,
3
+ copyReadme,
4
+ } = require('./utils/prepare');
5
+
6
+
7
+ function prepareRelease(config) {
8
+ const {
9
+ TO_DELETE_FILES,
10
+ PATH_MAP,
11
+ } = config;
12
+ if (!PATH_MAP
13
+ || !PATH_MAP.TARGET_ROOT
14
+ || !PATH_MAP.TARGET_PACKAGES
15
+ || !PATH_MAP.SOURCE_PACKAGES
16
+ || !PATH_MAP.SOURCE_README
17
+ || !PATH_MAP.TARGET_README
18
+ || !PATH_MAP.SOURCE_CHANGELOG
19
+ || !PATH_MAP.TARGET_CHANGELOG
20
+ || !TO_DELETE_FILES
21
+ ) {
22
+ throw new Error('config is not complete');
23
+ }
24
+ genPureReleaseDir({
25
+ targetRoot: PATH_MAP.TARGET_ROOT,
26
+ targetPackages: PATH_MAP.TARGET_PACKAGES,
27
+ sourcePackages: PATH_MAP.SOURCE_PACKAGES,
28
+ toDeleteFiles: TO_DELETE_FILES,
29
+ });
30
+ copyReadme({
31
+ sourceReadme: PATH_MAP.SOURCE_README,
32
+ targetReadme: PATH_MAP.TARGET_README,
33
+ sourceChangelog: PATH_MAP.SOURCE_CHANGELOG,
34
+ targetChangelog: PATH_MAP.TARGET_CHANGELOG,
35
+ });
36
+ }
37
+
38
+ module.exports = {
39
+ prepareRelease,
40
+ };
@@ -0,0 +1,26 @@
1
+ // 发布核心方法,不直接执行
2
+ const { getNextVersion } = require('t-comm');
3
+
4
+ const { doCommand } = require('../utils/utils');
5
+
6
+
7
+ function getVersionCommand(rawVersion) {
8
+ return getNextVersion('', rawVersion);
9
+ }
10
+
11
+
12
+ function releaseCore(versionType) {
13
+ doCommand('mkdir log || true');
14
+
15
+ const nextVersion = getVersionCommand(versionType);
16
+ console.log('🚀 [nextVersion] ', nextVersion);
17
+
18
+ doCommand(`npx standard-version --release-as ${nextVersion} -a --no-verify`);
19
+ }
20
+
21
+
22
+ module.exports = {
23
+ releaseCore,
24
+ getVersionCommand,
25
+ doCommand,
26
+ };
@@ -0,0 +1,8 @@
1
+ const MAIN_VERSION_LIST = ['patch', 'minor', 'major'];
2
+
3
+ const PRE_VERSION_LIST = ['alpha', 'beta', 'rc'];
4
+
5
+ module.exports = {
6
+ MAIN_VERSION_LIST,
7
+ PRE_VERSION_LIST,
8
+ };
@@ -0,0 +1,52 @@
1
+ const { execCommand } = require('t-comm');
2
+
3
+ const { MAIN_VERSION_LIST } = require('./config');
4
+
5
+
6
+ function validatePublish({
7
+ MANUAL_REVIEW_RESULT,
8
+ SHOULD_AUDIT,
9
+
10
+ versionType,
11
+ branch,
12
+
13
+ MAIN_BRANCH,
14
+ extraValidate,
15
+ }) {
16
+ console.log('🚀 [MANUAL_REVIEW_RESULT]', MANUAL_REVIEW_RESULT);
17
+ if (process.env.NPM_TOKEN_FOR_PUBLISH_PRESS_NEXT) return;
18
+
19
+ if (SHOULD_AUDIT === '1' && MANUAL_REVIEW_RESULT !== 'PROCESS') {
20
+ console.error('🚀 [Error] Not Review');
21
+ process.exit(1);
22
+ }
23
+
24
+ if (!versionType) {
25
+ console.error('🚀 [Error] No Version Type');
26
+ process.exit(1);
27
+ }
28
+
29
+ if (branch !== MAIN_BRANCH && MAIN_VERSION_LIST.includes(versionType)) {
30
+ console.error(`🚀 [Error] Only "${MAIN_BRANCH}" branch can generate ${versionType}`);
31
+ process.exit(1);
32
+ }
33
+
34
+ if (/^[a-zA-Z]+$/.test(versionType) && ![...MAIN_VERSION_LIST, 'alpha', 'beta'].includes(versionType)) {
35
+ console.error('🚀 [Error] Version type is invalid');
36
+ process.exit(1);
37
+ }
38
+
39
+ if (typeof extraValidate === 'function') {
40
+ extraValidate();
41
+ }
42
+ }
43
+
44
+ function doCommand(command, cwd = process.cwd()) {
45
+ execCommand(command, cwd || process.cwd(), 'inherit');
46
+ }
47
+
48
+
49
+ module.exports = {
50
+ validatePublish,
51
+ doCommand,
52
+ };