mazey 3.3.12 → 3.4.1
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/README.md +41 -41
- package/README_CN.md +8 -2
- package/lib/index.cjs.js +3 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +3 -3
- package/lib/mazey.min.js +3 -3
- package/package.json +8 -8
- package/scripts/README.md +28 -0
- package/scripts/build-helper.js +1 -3
- package/scripts/github-helper.js +31 -25
- package/scripts/release.js +1 -1
- package/src/index.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mazey",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
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
|
-
"docs": "cross-env rm -f
|
|
17
|
-
"lint
|
|
17
|
+
"docs": "cross-env rm -f ./docs/t.html && typedoc --hideGenerator && cp ./src/t.html ./docs",
|
|
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",
|
|
@@ -104,9 +108,5 @@
|
|
|
104
108
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
105
109
|
"pre-commit": "lint-staged"
|
|
106
110
|
}
|
|
107
|
-
},
|
|
108
|
-
"dependencies": {
|
|
109
|
-
"@babel/runtime-corejs3": "^7.11.2",
|
|
110
|
-
"core-js": "^3.6.5"
|
|
111
111
|
}
|
|
112
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} -->
|
package/scripts/build-helper.js
CHANGED
|
@@ -38,15 +38,13 @@ const generateToc = () => {
|
|
|
38
38
|
bullets: ['-', '*'],
|
|
39
39
|
}).content;
|
|
40
40
|
tocContent = tocContent.replace(/[ ]{4}/gm, '');
|
|
41
|
-
tocContent = '<!-- toc - begin -->\n' + '-
|
|
41
|
+
tocContent = '<!-- toc - begin -->\n' + '- Generated with ❤️\n' + tocContent;
|
|
42
42
|
tocContent = tocContent + '\n<!-- toc - end -->';
|
|
43
|
-
// console.log(tocContent);
|
|
44
43
|
// Insert to file.
|
|
45
44
|
// https://stackoverflow.com/questions/14177087/replace-a-string-in-a-file-with-nodejs
|
|
46
45
|
let newFileContent = fileContent;
|
|
47
46
|
// https://stackoverflow.com/questions/1979884/how-to-use-javascript-regex-over-multiple-lines
|
|
48
47
|
newFileContent = newFileContent.replace(/<!-- toc - begin -->[\s\S]*<!-- toc - end -->/gm, tocContent);
|
|
49
|
-
// console.log(newFileContent);
|
|
50
48
|
console.log('running...');
|
|
51
49
|
fs.writeFileSync(RMFilePath, newFileContent);
|
|
52
50
|
console.log('Generating Table of Contents is done.');
|
package/scripts/github-helper.js
CHANGED
|
@@ -5,16 +5,32 @@ const execa = require('execa');
|
|
|
5
5
|
const { generateToc } = require('./build-helper');
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Release
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Release this project with version by `process.env.VERSION` or `package.json`.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
11
|
*
|
|
12
12
|
* ```
|
|
13
13
|
* const pkgVersion = process.env.VERSION || require('../package.json').version;
|
|
14
14
|
* release(pkgVersion);
|
|
15
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}
|
|
16
32
|
*/
|
|
17
|
-
async function release (ver) {
|
|
33
|
+
async function release (ver, { canGenerateToc = false } = {}) {
|
|
18
34
|
if (!ver) {
|
|
19
35
|
ver = process.env.SCRIPTS_NPM_PACKAGE_VERSION;
|
|
20
36
|
}
|
|
@@ -26,32 +42,23 @@ async function release (ver) {
|
|
|
26
42
|
const { stdout: releaseStdout } = await execa('echo', [`Start release ${releaseVersion}...`]);
|
|
27
43
|
console.log(releaseStdout);
|
|
28
44
|
// Generating Table of Contents
|
|
29
|
-
|
|
45
|
+
if (canGenerateToc) {
|
|
46
|
+
generateToc();
|
|
47
|
+
}
|
|
30
48
|
// Commit
|
|
31
|
-
await
|
|
49
|
+
await gitCommit('stage');
|
|
32
50
|
// Marge
|
|
33
51
|
await gitMergeMaster2Release();
|
|
34
52
|
// Build
|
|
35
53
|
await execa('npm', ['run', 'preview']);
|
|
36
54
|
await execa('npm', ['publish']);
|
|
37
|
-
// git branch --show-current
|
|
38
|
-
// console.log('git push --set-upstream origin <branch>');
|
|
39
|
-
// Commit Stdout
|
|
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
55
|
// Commit Again
|
|
49
|
-
await
|
|
56
|
+
await gitCommit(releaseVersion);
|
|
50
57
|
// Push
|
|
51
58
|
console.log('Pushing to GitHub...');
|
|
52
59
|
await execa('git', ['tag', '-a', `${releaseVersion}`, '-m', `Release ${releaseVersion}`]);
|
|
53
60
|
await execa('git', ['push', 'origin', `refs/tags/${releaseVersion}`]);
|
|
54
|
-
await gitPush();
|
|
61
|
+
await gitPush();
|
|
55
62
|
console.log('All done.');
|
|
56
63
|
}
|
|
57
64
|
|
|
@@ -62,9 +69,9 @@ async function gitPush () {
|
|
|
62
69
|
try {
|
|
63
70
|
await execa('git', ['push'], { stdio: 'pipe' });
|
|
64
71
|
} catch (error) {
|
|
65
|
-
console.log('
|
|
72
|
+
console.log('Error:', error.message);
|
|
66
73
|
const { stdout: currentBranch } = await execa('git', ['branch', '--show-current'], { stdio: 'pipe' });
|
|
67
|
-
console.log(
|
|
74
|
+
console.log(`Current Branch: ${currentBranch}`);
|
|
68
75
|
await execa('git', ['push', '--set-upstream', 'origin', currentBranch]);
|
|
69
76
|
}
|
|
70
77
|
return true;
|
|
@@ -90,17 +97,16 @@ async function getGitCurrentBranch () {
|
|
|
90
97
|
try {
|
|
91
98
|
({ stdout: currentBranch } = await execa('git', ['branch', '--show-current'], { stdio: 'pipe' }));
|
|
92
99
|
} catch (error) {
|
|
93
|
-
// console.log('error:', error.message);
|
|
94
100
|
({ stdout: currentBranch } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { stdio: 'pipe' }));
|
|
95
101
|
}
|
|
96
|
-
console.log(
|
|
102
|
+
console.log(`Current Branch: ${currentBranch}`);
|
|
97
103
|
return currentBranch;
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
/**
|
|
101
107
|
* Commit current code.
|
|
102
108
|
*/
|
|
103
|
-
async function
|
|
109
|
+
async function gitCommit (releaseVersion = 0) {
|
|
104
110
|
const { stdout: diffStdout } = await execa('git', ['diff'], { stdio: 'pipe' });
|
|
105
111
|
if (diffStdout) {
|
|
106
112
|
console.log('Committing changes...');
|
|
@@ -117,5 +123,5 @@ module.exports = {
|
|
|
117
123
|
gitPush,
|
|
118
124
|
gitMergeMaster2Release,
|
|
119
125
|
getGitCurrentBranch,
|
|
120
|
-
|
|
126
|
+
gitCommit,
|
|
121
127
|
};
|
package/scripts/release.js
CHANGED
package/src/index.ts
CHANGED
|
@@ -590,7 +590,7 @@ export function debounce(func: any, wait: number, immediate?: any): any {
|
|
|
590
590
|
* @param {number/Date} start 开始时间戳 1585325367122
|
|
591
591
|
* @param {number/Date} end 结束时间戳 1585325367122
|
|
592
592
|
* @param {string} options.type 返回类型 d: 2(天) text: 2 天 4 时...
|
|
593
|
-
* @returns {
|
|
593
|
+
* @returns {string/number} 取决于 type
|
|
594
594
|
*/
|
|
595
595
|
export function friendlyInterval(
|
|
596
596
|
start = 0,
|