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/scripts/git-helper.js
CHANGED
|
@@ -1,163 +1,163 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
/* eslint-disable no-undef */
|
|
3
|
-
// Git Helper
|
|
4
|
-
const execa = require("execa");
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Release this project with version by `process.env.VERSION` or `package.json`.
|
|
8
|
-
*
|
|
9
|
-
* Usage:
|
|
10
|
-
*
|
|
11
|
-
* ```javascript
|
|
12
|
-
* const pkgVersion = process.env.VERSION || require('../package.json').version;
|
|
13
|
-
* release(pkgVersion);
|
|
14
|
-
* ```
|
|
15
|
-
*
|
|
16
|
-
* It will be more straightforward if you use the development dependence CrossEnv.
|
|
17
|
-
*
|
|
18
|
-
* ```shell
|
|
19
|
-
* # Install
|
|
20
|
-
* npm i cross-env -D
|
|
21
|
-
*
|
|
22
|
-
* # scripts
|
|
23
|
-
* cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* ```javascript
|
|
27
|
-
* // release.js
|
|
28
|
-
* release();
|
|
29
|
-
* ```
|
|
30
|
-
*
|
|
31
|
-
* @param {string} ver Version
|
|
32
|
-
* @returns {void}
|
|
33
|
-
*/
|
|
34
|
-
async function release (ver, { canGenerateToc = false, defaultBranch = "main" } = {}) {
|
|
35
|
-
if (!ver) {
|
|
36
|
-
ver = process.env.SCRIPTS_NPM_PACKAGE_VERSION;
|
|
37
|
-
}
|
|
38
|
-
if (!ver) {
|
|
39
|
-
console.error("Fail to get the current version.");
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
const { generateToc } = require("./build-helper");
|
|
43
|
-
const releaseVersion = `v${ver}`;
|
|
44
|
-
const { stdout: releaseStdout } = await execa("echo", [ `Start release ${releaseVersion}...` ]);
|
|
45
|
-
console.log(releaseStdout);
|
|
46
|
-
// Generating Table of Contents
|
|
47
|
-
if (canGenerateToc) {
|
|
48
|
-
generateToc();
|
|
49
|
-
}
|
|
50
|
-
// Commit
|
|
51
|
-
await gitCommit(`${releaseVersion} stage`);
|
|
52
|
-
// Marge
|
|
53
|
-
await gitMergeMain2Release(defaultBranch);
|
|
54
|
-
// Build
|
|
55
|
-
await execa("npm", [ "run", "preview" ]);
|
|
56
|
-
await execa("npm", [ "publish" ]);
|
|
57
|
-
// Commit Again
|
|
58
|
-
await gitCommit(releaseVersion);
|
|
59
|
-
// Push
|
|
60
|
-
console.log("Pushing to the remote Git...");
|
|
61
|
-
// await execa('git', ['tag', '-a', `${releaseVersion}`, '-m', `Release ${releaseVersion}`]);
|
|
62
|
-
// await execa('git', ['push', 'origin', `refs/tags/${releaseVersion}`]);
|
|
63
|
-
await gitTagPush(releaseVersion);
|
|
64
|
-
await gitPush();
|
|
65
|
-
console.log("All done.");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Push git tag.
|
|
70
|
-
*
|
|
71
|
-
* @example
|
|
72
|
-
* ```
|
|
73
|
-
* await gitTagPush('v1.0.0');
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* @param {string} ver Release version
|
|
77
|
-
* @returns {boolean} Is success
|
|
78
|
-
*/
|
|
79
|
-
async function gitTagPush (ver = "") {
|
|
80
|
-
if (!ver) {
|
|
81
|
-
console.error("Fail to get the current version.");
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
if (!ver.startsWith("v")) {
|
|
85
|
-
ver = `v${ver}`;
|
|
86
|
-
}
|
|
87
|
-
await execa("git", [ "tag", "-a", `${ver}`, "-m", `Release ${ver}` ]);
|
|
88
|
-
await execa("git", [ "push", "origin", `refs/tags/${ver}` ]);
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Push code.
|
|
94
|
-
*/
|
|
95
|
-
async function gitPush () {
|
|
96
|
-
try {
|
|
97
|
-
await execa("git", [ "push" ], { stdio: "pipe" });
|
|
98
|
-
} catch (error) {
|
|
99
|
-
console.log("Error:", error.message);
|
|
100
|
-
const { stdout: currentBranch } = await execa("git", [ "branch", "--show-current" ], { stdio: "pipe" });
|
|
101
|
-
console.log(`Current Branch: ${currentBranch}`);
|
|
102
|
-
await execa("git", [ "push", "--set-upstream", "origin", currentBranch ]);
|
|
103
|
-
}
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Merge main to current branch.
|
|
109
|
-
*/
|
|
110
|
-
async function gitMergeMain2Release (defaultBranch = "main") {
|
|
111
|
-
const currentBranch = await getGitCurrentBranch();
|
|
112
|
-
await execa("git", [ "checkout", defaultBranch ]);
|
|
113
|
-
await execa("git", [ "pull" ]);
|
|
114
|
-
await execa("git", [ "checkout", currentBranch ]);
|
|
115
|
-
await execa("git", [ "merge", defaultBranch ]);
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Alias of `gitMergeMain2Release`.
|
|
121
|
-
*/
|
|
122
|
-
async function gitMergeMaster2Release (defaultBranch = "main") {
|
|
123
|
-
return await gitMergeMain2Release(defaultBranch);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Get git current branch.
|
|
128
|
-
*/
|
|
129
|
-
async function getGitCurrentBranch () {
|
|
130
|
-
let currentBranch = "";
|
|
131
|
-
try {
|
|
132
|
-
({ stdout: currentBranch } = await execa("git", [ "branch", "--show-current" ], { stdio: "pipe" }));
|
|
133
|
-
} catch (error) {
|
|
134
|
-
({ stdout: currentBranch } = await execa("git", [ "rev-parse", "--abbrev-ref", "HEAD" ], { stdio: "pipe" }));
|
|
135
|
-
}
|
|
136
|
-
console.log(`Current Branch: ${currentBranch}`);
|
|
137
|
-
return currentBranch;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Commit current code.
|
|
142
|
-
*/
|
|
143
|
-
async function gitCommit (releaseVersion = 0) {
|
|
144
|
-
const { stdout: diffStdout } = await execa("git", [ "diff" ], { stdio: "pipe" });
|
|
145
|
-
if (diffStdout) {
|
|
146
|
-
console.log("Committing changes...");
|
|
147
|
-
await execa("git", [ "add", "-A" ]);
|
|
148
|
-
await execa("git", [ "commit", "-m", `release: ${releaseVersion}` ]);
|
|
149
|
-
} else {
|
|
150
|
-
console.log("No changes to commit.");
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
module.exports = {
|
|
156
|
-
release,
|
|
157
|
-
gitPush,
|
|
158
|
-
gitMergeMaster2Release, // Deprecated
|
|
159
|
-
gitMergeMain2Release,
|
|
160
|
-
getGitCurrentBranch,
|
|
161
|
-
gitCommit,
|
|
162
|
-
gitTagPush,
|
|
163
|
-
};
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
/* eslint-disable no-undef */
|
|
3
|
+
// Git Helper
|
|
4
|
+
const execa = require("execa");
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Release this project with version by `process.env.VERSION` or `package.json`.
|
|
8
|
+
*
|
|
9
|
+
* Usage:
|
|
10
|
+
*
|
|
11
|
+
* ```javascript
|
|
12
|
+
* const pkgVersion = process.env.VERSION || require('../package.json').version;
|
|
13
|
+
* release(pkgVersion);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* It will be more straightforward if you use the development dependence CrossEnv.
|
|
17
|
+
*
|
|
18
|
+
* ```shell
|
|
19
|
+
* # Install
|
|
20
|
+
* npm i cross-env -D
|
|
21
|
+
*
|
|
22
|
+
* # scripts
|
|
23
|
+
* cross-env SCRIPTS_NPM_PACKAGE_VERSION=$npm_package_version node ./scripts/release.js
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* ```javascript
|
|
27
|
+
* // release.js
|
|
28
|
+
* release();
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @param {string} ver Version
|
|
32
|
+
* @returns {void}
|
|
33
|
+
*/
|
|
34
|
+
async function release (ver, { canGenerateToc = false, defaultBranch = "main" } = {}) {
|
|
35
|
+
if (!ver) {
|
|
36
|
+
ver = process.env.SCRIPTS_NPM_PACKAGE_VERSION;
|
|
37
|
+
}
|
|
38
|
+
if (!ver) {
|
|
39
|
+
console.error("Fail to get the current version.");
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const { generateToc } = require("./build-helper");
|
|
43
|
+
const releaseVersion = `v${ver}`;
|
|
44
|
+
const { stdout: releaseStdout } = await execa("echo", [ `Start release ${releaseVersion}...` ]);
|
|
45
|
+
console.log(releaseStdout);
|
|
46
|
+
// Generating Table of Contents
|
|
47
|
+
if (canGenerateToc) {
|
|
48
|
+
generateToc();
|
|
49
|
+
}
|
|
50
|
+
// Commit
|
|
51
|
+
await gitCommit(`${releaseVersion} stage`);
|
|
52
|
+
// Marge
|
|
53
|
+
await gitMergeMain2Release(defaultBranch);
|
|
54
|
+
// Build
|
|
55
|
+
await execa("npm", [ "run", "preview" ]);
|
|
56
|
+
await execa("npm", [ "publish" ]);
|
|
57
|
+
// Commit Again
|
|
58
|
+
await gitCommit(releaseVersion);
|
|
59
|
+
// Push
|
|
60
|
+
console.log("Pushing to the remote Git...");
|
|
61
|
+
// await execa('git', ['tag', '-a', `${releaseVersion}`, '-m', `Release ${releaseVersion}`]);
|
|
62
|
+
// await execa('git', ['push', 'origin', `refs/tags/${releaseVersion}`]);
|
|
63
|
+
await gitTagPush(releaseVersion);
|
|
64
|
+
await gitPush();
|
|
65
|
+
console.log("All done.");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Push git tag.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```
|
|
73
|
+
* await gitTagPush('v1.0.0');
|
|
74
|
+
* ```
|
|
75
|
+
*
|
|
76
|
+
* @param {string} ver Release version
|
|
77
|
+
* @returns {boolean} Is success
|
|
78
|
+
*/
|
|
79
|
+
async function gitTagPush (ver = "") {
|
|
80
|
+
if (!ver) {
|
|
81
|
+
console.error("Fail to get the current version.");
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
if (!ver.startsWith("v")) {
|
|
85
|
+
ver = `v${ver}`;
|
|
86
|
+
}
|
|
87
|
+
await execa("git", [ "tag", "-a", `${ver}`, "-m", `Release ${ver}` ]);
|
|
88
|
+
await execa("git", [ "push", "origin", `refs/tags/${ver}` ]);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Push code.
|
|
94
|
+
*/
|
|
95
|
+
async function gitPush () {
|
|
96
|
+
try {
|
|
97
|
+
await execa("git", [ "push" ], { stdio: "pipe" });
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.log("Error:", error.message);
|
|
100
|
+
const { stdout: currentBranch } = await execa("git", [ "branch", "--show-current" ], { stdio: "pipe" });
|
|
101
|
+
console.log(`Current Branch: ${currentBranch}`);
|
|
102
|
+
await execa("git", [ "push", "--set-upstream", "origin", currentBranch ]);
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Merge main to current branch.
|
|
109
|
+
*/
|
|
110
|
+
async function gitMergeMain2Release (defaultBranch = "main") {
|
|
111
|
+
const currentBranch = await getGitCurrentBranch();
|
|
112
|
+
await execa("git", [ "checkout", defaultBranch ]);
|
|
113
|
+
await execa("git", [ "pull" ]);
|
|
114
|
+
await execa("git", [ "checkout", currentBranch ]);
|
|
115
|
+
await execa("git", [ "merge", defaultBranch ]);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Alias of `gitMergeMain2Release`.
|
|
121
|
+
*/
|
|
122
|
+
async function gitMergeMaster2Release (defaultBranch = "main") {
|
|
123
|
+
return await gitMergeMain2Release(defaultBranch);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get git current branch.
|
|
128
|
+
*/
|
|
129
|
+
async function getGitCurrentBranch () {
|
|
130
|
+
let currentBranch = "";
|
|
131
|
+
try {
|
|
132
|
+
({ stdout: currentBranch } = await execa("git", [ "branch", "--show-current" ], { stdio: "pipe" }));
|
|
133
|
+
} catch (error) {
|
|
134
|
+
({ stdout: currentBranch } = await execa("git", [ "rev-parse", "--abbrev-ref", "HEAD" ], { stdio: "pipe" }));
|
|
135
|
+
}
|
|
136
|
+
console.log(`Current Branch: ${currentBranch}`);
|
|
137
|
+
return currentBranch;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Commit current code.
|
|
142
|
+
*/
|
|
143
|
+
async function gitCommit (releaseVersion = 0) {
|
|
144
|
+
const { stdout: diffStdout } = await execa("git", [ "diff" ], { stdio: "pipe" });
|
|
145
|
+
if (diffStdout) {
|
|
146
|
+
console.log("Committing changes...");
|
|
147
|
+
await execa("git", [ "add", "-A" ]);
|
|
148
|
+
await execa("git", [ "commit", "-m", `release: ${releaseVersion}` ]);
|
|
149
|
+
} else {
|
|
150
|
+
console.log("No changes to commit.");
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
release,
|
|
157
|
+
gitPush,
|
|
158
|
+
gitMergeMaster2Release, // Deprecated
|
|
159
|
+
gitMergeMain2Release,
|
|
160
|
+
getGitCurrentBranch,
|
|
161
|
+
gitCommit,
|
|
162
|
+
gitTagPush,
|
|
163
|
+
};
|
package/scripts/release.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
/* eslint-disable no-undef */
|
|
3
|
-
// release
|
|
4
|
-
const { release } = require("./git-helper");
|
|
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);
|
|
8
|
-
|
|
9
|
-
release(pkgVersion, { canGenerateToc: true });
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
/* eslint-disable no-undef */
|
|
3
|
+
// release
|
|
4
|
+
const { release } = require("./git-helper");
|
|
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);
|
|
8
|
+
|
|
9
|
+
release(pkgVersion, { canGenerateToc: true });
|
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
-
/* eslint-disable no-undef */
|
|
3
|
-
import { babel } from "@rollup/plugin-babel";
|
|
4
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
5
|
-
import rollupTypescript from "rollup-plugin-typescript2";
|
|
6
|
-
import { DEFAULT_EXTENSIONS } from "@babel/core";
|
|
7
|
-
import cleaner from "rollup-plugin-cleaner";
|
|
8
|
-
import terser from "@rollup/plugin-terser";
|
|
9
|
-
import { dts } from "rollup-plugin-dts";
|
|
10
|
-
import path from "path";
|
|
11
|
-
import { fileURLToPath } from "url";
|
|
12
|
-
import { dirname } from "path";
|
|
13
|
-
|
|
14
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
-
const __dirname = dirname(__filename);
|
|
16
|
-
const _resolve = (_path) => path.resolve(__dirname, _path);
|
|
17
|
-
const pkgVersion = process.env.SCRIPTS_NPM_PACKAGE_VERSION || process.env.VERSION || "unknown";
|
|
18
|
-
const debugMode = process.env.SCRIPTS_NPM_PACKAGE_DEBUG;
|
|
19
|
-
const banner =
|
|
20
|
-
"/*!\n" +
|
|
21
|
-
` * Mazey v${pkgVersion} https://github.com/mazeyqian/mazey\n` +
|
|
22
|
-
` * (c) 2018-${new Date().getFullYear()} Cheng\n` +
|
|
23
|
-
" * Released under the MIT License.\n" +
|
|
24
|
-
" */";
|
|
25
|
-
const plugins = [
|
|
26
|
-
rollupTypescript(),
|
|
27
|
-
commonjs({
|
|
28
|
-
include: /node_modules/,
|
|
29
|
-
}),
|
|
30
|
-
babel({
|
|
31
|
-
babelHelpers: "runtime",
|
|
32
|
-
// Just convert the source code, don't run external dependencies.
|
|
33
|
-
exclude: "**/node_modules/**",
|
|
34
|
-
// Babel does not support TypeScript by default; it needs to be manually added.
|
|
35
|
-
extensions: [
|
|
36
|
-
...DEFAULT_EXTENSIONS,
|
|
37
|
-
".ts",
|
|
38
|
-
],
|
|
39
|
-
}),
|
|
40
|
-
];
|
|
41
|
-
const iifePlugins = [];
|
|
42
|
-
const dTsConf = {
|
|
43
|
-
input: _resolve("../src/typing.d.ts"),
|
|
44
|
-
// https://rollupjs.org/guide/en/#outputformat
|
|
45
|
-
output: [
|
|
46
|
-
{
|
|
47
|
-
file: _resolve("../lib/typing.d.ts"),
|
|
48
|
-
format: "es",
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
plugins: [
|
|
52
|
-
dts(),
|
|
53
|
-
],
|
|
54
|
-
external: [],
|
|
55
|
-
};
|
|
56
|
-
const gTsConf = {
|
|
57
|
-
input: _resolve("../types/global.d.ts"),
|
|
58
|
-
output: [
|
|
59
|
-
{
|
|
60
|
-
file: _resolve("../lib/global.d.ts"),
|
|
61
|
-
format: "es",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
plugins: [
|
|
65
|
-
dts(),
|
|
66
|
-
],
|
|
67
|
-
external: [],
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
if (debugMode !== "open") {
|
|
71
|
-
iifePlugins.push(
|
|
72
|
-
// Add minification.
|
|
73
|
-
// https://github.com/TrySound/rollup-plugin-terser
|
|
74
|
-
terser({ // https://github.com/terser/terser
|
|
75
|
-
format: {
|
|
76
|
-
// https://github.com/terser/terser#format-options
|
|
77
|
-
comments: /^!\n\s\*\sMazey/,
|
|
78
|
-
},
|
|
79
|
-
}),
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// https://rollupjs.org/guide/en/
|
|
84
|
-
export default [
|
|
85
|
-
{
|
|
86
|
-
input: _resolve("../src/index.ts"),
|
|
87
|
-
// https://rollupjs.org/guide/en/#outputformat
|
|
88
|
-
output: [
|
|
89
|
-
{
|
|
90
|
-
file: _resolve("../lib/index.cjs.js"),
|
|
91
|
-
format: "cjs",
|
|
92
|
-
banner,
|
|
93
|
-
plugins: iifePlugins,
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
file: _resolve("../lib/index.esm.js"),
|
|
97
|
-
format: "esm",
|
|
98
|
-
banner,
|
|
99
|
-
plugins: iifePlugins,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
file: _resolve("../lib/mazey.min.js"),
|
|
103
|
-
format: "iife",
|
|
104
|
-
name: "mazey",
|
|
105
|
-
banner,
|
|
106
|
-
plugins: iifePlugins,
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
plugins: [
|
|
110
|
-
...plugins,
|
|
111
|
-
cleaner({
|
|
112
|
-
targets: [
|
|
113
|
-
_resolve("../lib/"),
|
|
114
|
-
],
|
|
115
|
-
}),
|
|
116
|
-
],
|
|
117
|
-
external: [],
|
|
118
|
-
},
|
|
119
|
-
dTsConf,
|
|
120
|
-
gTsConf,
|
|
121
|
-
];
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
2
|
+
/* eslint-disable no-undef */
|
|
3
|
+
import { babel } from "@rollup/plugin-babel";
|
|
4
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
5
|
+
import rollupTypescript from "rollup-plugin-typescript2";
|
|
6
|
+
import { DEFAULT_EXTENSIONS } from "@babel/core";
|
|
7
|
+
import cleaner from "rollup-plugin-cleaner";
|
|
8
|
+
import terser from "@rollup/plugin-terser";
|
|
9
|
+
import { dts } from "rollup-plugin-dts";
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { fileURLToPath } from "url";
|
|
12
|
+
import { dirname } from "path";
|
|
13
|
+
|
|
14
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
15
|
+
const __dirname = dirname(__filename);
|
|
16
|
+
const _resolve = (_path) => path.resolve(__dirname, _path);
|
|
17
|
+
const pkgVersion = process.env.SCRIPTS_NPM_PACKAGE_VERSION || process.env.VERSION || "unknown";
|
|
18
|
+
const debugMode = process.env.SCRIPTS_NPM_PACKAGE_DEBUG;
|
|
19
|
+
const banner =
|
|
20
|
+
"/*!\n" +
|
|
21
|
+
` * Mazey v${pkgVersion} https://github.com/mazeyqian/mazey\n` +
|
|
22
|
+
` * (c) 2018-${new Date().getFullYear()} Cheng\n` +
|
|
23
|
+
" * Released under the MIT License.\n" +
|
|
24
|
+
" */";
|
|
25
|
+
const plugins = [
|
|
26
|
+
rollupTypescript(),
|
|
27
|
+
commonjs({
|
|
28
|
+
include: /node_modules/,
|
|
29
|
+
}),
|
|
30
|
+
babel({
|
|
31
|
+
babelHelpers: "runtime",
|
|
32
|
+
// Just convert the source code, don't run external dependencies.
|
|
33
|
+
exclude: "**/node_modules/**",
|
|
34
|
+
// Babel does not support TypeScript by default; it needs to be manually added.
|
|
35
|
+
extensions: [
|
|
36
|
+
...DEFAULT_EXTENSIONS,
|
|
37
|
+
".ts",
|
|
38
|
+
],
|
|
39
|
+
}),
|
|
40
|
+
];
|
|
41
|
+
const iifePlugins = [];
|
|
42
|
+
const dTsConf = {
|
|
43
|
+
input: _resolve("../src/typing.d.ts"),
|
|
44
|
+
// https://rollupjs.org/guide/en/#outputformat
|
|
45
|
+
output: [
|
|
46
|
+
{
|
|
47
|
+
file: _resolve("../lib/typing.d.ts"),
|
|
48
|
+
format: "es",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
plugins: [
|
|
52
|
+
dts(),
|
|
53
|
+
],
|
|
54
|
+
external: [],
|
|
55
|
+
};
|
|
56
|
+
const gTsConf = {
|
|
57
|
+
input: _resolve("../types/global.d.ts"),
|
|
58
|
+
output: [
|
|
59
|
+
{
|
|
60
|
+
file: _resolve("../lib/global.d.ts"),
|
|
61
|
+
format: "es",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
plugins: [
|
|
65
|
+
dts(),
|
|
66
|
+
],
|
|
67
|
+
external: [],
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
if (debugMode !== "open") {
|
|
71
|
+
iifePlugins.push(
|
|
72
|
+
// Add minification.
|
|
73
|
+
// https://github.com/TrySound/rollup-plugin-terser
|
|
74
|
+
terser({ // https://github.com/terser/terser
|
|
75
|
+
format: {
|
|
76
|
+
// https://github.com/terser/terser#format-options
|
|
77
|
+
comments: /^!\n\s\*\sMazey/,
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// https://rollupjs.org/guide/en/
|
|
84
|
+
export default [
|
|
85
|
+
{
|
|
86
|
+
input: _resolve("../src/index.ts"),
|
|
87
|
+
// https://rollupjs.org/guide/en/#outputformat
|
|
88
|
+
output: [
|
|
89
|
+
{
|
|
90
|
+
file: _resolve("../lib/index.cjs.js"),
|
|
91
|
+
format: "cjs",
|
|
92
|
+
banner,
|
|
93
|
+
plugins: iifePlugins,
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
file: _resolve("../lib/index.esm.js"),
|
|
97
|
+
format: "esm",
|
|
98
|
+
banner,
|
|
99
|
+
plugins: iifePlugins,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
file: _resolve("../lib/mazey.min.js"),
|
|
103
|
+
format: "iife",
|
|
104
|
+
name: "mazey",
|
|
105
|
+
banner,
|
|
106
|
+
plugins: iifePlugins,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
plugins: [
|
|
110
|
+
...plugins,
|
|
111
|
+
cleaner({
|
|
112
|
+
targets: [
|
|
113
|
+
_resolve("../lib/"),
|
|
114
|
+
],
|
|
115
|
+
}),
|
|
116
|
+
],
|
|
117
|
+
external: [],
|
|
118
|
+
},
|
|
119
|
+
dTsConf,
|
|
120
|
+
gTsConf,
|
|
121
|
+
];
|