mazey 3.3.10 → 3.3.12

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.
@@ -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,47 @@ 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' + '- Generate with ❤️\n' + tocContent;
42
+ tocContent = tocContent + '\n<!-- toc - end -->';
43
+ // console.log(tocContent);
44
+ // Insert to file.
45
+ // https://stackoverflow.com/questions/14177087/replace-a-string-in-a-file-with-nodejs
46
+ let newFileContent = fileContent;
47
+ // https://stackoverflow.com/questions/1979884/how-to-use-javascript-regex-over-multiple-lines
48
+ newFileContent = newFileContent.replace(/<!-- toc - begin -->[\s\S]*<!-- toc - end -->/gm, tocContent);
49
+ // console.log(newFileContent);
50
+ console.log('running...');
51
+ fs.writeFileSync(RMFilePath, newFileContent);
52
+ console.log('Generating Table of Contents is done.');
53
+ };
54
+
14
55
  module.exports = {
15
56
  _resolve,
16
57
  version,
58
+ generateToc,
17
59
  };
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,6 +2,7 @@
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
8
  * Release code.
@@ -24,30 +25,33 @@ async function release (ver) {
24
25
  const releaseVersion = `v${ver}`;
25
26
  const { stdout: releaseStdout } = await execa('echo', [`Start release ${releaseVersion}...`]);
26
27
  console.log(releaseStdout);
27
- // commit
28
+ // Generating Table of Contents
29
+ generateToc();
30
+ // Commit
28
31
  await getCommit('stage');
29
- // marge
32
+ // Marge
30
33
  await gitMergeMaster2Release();
31
- // build
34
+ // Build
32
35
  await execa('npm', ['run', 'preview']);
33
36
  await execa('npm', ['publish']);
34
37
  // git branch --show-current
35
38
  // console.log('git push --set-upstream origin <branch>');
36
39
  // 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
- }
40
+ // const { stdout: diffStdout } = await execa('git', ['diff'], { stdio: 'pipe' });
41
+ // if (diffStdout) {
42
+ // console.log('Committing changes...');
43
+ // await execa('git', ['add', '-A']);
44
+ // await execa('git', ['commit', '-m', `release: ${releaseVersion}`]);
45
+ // } else {
46
+ // console.log('No changes to commit.');
47
+ // }
48
+ // Commit Again
49
+ await getCommit(releaseVersion);
45
50
  // Push
46
51
  console.log('Pushing to GitHub...');
47
52
  await execa('git', ['tag', '-a', `${releaseVersion}`, '-m', `Release ${releaseVersion}`]);
48
53
  await execa('git', ['push', 'origin', `refs/tags/${releaseVersion}`]);
49
54
  await gitPush(); // execa('git', ['push']);
50
-
51
55
  console.log('All done.');
52
56
  }
53
57