mazey 3.3.5 → 3.3.7

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mazey",
3
- "version": "3.3.5",
3
+ "version": "3.3.7",
4
4
  "description": "Mazey's library for front-end.",
5
5
  "main": "lib/index.cjs.js",
6
6
  "module": "lib/index.esm.js",
@@ -15,8 +15,8 @@
15
15
  "test": "jest",
16
16
  "docs": "typedoc",
17
17
  "lint-and-fix": "eslint ./src/index.ts --ext 'ts,tsx' --fix",
18
- "preview": "npm run build && npm run test && npm run docs",
19
- "release": "npm run preview && npm publish && node ./scripts/release.js"
18
+ "preview": "npm run docs && npm run build && npm run test",
19
+ "release": "npm run preview && cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js"
20
20
  },
21
21
  "repository": {
22
22
  "type": "git",
@@ -69,6 +69,7 @@
69
69
  "@typescript-eslint/eslint-plugin": "^4.22.0",
70
70
  "@typescript-eslint/parser": "^4.22.0",
71
71
  "clean-webpack-plugin": "^1.0.1",
72
+ "cross-env": "^7.0.3",
72
73
  "date-fns": "^2.29.3",
73
74
  "eslint": "^6.8.0",
74
75
  "eslint-config-standard": "^14.1.0",
@@ -87,6 +88,7 @@
87
88
  "rollup-plugin-babel": "^4.3.3",
88
89
  "rollup-plugin-cleaner": "^1.0.0",
89
90
  "rollup-plugin-commonjs": "^10.1.0",
91
+ "rollup-plugin-copy": "^3.4.0",
90
92
  "rollup-plugin-terser": "^7.0.2",
91
93
  "rollup-plugin-typescript2": "^0.27.2",
92
94
  "ts-loader": "^8.0.2",
package/scripts/dev.js CHANGED
@@ -1,19 +1,22 @@
1
1
  /* eslint-disable no-undef */
2
2
  /* eslint-disable @typescript-eslint/no-var-requires */
3
- const execa = require('execa');
3
+ // const execa = require('execa');
4
+ const { getGitCurrentBranch } = require('./github-helper');
4
5
 
5
6
  (async () => {
6
7
  // const { stdout: pushMsg = '' } = await execa('git', ['push'], { stdio: 'pipe' })
7
8
  // .catch(error => {
8
9
  // console.log('error:', error.message);
9
10
  // });
10
- try {
11
- await execa('git', ['push'], { stdio: 'pipe' });
12
- } catch (error) {
13
- console.log('error:', error.message);
14
- const { stdout: currentBranch } = await execa('git', ['branch', '--show-current'], { stdio: 'pipe' });
15
- console.log('currentBranch:', currentBranch); // currentBranch: fix/rollup_dependences_mon_oct_31st_2022
16
- await execa('git', ['push', '--set-upstream', 'origin', currentBranch]);
17
- }
11
+ // try {
12
+ // await execa('git', ['push'], { stdio: 'pipe' });
13
+ // } catch (error) {
14
+ // console.log('error:', error.message);
15
+ // const { stdout: currentBranch } = await execa('git', ['branch', '--show-current'], { stdio: 'pipe' });
16
+ // console.log('currentBranch:', currentBranch); // currentBranch: fix/rollup_dependences_mon_oct_31st_2022
17
+ // await execa('git', ['push', '--set-upstream', 'origin', currentBranch]);
18
+ // }
18
19
  // console.log('pushMsg:', pushMsg);
20
+ const cb = await getGitCurrentBranch('fix returns value');
21
+ console.log('bbb', cb);
19
22
  })();
@@ -14,9 +14,23 @@ const execa = require('execa');
14
14
  * ```
15
15
  */
16
16
  async function release (ver) {
17
+ if (!ver) {
18
+ ver = process.env.SCRIPTS_NPM_PACKAGE_VERSION;
19
+ }
20
+ if (!ver) {
21
+ console.error('Fail to get the current version.');
22
+ return;
23
+ }
17
24
  const releaseVersion = `v${ver}`;
18
25
  const { stdout: releaseStdout } = await execa('echo', [`Start release ${releaseVersion}...`]);
19
26
  console.log(releaseStdout);
27
+ // commit
28
+ await getCommit('stage');
29
+ // marge
30
+ await gitMergeMaster2Release();
31
+ // build
32
+ await execa('npm', ['run', 'preview']);
33
+ await execa('npm', ['publish']);
20
34
  // git branch --show-current
21
35
  // console.log('git push --set-upstream origin <branch>');
22
36
  // Commit Stdout
@@ -38,7 +52,7 @@ async function release (ver) {
38
52
  }
39
53
 
40
54
  /**
41
- * Git Push
55
+ * Push code.
42
56
  */
43
57
  async function gitPush () {
44
58
  try {
@@ -49,9 +63,55 @@ async function gitPush () {
49
63
  console.log('currentBranch:', currentBranch); // currentBranch: fix/rollup_dependences_mon_oct_31st_2022
50
64
  await execa('git', ['push', '--set-upstream', 'origin', currentBranch]);
51
65
  }
66
+ return true;
67
+ }
68
+
69
+ /**
70
+ * Merge master to current branch.
71
+ */
72
+ async function gitMergeMaster2Release () {
73
+ const currentBranch = await getGitCurrentBranch();
74
+ await execa('git', ['checkout', 'master']);
75
+ await execa('git', ['pull']);
76
+ await execa('git', ['checkout', currentBranch]);
77
+ await execa('git', ['merge', 'master']);
78
+ return true;
79
+ }
80
+
81
+ /**
82
+ * Get git current branch.
83
+ */
84
+ async function getGitCurrentBranch () {
85
+ let currentBranch = '';
86
+ try {
87
+ ({ stdout: currentBranch } = await execa('git', ['branch', '--show-current'], { stdio: 'pipe' }));
88
+ } catch (error) {
89
+ // console.log('error:', error.message);
90
+ ({ stdout: currentBranch } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { stdio: 'pipe' }));
91
+ }
92
+ console.log('currentBranch:', currentBranch);
93
+ return currentBranch;
94
+ }
95
+
96
+ /**
97
+ * Commit current code.
98
+ */
99
+ async function getCommit (releaseVersion = 0) {
100
+ const { stdout: diffStdout } = await execa('git', ['diff'], { stdio: 'pipe' });
101
+ if (diffStdout) {
102
+ console.log('Committing changes...');
103
+ await execa('git', ['add', '-A']);
104
+ await execa('git', ['commit', '-m', `release: ${releaseVersion}`]);
105
+ } else {
106
+ console.log('No changes to commit.');
107
+ }
108
+ return true;
52
109
  }
53
110
 
54
111
  module.exports = {
55
112
  release,
56
113
  gitPush,
114
+ gitMergeMaster2Release,
115
+ getGitCurrentBranch,
116
+ getCommit,
57
117
  };
@@ -2,6 +2,8 @@
2
2
  /* eslint-disable no-undef */
3
3
  // release
4
4
  const { release } = require('./github-helper');
5
- const pkgVersion = process.env.VERSION || require('../package.json').version;
5
+ const pkgVersion = process.env.SCRIPTS_NPM_PACKAGE_VERSION || process.env.VERSION || require('../package.json').version;
6
+
7
+ console.log('release: SCRIPTS_NPM_PACKAGE_VERSION', process.env.SCRIPTS_NPM_PACKAGE_VERSION);
6
8
 
7
9
  release(pkgVersion);