mazey 3.3.11 → 3.4.0

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.11",
3
+ "version": "3.4.0",
4
4
  "description": "Mazey's library for front-end.",
5
5
  "main": "lib/index.cjs.js",
6
6
  "module": "lib/index.esm.js",
@@ -11,10 +11,11 @@
11
11
  },
12
12
  "scripts": {
13
13
  "dev": "webpack-dev-server --config ./scripts/webpack.config.dev.js --open",
14
- "build": "rollup --config ./scripts/rollup.config.js",
14
+ "build": "cross-env SCRIPTS_NPM_PACKAGE_DEBUG=\"close\" rollup --config ./scripts/rollup.config.js",
15
+ "build:debug": "cross-env SCRIPTS_NPM_PACKAGE_DEBUG=\"open\" rollup --config ./scripts/rollup.config.js",
15
16
  "test": "jest",
16
17
  "docs": "cross-env rm -f .docs/t.html && typedoc --hideGenerator && cp ./src/t.html ./docs",
17
- "lint-and-fix": "eslint ./src/index.ts --ext 'ts,tsx' --fix",
18
+ "lint:fix": "eslint ./src/index.ts --ext 'ts,tsx' --fix",
18
19
  "preview": "npm run docs && npm run build && npm run test",
19
20
  "release": "npm run preview && cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js"
20
21
  },
@@ -64,12 +65,15 @@
64
65
  "@babel/plugin-transform-runtime": "^7.11.0",
65
66
  "@babel/preset-env": "^7.5.5",
66
67
  "@babel/preset-typescript": "^7.10.4",
68
+ "@babel/runtime": "^7.20.7",
69
+ "@babel/runtime-corejs3": "^7.11.2",
67
70
  "@commitlint/cli": "^8.3.5",
68
71
  "@commitlint/config-conventional": "^8.3.4",
69
72
  "@typescript-eslint/eslint-plugin": "^4.22.0",
70
73
  "@typescript-eslint/parser": "^4.22.0",
71
74
  "clean-webpack-plugin": "^1.0.1",
72
75
  "cross-env": "^7.0.3",
76
+ "core-js": "^3.6.5",
73
77
  "date-fns": "^2.29.3",
74
78
  "eslint": "^6.8.0",
75
79
  "eslint-config-standard": "^14.1.0",
@@ -82,6 +86,7 @@
82
86
  "husky": "^4.3.8",
83
87
  "jest": "^27.5.1",
84
88
  "lint-staged": "^10.0.8",
89
+ "markdown-toc": "^1.2.0",
85
90
  "prettier": "^1.19.1",
86
91
  "prettier-eslint-cli": "^5.0.0",
87
92
  "rollup": "^2.79.1",
@@ -103,9 +108,5 @@
103
108
  "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
104
109
  "pre-commit": "lint-staged"
105
110
  }
106
- },
107
- "dependencies": {
108
- "@babel/runtime-corejs3": "^7.11.2",
109
- "core-js": "^3.6.5"
110
111
  }
111
112
  }
@@ -0,0 +1,28 @@
1
+ # scripts
2
+
3
+ ## release
4
+
5
+ Release this project with version by `process.env.VERSION` or `package.json`.
6
+
7
+ Usage:
8
+
9
+ ```
10
+ const pkgVersion = process.env.VERSION || require('../package.json').version;
11
+ release(pkgVersion);
12
+ ```
13
+
14
+ It will be more straightforward if you use the development dependence CrossEnv.
15
+
16
+ ```
17
+ # Install
18
+ npm i cross-env -D
19
+
20
+ # scripts
21
+ cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js
22
+
23
+ # release.js
24
+ release();
25
+ ```
26
+
27
+ <!-- @param {string} ver Version
28
+ @returns {void} -->
@@ -3,6 +3,8 @@
3
3
  const path = require('path');
4
4
  const _resolve = (_path) => path.resolve(__dirname, _path);
5
5
  const format = require('date-fns/format');
6
+ const toc = require('markdown-toc');
7
+ const fs = require('fs');
6
8
  // Generate version: 20210308.072903
7
9
  const genVersion = () => {
8
10
  const d = new Date();
@@ -11,7 +13,45 @@ const genVersion = () => {
11
13
  };
12
14
  const version = genVersion();
13
15
 
16
+ const generateToc = () => {
17
+ console.log('Generating Table of Contents...');
18
+ const RMFilePath = _resolve('../README.md');
19
+ // https://melvingeorge.me/blog/get-all-the-contents-from-file-as-string-nodejs
20
+ console.log('running...');
21
+ const buffer = fs.readFileSync(RMFilePath);
22
+ const fileContent = buffer.toString();
23
+ // https://github.com/jonschlinkert/markdown-toc
24
+ const removeUnnecessaryHeadings = (str) => {
25
+ return ![
26
+ 'mazey',
27
+ 'Install',
28
+ 'Usage',
29
+ 'Contributing',
30
+ 'License',
31
+ 'API Examples',
32
+ ].some(v => {
33
+ return str.includes(v);
34
+ });
35
+ };
36
+ let tocContent = toc(fileContent, {
37
+ filter: removeUnnecessaryHeadings,
38
+ bullets: ['-', '*'],
39
+ }).content;
40
+ tocContent = tocContent.replace(/[ ]{4}/gm, '');
41
+ tocContent = '<!-- toc - begin -->\n' + '- Generated with ❤️\n' + tocContent;
42
+ tocContent = tocContent + '\n<!-- toc - end -->';
43
+ // Insert to file.
44
+ // https://stackoverflow.com/questions/14177087/replace-a-string-in-a-file-with-nodejs
45
+ let newFileContent = fileContent;
46
+ // https://stackoverflow.com/questions/1979884/how-to-use-javascript-regex-over-multiple-lines
47
+ newFileContent = newFileContent.replace(/<!-- toc - begin -->[\s\S]*<!-- toc - end -->/gm, tocContent);
48
+ console.log('running...');
49
+ fs.writeFileSync(RMFilePath, newFileContent);
50
+ console.log('Generating Table of Contents is done.');
51
+ };
52
+
14
53
  module.exports = {
15
54
  _resolve,
16
55
  version,
56
+ generateToc,
17
57
  };
package/scripts/dev.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-undef */
2
2
  /* eslint-disable @typescript-eslint/no-var-requires */
3
3
  // const execa = require('execa');
4
- const { getGitCurrentBranch } = require('./github-helper');
4
+ const { generateToc } = require('./build-helper');
5
5
 
6
6
  (async () => {
7
7
  // const { stdout: pushMsg = '' } = await execa('git', ['push'], { stdio: 'pipe' })
@@ -17,6 +17,7 @@ const { getGitCurrentBranch } = require('./github-helper');
17
17
  // await execa('git', ['push', '--set-upstream', 'origin', currentBranch]);
18
18
  // }
19
19
  // console.log('pushMsg:', pushMsg);
20
- const cb = await getGitCurrentBranch('fix returns value');
21
- console.log('bbb', cb);
20
+ // const cb = await getGitCurrentBranch('fix returns value');
21
+ // console.log('bbb', cb);
22
+ generateToc();
22
23
  })();
@@ -2,16 +2,33 @@
2
2
  /* eslint-disable no-undef */
3
3
  // Github Helper
4
4
  const execa = require('execa');
5
+ const { generateToc } = require('./build-helper');
5
6
 
6
7
  /**
7
- * Release code.
8
- *
9
- * Example: Release code with version by `process.env.VERSION` or `package.json`.
8
+ * Release this project with version by `process.env.VERSION` or `package.json`.
9
+ *
10
+ * Usage:
10
11
  *
11
12
  * ```
12
13
  * const pkgVersion = process.env.VERSION || require('../package.json').version;
13
14
  * release(pkgVersion);
14
15
  * ```
16
+ *
17
+ * It will be more straightforward if you use the development dependence CrossEnv.
18
+ *
19
+ * ```
20
+ * # Install
21
+ * npm i cross-env -D
22
+ *
23
+ * # scripts
24
+ * cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js
25
+ *
26
+ * # release.js
27
+ * release();
28
+ * ```
29
+ *
30
+ * @param {string} ver Version
31
+ * @returns {void}
15
32
  */
16
33
  async function release (ver) {
17
34
  if (!ver) {
@@ -24,30 +41,22 @@ async function release (ver) {
24
41
  const releaseVersion = `v${ver}`;
25
42
  const { stdout: releaseStdout } = await execa('echo', [`Start release ${releaseVersion}...`]);
26
43
  console.log(releaseStdout);
27
- // commit
28
- await getCommit('stage');
29
- // marge
44
+ // Generating Table of Contents
45
+ generateToc();
46
+ // Commit
47
+ await gitCommit('stage');
48
+ // Marge
30
49
  await gitMergeMaster2Release();
31
- // build
50
+ // Build
32
51
  await execa('npm', ['run', 'preview']);
33
52
  await execa('npm', ['publish']);
34
- // git branch --show-current
35
- // console.log('git push --set-upstream origin <branch>');
36
- // Commit Stdout
37
- const { stdout: diffStdout } = await execa('git', ['diff'], { stdio: 'pipe' });
38
- if (diffStdout) {
39
- console.log('Committing changes...');
40
- await execa('git', ['add', '-A']);
41
- await execa('git', ['commit', '-m', `release: ${releaseVersion}`]);
42
- } else {
43
- console.log('No changes to commit.');
44
- }
53
+ // Commit Again
54
+ await gitCommit(releaseVersion);
45
55
  // Push
46
56
  console.log('Pushing to GitHub...');
47
57
  await execa('git', ['tag', '-a', `${releaseVersion}`, '-m', `Release ${releaseVersion}`]);
48
58
  await execa('git', ['push', 'origin', `refs/tags/${releaseVersion}`]);
49
- await gitPush(); // execa('git', ['push']);
50
-
59
+ await gitPush();
51
60
  console.log('All done.');
52
61
  }
53
62
 
@@ -58,9 +67,9 @@ async function gitPush () {
58
67
  try {
59
68
  await execa('git', ['push'], { stdio: 'pipe' });
60
69
  } catch (error) {
61
- console.log('error:', error.message);
70
+ console.log('Error:', error.message);
62
71
  const { stdout: currentBranch } = await execa('git', ['branch', '--show-current'], { stdio: 'pipe' });
63
- console.log('currentBranch:', currentBranch); // currentBranch: fix/rollup_dependences_mon_oct_31st_2022
72
+ console.log(`Current Branch: ${currentBranch}`);
64
73
  await execa('git', ['push', '--set-upstream', 'origin', currentBranch]);
65
74
  }
66
75
  return true;
@@ -86,17 +95,16 @@ async function getGitCurrentBranch () {
86
95
  try {
87
96
  ({ stdout: currentBranch } = await execa('git', ['branch', '--show-current'], { stdio: 'pipe' }));
88
97
  } catch (error) {
89
- // console.log('error:', error.message);
90
98
  ({ stdout: currentBranch } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { stdio: 'pipe' }));
91
99
  }
92
- console.log('currentBranch:', currentBranch);
100
+ console.log(`Current Branch: ${currentBranch}`);
93
101
  return currentBranch;
94
102
  }
95
103
 
96
104
  /**
97
105
  * Commit current code.
98
106
  */
99
- async function getCommit (releaseVersion = 0) {
107
+ async function gitCommit (releaseVersion = 0) {
100
108
  const { stdout: diffStdout } = await execa('git', ['diff'], { stdio: 'pipe' });
101
109
  if (diffStdout) {
102
110
  console.log('Committing changes...');
@@ -113,5 +121,5 @@ module.exports = {
113
121
  gitPush,
114
122
  gitMergeMaster2Release,
115
123
  getGitCurrentBranch,
116
- getCommit,
124
+ gitCommit,
117
125
  };