mazey 4.1.3 → 4.1.4
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/LICENSE +21 -21
- package/README.md +990 -990
- package/lib/browser.d.ts +2 -2
- package/lib/calc.d.ts +3 -3
- package/lib/debug.d.ts +1 -1
- package/lib/dom.d.ts +1 -1
- package/lib/global.d.ts +82 -82
- package/lib/index.cjs.js +2 -2
- package/lib/index.esm.js +2 -2
- package/lib/load.d.ts +3 -3
- package/lib/mazey.min.js +2 -2
- package/lib/perf.d.ts +1 -1
- package/lib/store.d.ts +6 -6
- package/lib/typing.d.ts +87 -87
- package/lib/url.d.ts +1 -1
- package/lib/util.d.ts +35 -15
- package/lib/util.d.ts.map +1 -1
- package/package.json +124 -124
- package/scripts/README.md +38 -38
- package/scripts/build-helper.js +76 -76
- package/scripts/dev.js +23 -23
- package/scripts/git-helper.js +163 -163
- package/scripts/release.js +9 -9
- package/scripts/rollup.config.mjs +121 -121
package/package.json
CHANGED
|
@@ -1,124 +1,124 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "mazey",
|
|
3
|
-
"version": "4.1.
|
|
4
|
-
"description": "A functional library for daily front-end work.",
|
|
5
|
-
"main": "lib/index.cjs.js",
|
|
6
|
-
"module": "lib/index.esm.js",
|
|
7
|
-
"typings": "lib/index.d.ts",
|
|
8
|
-
"types": "lib/index.d.ts",
|
|
9
|
-
"mainEntryPointFilePath": "lib/index.d.ts",
|
|
10
|
-
"directories": {
|
|
11
|
-
"lib": "./lib"
|
|
12
|
-
},
|
|
13
|
-
"unpkg": "lib/mazey.min.js",
|
|
14
|
-
"jsdelivr": "lib/mazey.min.js",
|
|
15
|
-
"scripts": {
|
|
16
|
-
"dev": "webpack serve --config ./scripts/webpack.config.dev.js --open",
|
|
17
|
-
"build": "cross-env SCRIPTS_NPM_PACKAGE_DEBUG=close SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version rollup --config ./scripts/rollup.config.mjs",
|
|
18
|
-
"build:debug": "cross-env SCRIPTS_NPM_PACKAGE_DEBUG=open SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version rollup --config ./scripts/rollup.config.mjs",
|
|
19
|
-
"test": "jest",
|
|
20
|
-
"test:debug": "npm run build:debug && npm run test",
|
|
21
|
-
"test:coverage": "npm run build:debug && npx jest --coverage",
|
|
22
|
-
"lint:fix": "eslint --ext 'js,ts,tsx' --fix ./src ./test ./scripts",
|
|
23
|
-
"docs": "typedoc --readme ./README.md --excludeProtected --excludePrivate --excludeInternal --hideGenerator",
|
|
24
|
-
"preview": "npm run build && npm run test",
|
|
25
|
-
"release": "npm run preview && cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js",
|
|
26
|
-
"release:win": "bash scripts/shell/env-win.sh && npm i --registry=https://registry.npmmirror.com && npm run release"
|
|
27
|
-
},
|
|
28
|
-
"repository": {
|
|
29
|
-
"type": "git",
|
|
30
|
-
"url": "git+https://github.com/mazeyqian/mazey.git"
|
|
31
|
-
},
|
|
32
|
-
"keywords": [
|
|
33
|
-
"front-end",
|
|
34
|
-
"load",
|
|
35
|
-
"math",
|
|
36
|
-
"url",
|
|
37
|
-
"style",
|
|
38
|
-
"css",
|
|
39
|
-
"debounce",
|
|
40
|
-
"throttle",
|
|
41
|
-
"trim",
|
|
42
|
-
"clone",
|
|
43
|
-
"json",
|
|
44
|
-
"random",
|
|
45
|
-
"dom",
|
|
46
|
-
"hash",
|
|
47
|
-
"storage",
|
|
48
|
-
"cookie",
|
|
49
|
-
"calculate",
|
|
50
|
-
"formula",
|
|
51
|
-
"browser",
|
|
52
|
-
"performance",
|
|
53
|
-
"pwa",
|
|
54
|
-
"console",
|
|
55
|
-
"function",
|
|
56
|
-
"typescript"
|
|
57
|
-
],
|
|
58
|
-
"author": {
|
|
59
|
-
"name": "Cheng",
|
|
60
|
-
"email": "mazeyqian@gmail.com",
|
|
61
|
-
"url": "https://github.com/mazeyqian"
|
|
62
|
-
},
|
|
63
|
-
"license": "MIT",
|
|
64
|
-
"bugs": {
|
|
65
|
-
"url": "https://github.com/mazeyqian/mazey/issues"
|
|
66
|
-
},
|
|
67
|
-
"homepage": "https://github.com/mazeyqian/mazey#readme",
|
|
68
|
-
"devDependencies": {
|
|
69
|
-
"@babel/core": "^7.23.2",
|
|
70
|
-
"@babel/plugin-transform-class-properties": "^7.22.5",
|
|
71
|
-
"@babel/plugin-transform-object-rest-spread": "^7.22.15",
|
|
72
|
-
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
73
|
-
"@babel/preset-env": "^7.23.2",
|
|
74
|
-
"@babel/preset-typescript": "^7.23.2",
|
|
75
|
-
"@babel/runtime": "^7.23.2",
|
|
76
|
-
"@babel/runtime-corejs3": "^7.23.2",
|
|
77
|
-
"@commitlint/cli": "^17.8.1",
|
|
78
|
-
"@commitlint/config-conventional": "^17.8.1",
|
|
79
|
-
"@rollup/plugin-babel": "^6.0.3",
|
|
80
|
-
"@rollup/plugin-commonjs": "^25.0.7",
|
|
81
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
82
|
-
"@types/jquery": "^3.5.29",
|
|
83
|
-
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
84
|
-
"@typescript-eslint/parser": "^6.12.0",
|
|
85
|
-
"clean-webpack-plugin": "^4.0.0",
|
|
86
|
-
"core-js": "^3.33.2",
|
|
87
|
-
"cross-env": "^7.0.3",
|
|
88
|
-
"date-fns": "^2.30.0",
|
|
89
|
-
"eslint": "^8.54.0",
|
|
90
|
-
"eslint-config-standard": "^17.1.0",
|
|
91
|
-
"eslint-plugin-import": "^2.29.0",
|
|
92
|
-
"eslint-plugin-node": "^11.1.0",
|
|
93
|
-
"eslint-plugin-promise": "^6.1.1",
|
|
94
|
-
"eslint-plugin-standard": "^4.1.0",
|
|
95
|
-
"execa": "^7.2.0",
|
|
96
|
-
"html-webpack-plugin": "^5.5.3",
|
|
97
|
-
"husky": "^8.0.3",
|
|
98
|
-
"jest": "^29.7.0",
|
|
99
|
-
"jest-environment-jsdom": "^29.7.0",
|
|
100
|
-
"jquery": "^3.7.1",
|
|
101
|
-
"lint-staged": "^14.0.1",
|
|
102
|
-
"markdown-toc": "^1.2.0",
|
|
103
|
-
"prettier": "^2.8.8",
|
|
104
|
-
"prettier-eslint-cli": "^8.0.1",
|
|
105
|
-
"rollup": "^3.29.4",
|
|
106
|
-
"rollup-plugin-cleaner": "^1.0.0",
|
|
107
|
-
"rollup-plugin-copy": "^3.4.0",
|
|
108
|
-
"rollup-plugin-dts": "^6.1.0",
|
|
109
|
-
"rollup-plugin-typescript2": "^0.34.1",
|
|
110
|
-
"ts-loader": "^9.4.4",
|
|
111
|
-
"tslib": "^2.6.2",
|
|
112
|
-
"typedoc": "^0.25.4",
|
|
113
|
-
"typescript": "5.3.2",
|
|
114
|
-
"webpack": "^5.89.0",
|
|
115
|
-
"webpack-cli": "^5.1.4",
|
|
116
|
-
"webpack-dev-server": "^4.15.1"
|
|
117
|
-
},
|
|
118
|
-
"husky": {
|
|
119
|
-
"hooks": {
|
|
120
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
121
|
-
"pre-commit": "lint-staged"
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "mazey",
|
|
3
|
+
"version": "4.1.4",
|
|
4
|
+
"description": "A functional library for daily front-end work.",
|
|
5
|
+
"main": "lib/index.cjs.js",
|
|
6
|
+
"module": "lib/index.esm.js",
|
|
7
|
+
"typings": "lib/index.d.ts",
|
|
8
|
+
"types": "lib/index.d.ts",
|
|
9
|
+
"mainEntryPointFilePath": "lib/index.d.ts",
|
|
10
|
+
"directories": {
|
|
11
|
+
"lib": "./lib"
|
|
12
|
+
},
|
|
13
|
+
"unpkg": "lib/mazey.min.js",
|
|
14
|
+
"jsdelivr": "lib/mazey.min.js",
|
|
15
|
+
"scripts": {
|
|
16
|
+
"dev": "webpack serve --config ./scripts/webpack.config.dev.js --open",
|
|
17
|
+
"build": "cross-env SCRIPTS_NPM_PACKAGE_DEBUG=close SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version rollup --config ./scripts/rollup.config.mjs",
|
|
18
|
+
"build:debug": "cross-env SCRIPTS_NPM_PACKAGE_DEBUG=open SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version rollup --config ./scripts/rollup.config.mjs",
|
|
19
|
+
"test": "jest",
|
|
20
|
+
"test:debug": "npm run build:debug && npm run test",
|
|
21
|
+
"test:coverage": "npm run build:debug && npx jest --coverage",
|
|
22
|
+
"lint:fix": "eslint --ext 'js,ts,tsx' --fix ./src ./test ./scripts",
|
|
23
|
+
"docs": "typedoc --readme ./README.md --excludeProtected --excludePrivate --excludeInternal --hideGenerator",
|
|
24
|
+
"preview": "npm run build && npm run test",
|
|
25
|
+
"release": "npm run preview && cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js",
|
|
26
|
+
"release:win": "bash scripts/shell/env-win.sh && npm i --registry=https://registry.npmmirror.com && npm run release"
|
|
27
|
+
},
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "git+https://github.com/mazeyqian/mazey.git"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"front-end",
|
|
34
|
+
"load",
|
|
35
|
+
"math",
|
|
36
|
+
"url",
|
|
37
|
+
"style",
|
|
38
|
+
"css",
|
|
39
|
+
"debounce",
|
|
40
|
+
"throttle",
|
|
41
|
+
"trim",
|
|
42
|
+
"clone",
|
|
43
|
+
"json",
|
|
44
|
+
"random",
|
|
45
|
+
"dom",
|
|
46
|
+
"hash",
|
|
47
|
+
"storage",
|
|
48
|
+
"cookie",
|
|
49
|
+
"calculate",
|
|
50
|
+
"formula",
|
|
51
|
+
"browser",
|
|
52
|
+
"performance",
|
|
53
|
+
"pwa",
|
|
54
|
+
"console",
|
|
55
|
+
"function",
|
|
56
|
+
"typescript"
|
|
57
|
+
],
|
|
58
|
+
"author": {
|
|
59
|
+
"name": "Cheng",
|
|
60
|
+
"email": "mazeyqian@gmail.com",
|
|
61
|
+
"url": "https://github.com/mazeyqian"
|
|
62
|
+
},
|
|
63
|
+
"license": "MIT",
|
|
64
|
+
"bugs": {
|
|
65
|
+
"url": "https://github.com/mazeyqian/mazey/issues"
|
|
66
|
+
},
|
|
67
|
+
"homepage": "https://github.com/mazeyqian/mazey#readme",
|
|
68
|
+
"devDependencies": {
|
|
69
|
+
"@babel/core": "^7.23.2",
|
|
70
|
+
"@babel/plugin-transform-class-properties": "^7.22.5",
|
|
71
|
+
"@babel/plugin-transform-object-rest-spread": "^7.22.15",
|
|
72
|
+
"@babel/plugin-transform-runtime": "^7.23.2",
|
|
73
|
+
"@babel/preset-env": "^7.23.2",
|
|
74
|
+
"@babel/preset-typescript": "^7.23.2",
|
|
75
|
+
"@babel/runtime": "^7.23.2",
|
|
76
|
+
"@babel/runtime-corejs3": "^7.23.2",
|
|
77
|
+
"@commitlint/cli": "^17.8.1",
|
|
78
|
+
"@commitlint/config-conventional": "^17.8.1",
|
|
79
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
80
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
81
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
82
|
+
"@types/jquery": "^3.5.29",
|
|
83
|
+
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
84
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
85
|
+
"clean-webpack-plugin": "^4.0.0",
|
|
86
|
+
"core-js": "^3.33.2",
|
|
87
|
+
"cross-env": "^7.0.3",
|
|
88
|
+
"date-fns": "^2.30.0",
|
|
89
|
+
"eslint": "^8.54.0",
|
|
90
|
+
"eslint-config-standard": "^17.1.0",
|
|
91
|
+
"eslint-plugin-import": "^2.29.0",
|
|
92
|
+
"eslint-plugin-node": "^11.1.0",
|
|
93
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
94
|
+
"eslint-plugin-standard": "^4.1.0",
|
|
95
|
+
"execa": "^7.2.0",
|
|
96
|
+
"html-webpack-plugin": "^5.5.3",
|
|
97
|
+
"husky": "^8.0.3",
|
|
98
|
+
"jest": "^29.7.0",
|
|
99
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
100
|
+
"jquery": "^3.7.1",
|
|
101
|
+
"lint-staged": "^14.0.1",
|
|
102
|
+
"markdown-toc": "^1.2.0",
|
|
103
|
+
"prettier": "^2.8.8",
|
|
104
|
+
"prettier-eslint-cli": "^8.0.1",
|
|
105
|
+
"rollup": "^3.29.4",
|
|
106
|
+
"rollup-plugin-cleaner": "^1.0.0",
|
|
107
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
108
|
+
"rollup-plugin-dts": "^6.1.0",
|
|
109
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
110
|
+
"ts-loader": "^9.4.4",
|
|
111
|
+
"tslib": "^2.6.2",
|
|
112
|
+
"typedoc": "^0.25.4",
|
|
113
|
+
"typescript": "5.3.2",
|
|
114
|
+
"webpack": "^5.89.0",
|
|
115
|
+
"webpack-cli": "^5.1.4",
|
|
116
|
+
"webpack-dev-server": "^4.15.1"
|
|
117
|
+
},
|
|
118
|
+
"husky": {
|
|
119
|
+
"hooks": {
|
|
120
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
121
|
+
"pre-commit": "lint-staged"
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
package/scripts/README.md
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
# scripts
|
|
2
|
-
|
|
3
|
-
## release
|
|
4
|
-
|
|
5
|
-
Release this project with version by `process.env.VERSION` or `package.json`.
|
|
6
|
-
|
|
7
|
-
Usage:
|
|
8
|
-
|
|
9
|
-
```javascript
|
|
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
|
-
```shell
|
|
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
|
-
|
|
24
|
-
```javascript
|
|
25
|
-
// release.js
|
|
26
|
-
release();
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
<!-- @param {string} ver Version
|
|
30
|
-
@returns {void} -->
|
|
31
|
-
|
|
32
|
-
## generateToc
|
|
33
|
-
|
|
34
|
-
Generate table of contents for the markdown file.
|
|
35
|
-
|
|
36
|
-
<!-- @param {string} path Path of markdown file.
|
|
37
|
-
@param {array} options.hiddenHeadings Hidden headings.
|
|
38
|
-
@returns {void} -->
|
|
1
|
+
# scripts
|
|
2
|
+
|
|
3
|
+
## release
|
|
4
|
+
|
|
5
|
+
Release this project with version by `process.env.VERSION` or `package.json`.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
|
|
9
|
+
```javascript
|
|
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
|
+
```shell
|
|
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
|
+
|
|
24
|
+
```javascript
|
|
25
|
+
// release.js
|
|
26
|
+
release();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
<!-- @param {string} ver Version
|
|
30
|
+
@returns {void} -->
|
|
31
|
+
|
|
32
|
+
## generateToc
|
|
33
|
+
|
|
34
|
+
Generate table of contents for the markdown file.
|
|
35
|
+
|
|
36
|
+
<!-- @param {string} path Path of markdown file.
|
|
37
|
+
@param {array} options.hiddenHeadings Hidden headings.
|
|
38
|
+
@returns {void} -->
|
package/scripts/build-helper.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
/* eslint-disable no-undef */
|
|
3
|
-
const path = require("path");
|
|
4
|
-
const _resolve = (_path) => path.resolve(__dirname, _path);
|
|
5
|
-
const format = require("date-fns/format");
|
|
6
|
-
const toc = require("markdown-toc");
|
|
7
|
-
const fs = require("fs");
|
|
8
|
-
// Generate version: 20210308.072903
|
|
9
|
-
const genVersion = () => {
|
|
10
|
-
const d = new Date();
|
|
11
|
-
const version = format(d, "yyyyMMdd.HHmmss");
|
|
12
|
-
return version;
|
|
13
|
-
};
|
|
14
|
-
const version = genVersion();
|
|
15
|
-
const defaultHiddenHeadings = [
|
|
16
|
-
"mazey",
|
|
17
|
-
"Install",
|
|
18
|
-
"Usage",
|
|
19
|
-
"Contributing",
|
|
20
|
-
"License",
|
|
21
|
-
"API Examples",
|
|
22
|
-
"Development Environment",
|
|
23
|
-
"Returns",
|
|
24
|
-
"Scripts",
|
|
25
|
-
"Node.js",
|
|
26
|
-
"TypeScript",
|
|
27
|
-
"Table of Contents",
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Generate table of contents for the markdown file.
|
|
32
|
-
*
|
|
33
|
-
* @param {string} path Path of markdown file.
|
|
34
|
-
* @param {array} options.hiddenHeadings Hidden headings.
|
|
35
|
-
* @returns {void}
|
|
36
|
-
*/
|
|
37
|
-
const generateToc = (path = "../README.md", options = {
|
|
38
|
-
hiddenHeadings: defaultHiddenHeadings,
|
|
39
|
-
}) => {
|
|
40
|
-
console.log("Generating Table of Contents...");
|
|
41
|
-
options = Object.assign({
|
|
42
|
-
hiddenHeadings: defaultHiddenHeadings,
|
|
43
|
-
}, options);
|
|
44
|
-
const RMFilePath = _resolve(path);
|
|
45
|
-
// https://melvingeorge.me/blog/get-all-the-contents-from-file-as-string-nodejs
|
|
46
|
-
console.log("running...");
|
|
47
|
-
const buffer = fs.readFileSync(RMFilePath);
|
|
48
|
-
const fileContent = buffer.toString();
|
|
49
|
-
// https://github.com/jonschlinkert/markdown-toc
|
|
50
|
-
const removeUnnecessaryHeadings = (str) => {
|
|
51
|
-
return !options.hiddenHeadings.some(v => {
|
|
52
|
-
return str.includes(v);
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
let tocContent = toc(fileContent, {
|
|
56
|
-
filter: removeUnnecessaryHeadings,
|
|
57
|
-
bullets: [ "-", "-" ],
|
|
58
|
-
}).content;
|
|
59
|
-
tocContent = tocContent.replace(/[ ]{4}/gm, "");
|
|
60
|
-
tocContent = "<!-- toc - begin -->\n" + "- Generated with ❤️\n" + tocContent;
|
|
61
|
-
tocContent = tocContent + "\n<!-- toc - end -->";
|
|
62
|
-
// Insert to file.
|
|
63
|
-
// https://stackoverflow.com/questions/14177087/replace-a-string-in-a-file-with-nodejs
|
|
64
|
-
let newFileContent = fileContent;
|
|
65
|
-
// https://stackoverflow.com/questions/1979884/how-to-use-javascript-regex-over-multiple-lines
|
|
66
|
-
newFileContent = newFileContent.replace(/<!-- toc - begin -->[\s\S]*<!-- toc - end -->/gm, tocContent);
|
|
67
|
-
console.log("running...");
|
|
68
|
-
fs.writeFileSync(RMFilePath, newFileContent);
|
|
69
|
-
console.log("Generating Table of Contents is done.");
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
module.exports = {
|
|
73
|
-
_resolve,
|
|
74
|
-
version,
|
|
75
|
-
generateToc,
|
|
76
|
-
};
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
/* eslint-disable no-undef */
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const _resolve = (_path) => path.resolve(__dirname, _path);
|
|
5
|
+
const format = require("date-fns/format");
|
|
6
|
+
const toc = require("markdown-toc");
|
|
7
|
+
const fs = require("fs");
|
|
8
|
+
// Generate version: 20210308.072903
|
|
9
|
+
const genVersion = () => {
|
|
10
|
+
const d = new Date();
|
|
11
|
+
const version = format(d, "yyyyMMdd.HHmmss");
|
|
12
|
+
return version;
|
|
13
|
+
};
|
|
14
|
+
const version = genVersion();
|
|
15
|
+
const defaultHiddenHeadings = [
|
|
16
|
+
"mazey",
|
|
17
|
+
"Install",
|
|
18
|
+
"Usage",
|
|
19
|
+
"Contributing",
|
|
20
|
+
"License",
|
|
21
|
+
"API Examples",
|
|
22
|
+
"Development Environment",
|
|
23
|
+
"Returns",
|
|
24
|
+
"Scripts",
|
|
25
|
+
"Node.js",
|
|
26
|
+
"TypeScript",
|
|
27
|
+
"Table of Contents",
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generate table of contents for the markdown file.
|
|
32
|
+
*
|
|
33
|
+
* @param {string} path Path of markdown file.
|
|
34
|
+
* @param {array} options.hiddenHeadings Hidden headings.
|
|
35
|
+
* @returns {void}
|
|
36
|
+
*/
|
|
37
|
+
const generateToc = (path = "../README.md", options = {
|
|
38
|
+
hiddenHeadings: defaultHiddenHeadings,
|
|
39
|
+
}) => {
|
|
40
|
+
console.log("Generating Table of Contents...");
|
|
41
|
+
options = Object.assign({
|
|
42
|
+
hiddenHeadings: defaultHiddenHeadings,
|
|
43
|
+
}, options);
|
|
44
|
+
const RMFilePath = _resolve(path);
|
|
45
|
+
// https://melvingeorge.me/blog/get-all-the-contents-from-file-as-string-nodejs
|
|
46
|
+
console.log("running...");
|
|
47
|
+
const buffer = fs.readFileSync(RMFilePath);
|
|
48
|
+
const fileContent = buffer.toString();
|
|
49
|
+
// https://github.com/jonschlinkert/markdown-toc
|
|
50
|
+
const removeUnnecessaryHeadings = (str) => {
|
|
51
|
+
return !options.hiddenHeadings.some(v => {
|
|
52
|
+
return str.includes(v);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
let tocContent = toc(fileContent, {
|
|
56
|
+
filter: removeUnnecessaryHeadings,
|
|
57
|
+
bullets: [ "-", "-" ],
|
|
58
|
+
}).content;
|
|
59
|
+
tocContent = tocContent.replace(/[ ]{4}/gm, "");
|
|
60
|
+
tocContent = "<!-- toc - begin -->\n" + "- Generated with ❤️\n" + tocContent;
|
|
61
|
+
tocContent = tocContent + "\n<!-- toc - end -->";
|
|
62
|
+
// Insert to file.
|
|
63
|
+
// https://stackoverflow.com/questions/14177087/replace-a-string-in-a-file-with-nodejs
|
|
64
|
+
let newFileContent = fileContent;
|
|
65
|
+
// https://stackoverflow.com/questions/1979884/how-to-use-javascript-regex-over-multiple-lines
|
|
66
|
+
newFileContent = newFileContent.replace(/<!-- toc - begin -->[\s\S]*<!-- toc - end -->/gm, tocContent);
|
|
67
|
+
console.log("running...");
|
|
68
|
+
fs.writeFileSync(RMFilePath, newFileContent);
|
|
69
|
+
console.log("Generating Table of Contents is done.");
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
_resolve,
|
|
74
|
+
version,
|
|
75
|
+
generateToc,
|
|
76
|
+
};
|
package/scripts/dev.js
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
/* eslint-disable no-undef */
|
|
2
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
-
// const execa = require('execa');
|
|
4
|
-
const { generateToc } = require("./build-helper");
|
|
5
|
-
|
|
6
|
-
(async () => {
|
|
7
|
-
// const { stdout: pushMsg = '' } = await execa('git', ['push'], { stdio: 'pipe' })
|
|
8
|
-
// .catch(error => {
|
|
9
|
-
// console.log('error:', error.message);
|
|
10
|
-
// });
|
|
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
|
-
// }
|
|
19
|
-
// console.log('pushMsg:', pushMsg);
|
|
20
|
-
// const cb = await getGitCurrentBranch('fix returns value');
|
|
21
|
-
// console.log('bbb', cb);
|
|
22
|
-
generateToc();
|
|
23
|
-
})();
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
3
|
+
// const execa = require('execa');
|
|
4
|
+
const { generateToc } = require("./build-helper");
|
|
5
|
+
|
|
6
|
+
(async () => {
|
|
7
|
+
// const { stdout: pushMsg = '' } = await execa('git', ['push'], { stdio: 'pipe' })
|
|
8
|
+
// .catch(error => {
|
|
9
|
+
// console.log('error:', error.message);
|
|
10
|
+
// });
|
|
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
|
+
// }
|
|
19
|
+
// console.log('pushMsg:', pushMsg);
|
|
20
|
+
// const cb = await getGitCurrentBranch('fix returns value');
|
|
21
|
+
// console.log('bbb', cb);
|
|
22
|
+
generateToc();
|
|
23
|
+
})();
|