@deot/dev-builder 1.1.2 → 2.0.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 +30 -4
- package/api-extractor.shared.json +76 -0
- package/dist/index.cjs.js +247 -256
- package/dist/index.es.js +216 -227
- package/package.json +10 -12
- package/shared.config.ts +55 -0
package/README.md
CHANGED
|
@@ -5,9 +5,35 @@
|
|
|
5
5
|
- 优先执行`scripts`下的`build`和`build:types`,如果声明`build`,打包由用户管理,`build:types`,类型编译由用户管理
|
|
6
6
|
- 可被打包的文件匹配:`src/index.*.(j|t|s?cs)s`
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## 自定义配置
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
- 如果改成`vite`打包,则考虑读取配置`vite.config.js`
|
|
10
|
+
提供环境变量`BUILD_OPTIONS`
|
|
12
11
|
|
|
13
|
-
|
|
12
|
+
```ts
|
|
13
|
+
interface BUILD_OPTIONS {
|
|
14
|
+
packageFolderName?: string;
|
|
15
|
+
workspace?: string;
|
|
16
|
+
watch: boolean;
|
|
17
|
+
coverage: boolean;
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
根目录创建`build.config.ts`, 可以选择`configShared`合并或单独基于`BUILD_OPTIONS`配置
|
|
22
|
+
> 也可以是`z.build.config.ts`, 前缀主要是置底
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { mergeConfig, defineConfig } from 'vite';
|
|
26
|
+
import configShared from '@deot/dev-builder/shared.config';
|
|
27
|
+
|
|
28
|
+
export default mergeConfig(
|
|
29
|
+
configShared,
|
|
30
|
+
defineConfig({
|
|
31
|
+
// custom config
|
|
32
|
+
plugins: [
|
|
33
|
+
vue(),
|
|
34
|
+
react()
|
|
35
|
+
]
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
```
|
|
39
|
+
取`build.config.ts`, 是为了方便从`build`转其他测试工具时,可以不改变文件名
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// this the shared base config for all packages.
|
|
2
|
+
{
|
|
3
|
+
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
4
|
+
"compiler": {
|
|
5
|
+
"overrideTsconfig": {
|
|
6
|
+
"compilerOptions": {
|
|
7
|
+
"paths": null
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"apiReport": {
|
|
12
|
+
"enabled": true,
|
|
13
|
+
"reportFolder": "<projectFolder>/temp/"
|
|
14
|
+
},
|
|
15
|
+
|
|
16
|
+
"docModel": {
|
|
17
|
+
"enabled": true
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
"dtsRollup": {
|
|
21
|
+
"enabled": true,
|
|
22
|
+
"untrimmedFilePath": ""
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
"tsdocMetadata": {
|
|
26
|
+
"enabled": false
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
"messages": {
|
|
30
|
+
"compilerMessageReporting": {
|
|
31
|
+
"default": {
|
|
32
|
+
"logLevel": "warning"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
"extractorMessageReporting": {
|
|
37
|
+
"default": {
|
|
38
|
+
"logLevel": "warning",
|
|
39
|
+
"addToApiReportFile": true
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
"ae-missing-release-tag": {
|
|
43
|
+
"logLevel": "none"
|
|
44
|
+
},
|
|
45
|
+
"ae-wrong-input-file-type": {
|
|
46
|
+
"logLevel": "none"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
"tsdocMessageReporting": {
|
|
51
|
+
"default": {
|
|
52
|
+
"logLevel": "warning"
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
"tsdoc-undefined-tag": {
|
|
56
|
+
"logLevel": "none"
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
"tsdoc-escape-greater-than": {
|
|
60
|
+
"logLevel": "none"
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
"tsdoc-malformed-inline-tag": {
|
|
64
|
+
"logLevel": "none"
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
"tsdoc-escape-right-brace": {
|
|
68
|
+
"logLevel": "none"
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
"tsdoc-unnecessary-backslash": {
|
|
72
|
+
"logLevel": "none"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,291 +1,282 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var apiExtractor = require('@microsoft/api-extractor');
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
|
|
5
|
+
const devShared = require('@deot/dev-shared');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const node_module = require('node:module');
|
|
8
|
+
const fs = require('fs-extra');
|
|
9
|
+
const chalk = require('chalk');
|
|
10
|
+
const ora = require('ora');
|
|
11
|
+
const node_url = require('node:url');
|
|
12
|
+
const vite = require('vite');
|
|
13
|
+
const sass = require('sass');
|
|
14
|
+
const postcss = require('postcss');
|
|
15
|
+
const atImport = require('postcss-import');
|
|
16
|
+
const atUrl = require('postcss-url');
|
|
17
|
+
const flexBugs = require('postcss-flexbugs-fixes');
|
|
18
|
+
const cssnano = require('cssnano');
|
|
19
|
+
const autoprefixer = require('autoprefixer');
|
|
20
|
+
const apiExtractor = require('@microsoft/api-extractor');
|
|
22
21
|
|
|
23
22
|
function _interopNamespaceDefault(e) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
24
|
+
if (e) {
|
|
25
|
+
for (const k in e) {
|
|
26
|
+
if (k !== 'default') {
|
|
27
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
28
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: () => e[k]
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
n.default = e;
|
|
36
|
+
return Object.freeze(n);
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
|
|
39
|
+
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
41
40
|
|
|
41
|
+
const dirname$1 = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs.js', document.baseURI).href))));
|
|
42
42
|
const run$3 = async (options) => {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const scripts = files.map((file) => {
|
|
52
|
-
let filepath = path__namespace.resolve(srcDir, file);
|
|
53
|
-
return {
|
|
54
|
-
file,
|
|
55
|
-
input: filepath,
|
|
56
|
-
output: [
|
|
57
|
-
{
|
|
58
|
-
file: path__namespace.resolve(packageDir, './dist', file.replace(/(\.(j|t)s)$/, '.es.js')),
|
|
59
|
-
format: 'es',
|
|
60
|
-
exports: 'named',
|
|
61
|
-
sourcemap: false
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
file: path__namespace.resolve(packageDir, './dist', file.replace(/(\.(j|t)s)$/, '.iife.js')),
|
|
65
|
-
format: 'iife',
|
|
66
|
-
name: packageName,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
file: path__namespace.resolve(packageDir, './dist', file.replace(/(\.(j|t)s)$/, '.cjs.js')),
|
|
70
|
-
format: 'cjs'
|
|
71
|
-
}
|
|
72
|
-
].filter(i => {
|
|
73
|
-
return commandOptions.scriptFormats.includes(i.format);
|
|
74
|
-
})
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
const external = Object
|
|
78
|
-
.keys({
|
|
79
|
-
...packageOptions.dependencies,
|
|
80
|
-
...packageOptions.peerDependencies
|
|
81
|
-
})
|
|
82
|
-
.map(i => new RegExp(`^${i}$`));
|
|
83
|
-
const source = workspace ? `${workspace}/${packageFolderName}/**/*` : 'src/**/*';
|
|
84
|
-
const shims = workspace ? `${workspace}/shims.d.ts` : 'shims.d.ts';
|
|
85
|
-
const outDir = workspace ? `${workspace}/${packageFolderName}/dist` : 'dist';
|
|
86
|
-
const stats = [];
|
|
87
|
-
await scripts
|
|
88
|
-
.reduce((preProcess, current) => {
|
|
89
|
-
preProcess = preProcess
|
|
90
|
-
.then(() => rollup.rollup({
|
|
91
|
-
input: current.input,
|
|
92
|
-
external: [
|
|
93
|
-
/^node:/,
|
|
94
|
-
/^[a-zA-Z@]/,
|
|
95
|
-
...external
|
|
96
|
-
],
|
|
97
|
-
plugins: [
|
|
98
|
-
typescript({
|
|
99
|
-
include: [source, shims],
|
|
100
|
-
exclude: ['dist'],
|
|
101
|
-
compilerOptions: {
|
|
102
|
-
rootDir: '.',
|
|
103
|
-
outDir,
|
|
104
|
-
declaration: /^index.ts$/.test(current.file)
|
|
105
|
-
}
|
|
106
|
-
}),
|
|
107
|
-
commonjs({ extensions: ['.js', '.ts'] }),
|
|
108
|
-
pluginNodeResolve.nodeResolve(),
|
|
109
|
-
replace({
|
|
110
|
-
'1.1.1': `'${packageOptions.version}'`,
|
|
111
|
-
false: 'false',
|
|
112
|
-
true: true
|
|
113
|
-
})
|
|
114
|
-
]
|
|
115
|
-
}))
|
|
116
|
-
.then((builder) => Promise.all(current.output.map(builder.write)))
|
|
117
|
-
.then(() => Promise.all(current.output.map((i) => fs.stat(i.file))))
|
|
118
|
-
.then((stats$) => {
|
|
119
|
-
stats$.forEach((stat, index) => {
|
|
120
|
-
stats.push({
|
|
121
|
-
file: current.file,
|
|
122
|
-
format: current.output[index].format,
|
|
123
|
-
size: stat.size
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
return preProcess;
|
|
128
|
-
}, Promise.resolve());
|
|
43
|
+
const locals = devShared.Locals.impl();
|
|
44
|
+
const { cwd } = locals;
|
|
45
|
+
const { packageName, packageDir, packageOptions } = options || {};
|
|
46
|
+
const stats = [];
|
|
47
|
+
const srcDir = path__namespace.resolve(packageDir, "./src");
|
|
48
|
+
const outDir = path__namespace.resolve(packageDir, "./dist");
|
|
49
|
+
let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(t|j)s$/.test(i)) : [];
|
|
50
|
+
if (!files.length)
|
|
129
51
|
return stats;
|
|
52
|
+
process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify({
|
|
53
|
+
files,
|
|
54
|
+
packageName,
|
|
55
|
+
packageDir,
|
|
56
|
+
packageOptions
|
|
57
|
+
}));
|
|
58
|
+
let options$ = {};
|
|
59
|
+
if (fs.existsSync(`${cwd}/build.config.ts`)) {
|
|
60
|
+
options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./build.config.ts"));
|
|
61
|
+
} else if (fs.existsSync(`${cwd}/z.build.config.ts`)) {
|
|
62
|
+
options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./z.build.config.ts"));
|
|
63
|
+
} else {
|
|
64
|
+
options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(dirname$1, "../shared.config.ts"));
|
|
65
|
+
}
|
|
66
|
+
await vite.build(options$);
|
|
67
|
+
let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.js$/.test(i));
|
|
68
|
+
outputs.forEach((file) => {
|
|
69
|
+
let stat = fs.statSync(path__namespace.resolve(outDir, file));
|
|
70
|
+
stats.push({
|
|
71
|
+
file: file.replace(/^(.*)(\..*\.js)/, "$1.ts"),
|
|
72
|
+
format: file.replace(/.*\.(.*)\.js/, "$1"),
|
|
73
|
+
size: stat.size
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
return stats;
|
|
130
77
|
};
|
|
131
78
|
|
|
132
79
|
const run$2 = async (options) => {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
.then((source) => {
|
|
152
|
-
let output = path__namespace.resolve(packageDir, `./dist/${file.replace(/\.scss$/g, '.css')}`);
|
|
153
|
-
fs.outputFileSync(output, source.css);
|
|
154
|
-
return fs.stat(output);
|
|
155
|
-
})
|
|
156
|
-
.then((stat) => {
|
|
157
|
-
stats.push({
|
|
158
|
-
file,
|
|
159
|
-
size: stat.size
|
|
160
|
-
});
|
|
80
|
+
const { packageDir } = options || {};
|
|
81
|
+
const srcDir = path__namespace.resolve(packageDir, "./src");
|
|
82
|
+
const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.s?css$/.test(i)) : [];
|
|
83
|
+
const stats = [];
|
|
84
|
+
await styles.reduce(
|
|
85
|
+
(preProcess, file) => {
|
|
86
|
+
preProcess = preProcess.then(() => {
|
|
87
|
+
let filepath = path__namespace.resolve(srcDir, file);
|
|
88
|
+
const data = sass.compile(filepath, { style: "compressed" });
|
|
89
|
+
return postcss().use(atImport()).use(atUrl()).use(flexBugs()).use(cssnano()).use(autoprefixer({ remove: false })).process(data.css, { from: filepath });
|
|
90
|
+
}).then((source) => {
|
|
91
|
+
let output = path__namespace.resolve(packageDir, `./dist/${file.replace(/\.scss$/g, ".css")}`);
|
|
92
|
+
fs.outputFileSync(output, source.css);
|
|
93
|
+
return fs.stat(output);
|
|
94
|
+
}).then((stat) => {
|
|
95
|
+
stats.push({
|
|
96
|
+
file,
|
|
97
|
+
size: stat.size
|
|
161
98
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
99
|
+
});
|
|
100
|
+
return preProcess;
|
|
101
|
+
},
|
|
102
|
+
Promise.resolve()
|
|
103
|
+
);
|
|
104
|
+
return stats;
|
|
165
105
|
};
|
|
166
106
|
|
|
107
|
+
const dirname = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs.js', document.baseURI).href))));
|
|
167
108
|
const run$1 = async (options) => {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
109
|
+
const { workspace } = devShared.Locals.impl();
|
|
110
|
+
const { packageDir, packageFolderName, packageOptions, commandOptions } = options;
|
|
111
|
+
const done = () => {
|
|
112
|
+
const stats = [];
|
|
113
|
+
let fullpath = `${packageDir}/dist/index.d.ts`;
|
|
114
|
+
if (fs.existsSync(fullpath)) {
|
|
115
|
+
let stat = fs.statSync(fullpath);
|
|
116
|
+
stats.push({
|
|
117
|
+
file: "index.d.ts",
|
|
118
|
+
size: stat.size
|
|
119
|
+
});
|
|
175
120
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
121
|
+
return stats;
|
|
122
|
+
};
|
|
123
|
+
if (!commandOptions.dts) {
|
|
124
|
+
return done();
|
|
125
|
+
}
|
|
126
|
+
if (workspace && packageOptions?.scripts?.["build:types"]) {
|
|
127
|
+
await devShared.Shell.spawn(`npm`, ["run", "build:types"], {
|
|
128
|
+
cwd: packageDir
|
|
129
|
+
});
|
|
130
|
+
return done();
|
|
131
|
+
}
|
|
132
|
+
let tempDir = `${packageDir}/dist/temp`;
|
|
133
|
+
let rootDir = path__namespace.relative(tempDir, process.cwd());
|
|
134
|
+
fs.outputFileSync(`${tempDir}/tsconfig.json`, JSON.stringify({
|
|
135
|
+
extends: `${rootDir}/tsconfig.json`,
|
|
136
|
+
compilerOptions: {
|
|
137
|
+
declaration: true,
|
|
138
|
+
emitDeclarationOnly: true,
|
|
139
|
+
rootDir,
|
|
140
|
+
outDir: "."
|
|
141
|
+
},
|
|
142
|
+
include: [
|
|
143
|
+
path__namespace.relative(tempDir, path__namespace.resolve(packageDir, `src/*`))
|
|
144
|
+
]
|
|
145
|
+
}, null, " "));
|
|
146
|
+
await devShared.Shell.spawn("tsc", ["-p", `${tempDir}/tsconfig.json`]);
|
|
147
|
+
const configPath = `${tempDir}/api-extractor.json`;
|
|
148
|
+
fs.outputFileSync(configPath, JSON.stringify({
|
|
149
|
+
extends: path__namespace.relative(tempDir, path__namespace.resolve(dirname, "../api-extractor.shared.json")),
|
|
150
|
+
mainEntryPointFilePath: `.${workspace ? "/packages/" : ""}${packageFolderName}/src/index.d.ts`,
|
|
151
|
+
// workspace、时以temp/packages/*/src结构,否则APIExtractor会报错
|
|
152
|
+
dtsRollup: {
|
|
153
|
+
publicTrimmedFilePath: "../index.d.ts"
|
|
154
|
+
}
|
|
155
|
+
}, null, " "));
|
|
156
|
+
const result = apiExtractor.Extractor.invoke(
|
|
157
|
+
apiExtractor.ExtractorConfig.loadFileAndPrepare(configPath),
|
|
158
|
+
{
|
|
159
|
+
localBuild: true,
|
|
160
|
+
showVerboseMessages: false,
|
|
161
|
+
// 去掉版本提示
|
|
162
|
+
messageCallback: (message) => {
|
|
163
|
+
if (message.messageId === "console-compiler-version-notice" || message.messageId === "console-preamble") {
|
|
164
|
+
message.handled = true;
|
|
185
165
|
}
|
|
166
|
+
}
|
|
186
167
|
}
|
|
187
|
-
|
|
168
|
+
);
|
|
169
|
+
if (!result.succeeded) {
|
|
170
|
+
devShared.Logger.error(
|
|
171
|
+
`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`
|
|
172
|
+
);
|
|
173
|
+
process.exitCode = 1;
|
|
174
|
+
}
|
|
175
|
+
await fs.remove(`${packageDir}/dist/temp`);
|
|
176
|
+
return done();
|
|
188
177
|
};
|
|
189
178
|
|
|
190
179
|
const require$ = node_module.createRequire(process.cwd());
|
|
191
180
|
class Build {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
181
|
+
packageDir;
|
|
182
|
+
packageFolderName;
|
|
183
|
+
packageSourceDir;
|
|
184
|
+
packageName;
|
|
185
|
+
packageOptions;
|
|
186
|
+
commandOptions;
|
|
187
|
+
constructor(packageFolderName, commandOptions) {
|
|
188
|
+
const { workspace, packageDir, packageName, packageFolderName: packageFolderName$ } = devShared.Locals.impl();
|
|
189
|
+
this.packageFolderName = packageFolderName || "";
|
|
190
|
+
this.packageDir = path__namespace.resolve(packageDir, workspace ? `./${packageFolderName}` : "");
|
|
191
|
+
this.packageSourceDir = path__namespace.resolve(packageDir, "./src");
|
|
192
|
+
this.packageName = packageFolderName === packageFolderName$ ? packageName : `${packageName}-${packageFolderName}`;
|
|
193
|
+
this.packageOptions = require$(`${this.packageDir}/package.json`);
|
|
194
|
+
this.commandOptions = commandOptions;
|
|
195
|
+
}
|
|
196
|
+
async process() {
|
|
197
|
+
let start = Date.now();
|
|
198
|
+
const { cwd, workspace } = devShared.Locals.impl();
|
|
199
|
+
const { packageOptions, packageName, packageDir } = this;
|
|
200
|
+
if (workspace && packageOptions?.scripts?.build && packageDir !== cwd) {
|
|
201
|
+
await devShared.Shell.spawn(`npm`, ["run", "build"], {
|
|
202
|
+
cwd: packageDir
|
|
203
|
+
});
|
|
204
|
+
return;
|
|
208
205
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
devShared.Logger.log(`${chalk.magenta(stat.file)}: ${devShared.Utils.formatBytes(stat.size)}`);
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
catch (e) {
|
|
245
|
-
devShared.Logger.log('Error!', e);
|
|
246
|
-
throw e;
|
|
247
|
-
}
|
|
206
|
+
const srcDir = path__namespace.resolve(packageDir, "./src");
|
|
207
|
+
let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i)) : [];
|
|
208
|
+
if (!files.length)
|
|
209
|
+
return;
|
|
210
|
+
const spinner = ora(`${packageName} Build ...`);
|
|
211
|
+
try {
|
|
212
|
+
spinner.start();
|
|
213
|
+
await fs.emptyDir(`${packageDir}/dist`);
|
|
214
|
+
const scriptStats = await run$3(this);
|
|
215
|
+
const scriptDuration = Date.now() - start;
|
|
216
|
+
const styleStats = await run$2(this);
|
|
217
|
+
const styleDuration = Date.now() - start - scriptDuration;
|
|
218
|
+
const typeStats = await run$1(this);
|
|
219
|
+
const typeDuration = Date.now() - start - styleDuration - scriptDuration;
|
|
220
|
+
spinner.stop();
|
|
221
|
+
let message = "";
|
|
222
|
+
message += `${chalk.cyan(`${packageName}`)}: ${chalk.green("Success")} ${chalk.blue(`${Date.now() - start}ms`)}(`;
|
|
223
|
+
message += styleStats.length ? `css: ${chalk.yellow(styleDuration)}ms; ` : "";
|
|
224
|
+
message += scriptStats.length ? `js: ${chalk.yellow(scriptDuration)}ms${typeStats.length ? "; " : ""}` : "";
|
|
225
|
+
message += typeStats.length ? `dts: ${chalk.yellow(typeDuration)}ms` : "";
|
|
226
|
+
message += ")";
|
|
227
|
+
devShared.Logger.log(message);
|
|
228
|
+
scriptStats.concat(styleStats).concat(typeStats).forEach((stat) => {
|
|
229
|
+
let message$ = "";
|
|
230
|
+
message$ += `${chalk.magenta(stat.file)}: `;
|
|
231
|
+
message$ += stat.format ? `${chalk.green(stat.format.toUpperCase())} - ` : "";
|
|
232
|
+
message$ += `${devShared.Utils.formatBytes(stat.size)}`;
|
|
233
|
+
devShared.Logger.log(message$);
|
|
234
|
+
});
|
|
235
|
+
} catch (e) {
|
|
236
|
+
devShared.Logger.log("Error!", e);
|
|
237
|
+
throw e;
|
|
248
238
|
}
|
|
239
|
+
}
|
|
249
240
|
}
|
|
250
241
|
const build = (options, commandOptions) => {
|
|
251
|
-
|
|
242
|
+
return new Build(options, commandOptions);
|
|
252
243
|
};
|
|
253
244
|
|
|
254
245
|
const run = (options) => devShared.Utils.autoCatch(async () => {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
246
|
+
options = {
|
|
247
|
+
scriptFormats: "es,cjs",
|
|
248
|
+
...options
|
|
249
|
+
};
|
|
250
|
+
const locals = devShared.Locals.impl();
|
|
251
|
+
if (typeof options.dryRun === "undefined") {
|
|
252
|
+
options.dryRun = process.env.NODE_ENV === "UNIT";
|
|
253
|
+
}
|
|
254
|
+
const { normalizePackageFolderNames } = devShared.Locals.impl();
|
|
255
|
+
let packageFolderName = devShared.Locals.getPackageFolderName(options.packageName || "*");
|
|
256
|
+
let inputs = [];
|
|
257
|
+
if (locals.workspace && packageFolderName === "*") {
|
|
258
|
+
inputs = normalizePackageFolderNames;
|
|
259
|
+
} else {
|
|
260
|
+
inputs = [packageFolderName];
|
|
261
|
+
}
|
|
262
|
+
if (options.dryRun)
|
|
263
|
+
return devShared.Shell.spawn(`echo ${inputs.join(" ")}`);
|
|
264
|
+
await inputs.reduce(
|
|
265
|
+
(preProcess, packageFolderName$) => {
|
|
266
|
+
preProcess = preProcess.then(() => build(packageFolderName$, options).process());
|
|
267
|
+
return preProcess;
|
|
268
|
+
},
|
|
269
|
+
Promise.resolve()
|
|
270
|
+
);
|
|
279
271
|
}, {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
devShared.Logger.error(e);
|
|
286
|
-
}
|
|
287
|
-
process.exit(1);
|
|
272
|
+
onError: (e) => {
|
|
273
|
+
if (typeof e === "number" && e === 1) {
|
|
274
|
+
devShared.Logger.error("编译未通过");
|
|
275
|
+
} else {
|
|
276
|
+
devShared.Logger.error(e);
|
|
288
277
|
}
|
|
278
|
+
process.exit(1);
|
|
279
|
+
}
|
|
289
280
|
});
|
|
290
281
|
|
|
291
282
|
exports.run = run;
|
package/dist/index.es.js
CHANGED
|
@@ -4,11 +4,8 @@ import { createRequire } from 'node:module';
|
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
5
|
import chalk from 'chalk';
|
|
6
6
|
import ora from 'ora';
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import commonjs from '@rollup/plugin-commonjs';
|
|
10
|
-
import replace from '@rollup/plugin-replace';
|
|
11
|
-
import { rollup } from 'rollup';
|
|
7
|
+
import { fileURLToPath } from 'node:url';
|
|
8
|
+
import { build as build$1 } from 'vite';
|
|
12
9
|
import sass from 'sass';
|
|
13
10
|
import postcss from 'postcss';
|
|
14
11
|
import atImport from 'postcss-import';
|
|
@@ -18,253 +15,245 @@ import cssnano from 'cssnano';
|
|
|
18
15
|
import autoprefixer from 'autoprefixer';
|
|
19
16
|
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor';
|
|
20
17
|
|
|
18
|
+
const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
21
19
|
const run$3 = async (options) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const scripts = files.map((file) => {
|
|
31
|
-
let filepath = path.resolve(srcDir, file);
|
|
32
|
-
return {
|
|
33
|
-
file,
|
|
34
|
-
input: filepath,
|
|
35
|
-
output: [
|
|
36
|
-
{
|
|
37
|
-
file: path.resolve(packageDir, './dist', file.replace(/(\.(j|t)s)$/, '.es.js')),
|
|
38
|
-
format: 'es',
|
|
39
|
-
exports: 'named',
|
|
40
|
-
sourcemap: false
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
file: path.resolve(packageDir, './dist', file.replace(/(\.(j|t)s)$/, '.iife.js')),
|
|
44
|
-
format: 'iife',
|
|
45
|
-
name: packageName,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
file: path.resolve(packageDir, './dist', file.replace(/(\.(j|t)s)$/, '.cjs.js')),
|
|
49
|
-
format: 'cjs'
|
|
50
|
-
}
|
|
51
|
-
].filter(i => {
|
|
52
|
-
return commandOptions.scriptFormats.includes(i.format);
|
|
53
|
-
})
|
|
54
|
-
};
|
|
55
|
-
});
|
|
56
|
-
const external = Object
|
|
57
|
-
.keys({
|
|
58
|
-
...packageOptions.dependencies,
|
|
59
|
-
...packageOptions.peerDependencies
|
|
60
|
-
})
|
|
61
|
-
.map(i => new RegExp(`^${i}$`));
|
|
62
|
-
const source = workspace ? `${workspace}/${packageFolderName}/**/*` : 'src/**/*';
|
|
63
|
-
const shims = workspace ? `${workspace}/shims.d.ts` : 'shims.d.ts';
|
|
64
|
-
const outDir = workspace ? `${workspace}/${packageFolderName}/dist` : 'dist';
|
|
65
|
-
const stats = [];
|
|
66
|
-
await scripts
|
|
67
|
-
.reduce((preProcess, current) => {
|
|
68
|
-
preProcess = preProcess
|
|
69
|
-
.then(() => rollup({
|
|
70
|
-
input: current.input,
|
|
71
|
-
external: [
|
|
72
|
-
/^node:/,
|
|
73
|
-
/^[a-zA-Z@]/,
|
|
74
|
-
...external
|
|
75
|
-
],
|
|
76
|
-
plugins: [
|
|
77
|
-
typescript({
|
|
78
|
-
include: [source, shims],
|
|
79
|
-
exclude: ['dist'],
|
|
80
|
-
compilerOptions: {
|
|
81
|
-
rootDir: '.',
|
|
82
|
-
outDir,
|
|
83
|
-
declaration: /^index.ts$/.test(current.file)
|
|
84
|
-
}
|
|
85
|
-
}),
|
|
86
|
-
commonjs({ extensions: ['.js', '.ts'] }),
|
|
87
|
-
nodeResolve(),
|
|
88
|
-
replace({
|
|
89
|
-
'1.1.1': `'${packageOptions.version}'`,
|
|
90
|
-
false: 'false',
|
|
91
|
-
true: true
|
|
92
|
-
})
|
|
93
|
-
]
|
|
94
|
-
}))
|
|
95
|
-
.then((builder) => Promise.all(current.output.map(builder.write)))
|
|
96
|
-
.then(() => Promise.all(current.output.map((i) => fs.stat(i.file))))
|
|
97
|
-
.then((stats$) => {
|
|
98
|
-
stats$.forEach((stat, index) => {
|
|
99
|
-
stats.push({
|
|
100
|
-
file: current.file,
|
|
101
|
-
format: current.output[index].format,
|
|
102
|
-
size: stat.size
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
return preProcess;
|
|
107
|
-
}, Promise.resolve());
|
|
20
|
+
const locals = Locals.impl();
|
|
21
|
+
const { cwd } = locals;
|
|
22
|
+
const { packageName, packageDir, packageOptions } = options || {};
|
|
23
|
+
const stats = [];
|
|
24
|
+
const srcDir = path.resolve(packageDir, "./src");
|
|
25
|
+
const outDir = path.resolve(packageDir, "./dist");
|
|
26
|
+
let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(t|j)s$/.test(i)) : [];
|
|
27
|
+
if (!files.length)
|
|
108
28
|
return stats;
|
|
29
|
+
process.env.BUILD_OPTIONS = encodeURIComponent(JSON.stringify({
|
|
30
|
+
files,
|
|
31
|
+
packageName,
|
|
32
|
+
packageDir,
|
|
33
|
+
packageOptions
|
|
34
|
+
}));
|
|
35
|
+
let options$ = {};
|
|
36
|
+
if (fs.existsSync(`${cwd}/build.config.ts`)) {
|
|
37
|
+
options$.configFile = path.relative(cwd, path.resolve(cwd, "./build.config.ts"));
|
|
38
|
+
} else if (fs.existsSync(`${cwd}/z.build.config.ts`)) {
|
|
39
|
+
options$.configFile = path.relative(cwd, path.resolve(cwd, "./z.build.config.ts"));
|
|
40
|
+
} else {
|
|
41
|
+
options$.configFile = path.relative(cwd, path.resolve(dirname$1, "../shared.config.ts"));
|
|
42
|
+
}
|
|
43
|
+
await build$1(options$);
|
|
44
|
+
let outputs = fs.readdirSync(outDir).filter((i) => /^index(.*)(?!=\.d)\.js$/.test(i));
|
|
45
|
+
outputs.forEach((file) => {
|
|
46
|
+
let stat = fs.statSync(path.resolve(outDir, file));
|
|
47
|
+
stats.push({
|
|
48
|
+
file: file.replace(/^(.*)(\..*\.js)/, "$1.ts"),
|
|
49
|
+
format: file.replace(/.*\.(.*)\.js/, "$1"),
|
|
50
|
+
size: stat.size
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
return stats;
|
|
109
54
|
};
|
|
110
55
|
|
|
111
56
|
const run$2 = async (options) => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
.then((source) => {
|
|
131
|
-
let output = path.resolve(packageDir, `./dist/${file.replace(/\.scss$/g, '.css')}`);
|
|
132
|
-
fs.outputFileSync(output, source.css);
|
|
133
|
-
return fs.stat(output);
|
|
134
|
-
})
|
|
135
|
-
.then((stat) => {
|
|
136
|
-
stats.push({
|
|
137
|
-
file,
|
|
138
|
-
size: stat.size
|
|
139
|
-
});
|
|
57
|
+
const { packageDir } = options || {};
|
|
58
|
+
const srcDir = path.resolve(packageDir, "./src");
|
|
59
|
+
const styles = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.s?css$/.test(i)) : [];
|
|
60
|
+
const stats = [];
|
|
61
|
+
await styles.reduce(
|
|
62
|
+
(preProcess, file) => {
|
|
63
|
+
preProcess = preProcess.then(() => {
|
|
64
|
+
let filepath = path.resolve(srcDir, file);
|
|
65
|
+
const data = sass.compile(filepath, { style: "compressed" });
|
|
66
|
+
return postcss().use(atImport()).use(atUrl()).use(flexBugs()).use(cssnano()).use(autoprefixer({ remove: false })).process(data.css, { from: filepath });
|
|
67
|
+
}).then((source) => {
|
|
68
|
+
let output = path.resolve(packageDir, `./dist/${file.replace(/\.scss$/g, ".css")}`);
|
|
69
|
+
fs.outputFileSync(output, source.css);
|
|
70
|
+
return fs.stat(output);
|
|
71
|
+
}).then((stat) => {
|
|
72
|
+
stats.push({
|
|
73
|
+
file,
|
|
74
|
+
size: stat.size
|
|
140
75
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
76
|
+
});
|
|
77
|
+
return preProcess;
|
|
78
|
+
},
|
|
79
|
+
Promise.resolve()
|
|
80
|
+
);
|
|
81
|
+
return stats;
|
|
144
82
|
};
|
|
145
83
|
|
|
84
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
146
85
|
const run$1 = async (options) => {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
86
|
+
const { workspace } = Locals.impl();
|
|
87
|
+
const { packageDir, packageFolderName, packageOptions, commandOptions } = options;
|
|
88
|
+
const done = () => {
|
|
89
|
+
const stats = [];
|
|
90
|
+
let fullpath = `${packageDir}/dist/index.d.ts`;
|
|
91
|
+
if (fs.existsSync(fullpath)) {
|
|
92
|
+
let stat = fs.statSync(fullpath);
|
|
93
|
+
stats.push({
|
|
94
|
+
file: "index.d.ts",
|
|
95
|
+
size: stat.size
|
|
96
|
+
});
|
|
154
97
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
98
|
+
return stats;
|
|
99
|
+
};
|
|
100
|
+
if (!commandOptions.dts) {
|
|
101
|
+
return done();
|
|
102
|
+
}
|
|
103
|
+
if (workspace && packageOptions?.scripts?.["build:types"]) {
|
|
104
|
+
await Shell.spawn(`npm`, ["run", "build:types"], {
|
|
105
|
+
cwd: packageDir
|
|
106
|
+
});
|
|
107
|
+
return done();
|
|
108
|
+
}
|
|
109
|
+
let tempDir = `${packageDir}/dist/temp`;
|
|
110
|
+
let rootDir = path.relative(tempDir, process.cwd());
|
|
111
|
+
fs.outputFileSync(`${tempDir}/tsconfig.json`, JSON.stringify({
|
|
112
|
+
extends: `${rootDir}/tsconfig.json`,
|
|
113
|
+
compilerOptions: {
|
|
114
|
+
declaration: true,
|
|
115
|
+
emitDeclarationOnly: true,
|
|
116
|
+
rootDir,
|
|
117
|
+
outDir: "."
|
|
118
|
+
},
|
|
119
|
+
include: [
|
|
120
|
+
path.relative(tempDir, path.resolve(packageDir, `src/*`))
|
|
121
|
+
]
|
|
122
|
+
}, null, " "));
|
|
123
|
+
await Shell.spawn("tsc", ["-p", `${tempDir}/tsconfig.json`]);
|
|
124
|
+
const configPath = `${tempDir}/api-extractor.json`;
|
|
125
|
+
fs.outputFileSync(configPath, JSON.stringify({
|
|
126
|
+
extends: path.relative(tempDir, path.resolve(dirname, "../api-extractor.shared.json")),
|
|
127
|
+
mainEntryPointFilePath: `.${workspace ? "/packages/" : ""}${packageFolderName}/src/index.d.ts`,
|
|
128
|
+
// workspace、时以temp/packages/*/src结构,否则APIExtractor会报错
|
|
129
|
+
dtsRollup: {
|
|
130
|
+
publicTrimmedFilePath: "../index.d.ts"
|
|
131
|
+
}
|
|
132
|
+
}, null, " "));
|
|
133
|
+
const result = Extractor.invoke(
|
|
134
|
+
ExtractorConfig.loadFileAndPrepare(configPath),
|
|
135
|
+
{
|
|
136
|
+
localBuild: true,
|
|
137
|
+
showVerboseMessages: false,
|
|
138
|
+
// 去掉版本提示
|
|
139
|
+
messageCallback: (message) => {
|
|
140
|
+
if (message.messageId === "console-compiler-version-notice" || message.messageId === "console-preamble") {
|
|
141
|
+
message.handled = true;
|
|
164
142
|
}
|
|
143
|
+
}
|
|
165
144
|
}
|
|
166
|
-
|
|
145
|
+
);
|
|
146
|
+
if (!result.succeeded) {
|
|
147
|
+
Logger.error(
|
|
148
|
+
`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`
|
|
149
|
+
);
|
|
150
|
+
process.exitCode = 1;
|
|
151
|
+
}
|
|
152
|
+
await fs.remove(`${packageDir}/dist/temp`);
|
|
153
|
+
return done();
|
|
167
154
|
};
|
|
168
155
|
|
|
169
156
|
const require$ = createRequire(process.cwd());
|
|
170
157
|
class Build {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
158
|
+
packageDir;
|
|
159
|
+
packageFolderName;
|
|
160
|
+
packageSourceDir;
|
|
161
|
+
packageName;
|
|
162
|
+
packageOptions;
|
|
163
|
+
commandOptions;
|
|
164
|
+
constructor(packageFolderName, commandOptions) {
|
|
165
|
+
const { workspace, packageDir, packageName, packageFolderName: packageFolderName$ } = Locals.impl();
|
|
166
|
+
this.packageFolderName = packageFolderName || "";
|
|
167
|
+
this.packageDir = path.resolve(packageDir, workspace ? `./${packageFolderName}` : "");
|
|
168
|
+
this.packageSourceDir = path.resolve(packageDir, "./src");
|
|
169
|
+
this.packageName = packageFolderName === packageFolderName$ ? packageName : `${packageName}-${packageFolderName}`;
|
|
170
|
+
this.packageOptions = require$(`${this.packageDir}/package.json`);
|
|
171
|
+
this.commandOptions = commandOptions;
|
|
172
|
+
}
|
|
173
|
+
async process() {
|
|
174
|
+
let start = Date.now();
|
|
175
|
+
const { cwd, workspace } = Locals.impl();
|
|
176
|
+
const { packageOptions, packageName, packageDir } = this;
|
|
177
|
+
if (workspace && packageOptions?.scripts?.build && packageDir !== cwd) {
|
|
178
|
+
await Shell.spawn(`npm`, ["run", "build"], {
|
|
179
|
+
cwd: packageDir
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
187
182
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
Logger.log(`${chalk.magenta(stat.file)}: ${Utils.formatBytes(stat.size)}`);
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
catch (e) {
|
|
224
|
-
Logger.log('Error!', e);
|
|
225
|
-
throw e;
|
|
226
|
-
}
|
|
183
|
+
const srcDir = path.resolve(packageDir, "./src");
|
|
184
|
+
let files = fs.existsSync(srcDir) ? fs.readdirSync(srcDir).filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i)) : [];
|
|
185
|
+
if (!files.length)
|
|
186
|
+
return;
|
|
187
|
+
const spinner = ora(`${packageName} Build ...`);
|
|
188
|
+
try {
|
|
189
|
+
spinner.start();
|
|
190
|
+
await fs.emptyDir(`${packageDir}/dist`);
|
|
191
|
+
const scriptStats = await run$3(this);
|
|
192
|
+
const scriptDuration = Date.now() - start;
|
|
193
|
+
const styleStats = await run$2(this);
|
|
194
|
+
const styleDuration = Date.now() - start - scriptDuration;
|
|
195
|
+
const typeStats = await run$1(this);
|
|
196
|
+
const typeDuration = Date.now() - start - styleDuration - scriptDuration;
|
|
197
|
+
spinner.stop();
|
|
198
|
+
let message = "";
|
|
199
|
+
message += `${chalk.cyan(`${packageName}`)}: ${chalk.green("Success")} ${chalk.blue(`${Date.now() - start}ms`)}(`;
|
|
200
|
+
message += styleStats.length ? `css: ${chalk.yellow(styleDuration)}ms; ` : "";
|
|
201
|
+
message += scriptStats.length ? `js: ${chalk.yellow(scriptDuration)}ms${typeStats.length ? "; " : ""}` : "";
|
|
202
|
+
message += typeStats.length ? `dts: ${chalk.yellow(typeDuration)}ms` : "";
|
|
203
|
+
message += ")";
|
|
204
|
+
Logger.log(message);
|
|
205
|
+
scriptStats.concat(styleStats).concat(typeStats).forEach((stat) => {
|
|
206
|
+
let message$ = "";
|
|
207
|
+
message$ += `${chalk.magenta(stat.file)}: `;
|
|
208
|
+
message$ += stat.format ? `${chalk.green(stat.format.toUpperCase())} - ` : "";
|
|
209
|
+
message$ += `${Utils.formatBytes(stat.size)}`;
|
|
210
|
+
Logger.log(message$);
|
|
211
|
+
});
|
|
212
|
+
} catch (e) {
|
|
213
|
+
Logger.log("Error!", e);
|
|
214
|
+
throw e;
|
|
227
215
|
}
|
|
216
|
+
}
|
|
228
217
|
}
|
|
229
218
|
const build = (options, commandOptions) => {
|
|
230
|
-
|
|
219
|
+
return new Build(options, commandOptions);
|
|
231
220
|
};
|
|
232
221
|
|
|
233
222
|
const run = (options) => Utils.autoCatch(async () => {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
223
|
+
options = {
|
|
224
|
+
scriptFormats: "es,cjs",
|
|
225
|
+
...options
|
|
226
|
+
};
|
|
227
|
+
const locals = Locals.impl();
|
|
228
|
+
if (typeof options.dryRun === "undefined") {
|
|
229
|
+
options.dryRun = process.env.NODE_ENV === "UNIT";
|
|
230
|
+
}
|
|
231
|
+
const { normalizePackageFolderNames } = Locals.impl();
|
|
232
|
+
let packageFolderName = Locals.getPackageFolderName(options.packageName || "*");
|
|
233
|
+
let inputs = [];
|
|
234
|
+
if (locals.workspace && packageFolderName === "*") {
|
|
235
|
+
inputs = normalizePackageFolderNames;
|
|
236
|
+
} else {
|
|
237
|
+
inputs = [packageFolderName];
|
|
238
|
+
}
|
|
239
|
+
if (options.dryRun)
|
|
240
|
+
return Shell.spawn(`echo ${inputs.join(" ")}`);
|
|
241
|
+
await inputs.reduce(
|
|
242
|
+
(preProcess, packageFolderName$) => {
|
|
243
|
+
preProcess = preProcess.then(() => build(packageFolderName$, options).process());
|
|
244
|
+
return preProcess;
|
|
245
|
+
},
|
|
246
|
+
Promise.resolve()
|
|
247
|
+
);
|
|
258
248
|
}, {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
Logger.error(e);
|
|
265
|
-
}
|
|
266
|
-
process.exit(1);
|
|
249
|
+
onError: (e) => {
|
|
250
|
+
if (typeof e === "number" && e === 1) {
|
|
251
|
+
Logger.error("编译未通过");
|
|
252
|
+
} else {
|
|
253
|
+
Logger.error(e);
|
|
267
254
|
}
|
|
255
|
+
process.exit(1);
|
|
256
|
+
}
|
|
268
257
|
});
|
|
269
258
|
|
|
270
259
|
export { run };
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-builder",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"main": "dist/index.es.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"api-extractor.shared.json",
|
|
11
|
+
"shared.config.ts"
|
|
10
12
|
],
|
|
11
13
|
"license": "MIT",
|
|
12
14
|
"publishConfig": {
|
|
@@ -21,25 +23,21 @@
|
|
|
21
23
|
}
|
|
22
24
|
},
|
|
23
25
|
"dependencies": {
|
|
24
|
-
"@deot/dev-shared": "^
|
|
25
|
-
"@microsoft/api-extractor": "^7.
|
|
26
|
-
"@rollup/plugin-commonjs": "^24.1.0",
|
|
27
|
-
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
28
|
-
"@rollup/plugin-replace": "^5.0.2",
|
|
29
|
-
"@rollup/plugin-typescript": "^11.1.0",
|
|
26
|
+
"@deot/dev-shared": "^2.0.0",
|
|
27
|
+
"@microsoft/api-extractor": "^7.35.1",
|
|
30
28
|
"autoprefixer": "^10.4.14",
|
|
31
29
|
"chalk": "^5.2.0",
|
|
32
30
|
"cssnano": "^5.1.15",
|
|
33
31
|
"fs-extra": "^11.1.1",
|
|
34
32
|
"ora": "^6.1.2",
|
|
35
|
-
"postcss": "^8.4.
|
|
33
|
+
"postcss": "^8.4.24",
|
|
36
34
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
37
35
|
"postcss-import": "^15.1.0",
|
|
38
36
|
"postcss-url": "^10.1.3",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
37
|
+
"sass": "^1.62.1",
|
|
38
|
+
"vite": "^4.3.9"
|
|
41
39
|
},
|
|
42
40
|
"devDependencies": {
|
|
43
|
-
"typescript": "^5.
|
|
41
|
+
"typescript": "^5.1.3"
|
|
44
42
|
}
|
|
45
43
|
}
|
package/shared.config.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import atImport from "postcss-import";
|
|
4
|
+
import atUrl from "postcss-url";
|
|
5
|
+
import flexBugs from "postcss-flexbugs-fixes";
|
|
6
|
+
import cssnano from "cssnano";
|
|
7
|
+
import autoprefixer from "autoprefixer";
|
|
8
|
+
|
|
9
|
+
// options
|
|
10
|
+
const buildOptions = JSON.parse(decodeURIComponent(process.env.BUILD_OPTIONS || '{}'));
|
|
11
|
+
|
|
12
|
+
const { files = [], packageName, packageDir, packageOptions = {} } = buildOptions;
|
|
13
|
+
|
|
14
|
+
const external = Object
|
|
15
|
+
.keys({
|
|
16
|
+
...packageOptions.dependencies,
|
|
17
|
+
...packageOptions.peerDependencies
|
|
18
|
+
})
|
|
19
|
+
.map(i => new RegExp(`^${i}$`));
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
plugins: [],
|
|
23
|
+
logLevel: 'silent',
|
|
24
|
+
css: {
|
|
25
|
+
postcss: {
|
|
26
|
+
plugins: [
|
|
27
|
+
atImport(),
|
|
28
|
+
atUrl(),
|
|
29
|
+
flexBugs(),
|
|
30
|
+
cssnano(),
|
|
31
|
+
autoprefixer({ remove: false })
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
build: {
|
|
36
|
+
minify: false,
|
|
37
|
+
target: 'esnext',
|
|
38
|
+
outDir: path.resolve(packageDir, './dist'),
|
|
39
|
+
lib: {
|
|
40
|
+
entry: files.map((file: string) => path.resolve(packageDir, './src', file)),
|
|
41
|
+
formats: ['es', 'cjs'], // iife需要控制单独控制external,目前还做不到
|
|
42
|
+
name: packageName,
|
|
43
|
+
fileName: (format, entryName) => {
|
|
44
|
+
return `${entryName}.${format}.js`;
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
rollupOptions: {
|
|
48
|
+
external: [
|
|
49
|
+
/^node:/,
|
|
50
|
+
/^[a-zA-Z@]/,
|
|
51
|
+
...external
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|