@deot/dev-builder 1.1.0 → 1.1.2
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 +1 -2
- package/dist/index.cjs.js +185 -127
- package/dist/index.es.js +185 -127
- package/package.json +25 -5
package/README.md
CHANGED
package/dist/index.cjs.js
CHANGED
|
@@ -4,14 +4,21 @@ var devShared = require('@deot/dev-shared');
|
|
|
4
4
|
var path = require('node:path');
|
|
5
5
|
var node_module = require('node:module');
|
|
6
6
|
var fs = require('fs-extra');
|
|
7
|
+
var chalk = require('chalk');
|
|
8
|
+
var ora = require('ora');
|
|
7
9
|
var typescript = require('@rollup/plugin-typescript');
|
|
8
10
|
var pluginNodeResolve = require('@rollup/plugin-node-resolve');
|
|
9
11
|
var commonjs = require('@rollup/plugin-commonjs');
|
|
10
12
|
var replace = require('@rollup/plugin-replace');
|
|
11
13
|
var rollup = require('rollup');
|
|
14
|
+
var sass = require('sass');
|
|
15
|
+
var postcss = require('postcss');
|
|
16
|
+
var atImport = require('postcss-import');
|
|
17
|
+
var atUrl = require('postcss-url');
|
|
18
|
+
var flexBugs = require('postcss-flexbugs-fixes');
|
|
19
|
+
var cssnano = require('cssnano');
|
|
20
|
+
var autoprefixer = require('autoprefixer');
|
|
12
21
|
var apiExtractor = require('@microsoft/api-extractor');
|
|
13
|
-
var chalk = require('chalk');
|
|
14
|
-
var ora = require('ora');
|
|
15
22
|
|
|
16
23
|
function _interopNamespaceDefault(e) {
|
|
17
24
|
var n = Object.create(null);
|
|
@@ -32,59 +39,176 @@ function _interopNamespaceDefault(e) {
|
|
|
32
39
|
|
|
33
40
|
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
34
41
|
|
|
42
|
+
const run$3 = async (options) => {
|
|
43
|
+
const { packageName, packageFolderName, packageDir, commandOptions, packageOptions } = options || {};
|
|
44
|
+
const { workspace } = devShared.Locals.impl();
|
|
45
|
+
const srcDir = path__namespace.resolve(packageDir, './src');
|
|
46
|
+
let files = fs.existsSync(srcDir)
|
|
47
|
+
? fs
|
|
48
|
+
.readdirSync(srcDir)
|
|
49
|
+
.filter((i) => /^index(.*)\.(t|j)s$/.test(i))
|
|
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());
|
|
129
|
+
return stats;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const run$2 = async (options) => {
|
|
133
|
+
const { packageDir } = options || {};
|
|
134
|
+
const srcDir = path__namespace.resolve(packageDir, './src');
|
|
135
|
+
const styles = fs.readdirSync(srcDir).filter((i) => /^index(.*)\.s?css$/.test(i));
|
|
136
|
+
const stats = [];
|
|
137
|
+
await styles
|
|
138
|
+
.reduce((preProcess, file) => {
|
|
139
|
+
preProcess = preProcess
|
|
140
|
+
.then(() => {
|
|
141
|
+
let filepath = path__namespace.resolve(srcDir, file);
|
|
142
|
+
const data = sass.compile(filepath, { style: 'compressed' });
|
|
143
|
+
return postcss()
|
|
144
|
+
.use(atImport())
|
|
145
|
+
.use(atUrl())
|
|
146
|
+
.use(flexBugs())
|
|
147
|
+
.use(cssnano())
|
|
148
|
+
.use(autoprefixer({ remove: false }))
|
|
149
|
+
.process(data.css, { from: filepath });
|
|
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
|
+
});
|
|
161
|
+
});
|
|
162
|
+
return preProcess;
|
|
163
|
+
}, Promise.resolve());
|
|
164
|
+
return stats;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const run$1 = async (options) => {
|
|
168
|
+
const { workspace } = devShared.Locals.impl();
|
|
169
|
+
const { packageDir, packageOptions } = options;
|
|
170
|
+
if (workspace && packageOptions?.scripts?.['build:types']) {
|
|
171
|
+
await devShared.Shell.spawn(`npm`, ['run', 'build:types'], {
|
|
172
|
+
cwd: packageDir
|
|
173
|
+
});
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const config = path__namespace.resolve(packageDir, `api-extractor.json`);
|
|
177
|
+
if (fs.existsSync(config)) {
|
|
178
|
+
const result = apiExtractor.Extractor.invoke(apiExtractor.ExtractorConfig.loadFileAndPrepare(config), {
|
|
179
|
+
localBuild: true,
|
|
180
|
+
showVerboseMessages: false
|
|
181
|
+
});
|
|
182
|
+
if (!result.succeeded) {
|
|
183
|
+
devShared.Logger.error(`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`);
|
|
184
|
+
process.exitCode = 1;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
await fs.remove(`${packageDir}/dist/${workspace || 'src'}`);
|
|
188
|
+
};
|
|
189
|
+
|
|
35
190
|
const require$ = node_module.createRequire(process.cwd());
|
|
36
191
|
class Build {
|
|
37
192
|
packageDir;
|
|
193
|
+
packageFolderName;
|
|
194
|
+
packageSourceDir;
|
|
38
195
|
packageName;
|
|
39
196
|
packageOptions;
|
|
40
|
-
config;
|
|
41
197
|
commandOptions;
|
|
42
|
-
constructor(
|
|
43
|
-
const { workspace, packageDir, packageName } = devShared.Locals.impl();
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
? packageDir$ + '/src/index.ts'
|
|
49
|
-
: fs.existsSync(packageDir$ + '/src/index.js')
|
|
50
|
-
? packageDir$ + '/src/index.js'
|
|
51
|
-
: '';
|
|
52
|
-
config = {
|
|
53
|
-
dir: packageDir$,
|
|
54
|
-
name: packageFolderName || 'index',
|
|
55
|
-
input,
|
|
56
|
-
output: [
|
|
57
|
-
{
|
|
58
|
-
file: packageDir$ + '/dist/index.es.js',
|
|
59
|
-
format: 'es',
|
|
60
|
-
exports: 'named',
|
|
61
|
-
sourcemap: false
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
file: packageDir$ + '/dist/index.iife.js',
|
|
65
|
-
format: 'iife',
|
|
66
|
-
name: packageName,
|
|
67
|
-
},
|
|
68
|
-
{
|
|
69
|
-
file: packageDir$ + '/dist/index.cjs.js',
|
|
70
|
-
format: 'cjs'
|
|
71
|
-
}
|
|
72
|
-
].filter(i => {
|
|
73
|
-
return commandOptions.formats.includes(i.format);
|
|
74
|
-
})
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
this.packageDir = path__namespace.resolve(packageDir, workspace ? `./${config.name}` : '');
|
|
78
|
-
this.packageName = config.name === 'index'
|
|
198
|
+
constructor(packageFolderName, commandOptions) {
|
|
199
|
+
const { workspace, packageDir, packageName, packageFolderName: packageFolderName$ } = devShared.Locals.impl();
|
|
200
|
+
this.packageFolderName = packageFolderName || '';
|
|
201
|
+
this.packageDir = path__namespace.resolve(packageDir, workspace ? `./${packageFolderName}` : '');
|
|
202
|
+
this.packageSourceDir = path__namespace.resolve(packageDir, './src');
|
|
203
|
+
this.packageName = packageFolderName === packageFolderName$
|
|
79
204
|
? packageName
|
|
80
|
-
: `${packageName}-${
|
|
205
|
+
: `${packageName}-${packageFolderName}`;
|
|
81
206
|
this.packageOptions = require$(`${this.packageDir}/package.json`);
|
|
82
|
-
this.config = config;
|
|
83
207
|
this.commandOptions = commandOptions;
|
|
84
208
|
}
|
|
85
209
|
async process() {
|
|
86
210
|
const { cwd, workspace } = devShared.Locals.impl();
|
|
87
|
-
const {
|
|
211
|
+
const { packageOptions, packageName, packageDir } = this;
|
|
88
212
|
if (workspace
|
|
89
213
|
&& packageOptions?.scripts?.build
|
|
90
214
|
&& packageDir !== cwd) {
|
|
@@ -93,18 +217,28 @@ class Build {
|
|
|
93
217
|
});
|
|
94
218
|
return;
|
|
95
219
|
}
|
|
96
|
-
|
|
220
|
+
const srcDir = path__namespace.resolve(packageDir, './src');
|
|
221
|
+
let files = fs.existsSync(srcDir)
|
|
222
|
+
? fs
|
|
223
|
+
.readdirSync(srcDir)
|
|
224
|
+
.filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i))
|
|
225
|
+
: [];
|
|
226
|
+
if (!files.length)
|
|
97
227
|
return;
|
|
98
228
|
const spinner = ora(`${packageName} Build ...`);
|
|
99
229
|
try {
|
|
100
230
|
spinner.start();
|
|
101
231
|
await fs.emptyDir(`${packageDir}/dist`);
|
|
102
|
-
const
|
|
103
|
-
await this
|
|
232
|
+
const styleStats = await run$2(this);
|
|
233
|
+
const scriptStats = await run$3(this);
|
|
234
|
+
run$1(this);
|
|
104
235
|
spinner.stop();
|
|
105
236
|
devShared.Logger.log(`${chalk.cyan(`${packageName}`)}: ${chalk.green('Success')}`);
|
|
106
|
-
|
|
107
|
-
devShared.Logger.log(`${chalk.green(stat.format.toUpperCase())}
|
|
237
|
+
scriptStats.forEach((stat) => {
|
|
238
|
+
devShared.Logger.log(`${chalk.magenta(stat.file)}: ${chalk.green(stat.format.toUpperCase())} - ${devShared.Utils.formatBytes(stat.size)}`);
|
|
239
|
+
});
|
|
240
|
+
styleStats.forEach((stat) => {
|
|
241
|
+
devShared.Logger.log(`${chalk.magenta(stat.file)}: ${devShared.Utils.formatBytes(stat.size)}`);
|
|
108
242
|
});
|
|
109
243
|
}
|
|
110
244
|
catch (e) {
|
|
@@ -112,82 +246,6 @@ class Build {
|
|
|
112
246
|
throw e;
|
|
113
247
|
}
|
|
114
248
|
}
|
|
115
|
-
async buildSources() {
|
|
116
|
-
const { workspace } = devShared.Locals.impl();
|
|
117
|
-
const { name, input, output } = this.config;
|
|
118
|
-
const { packageOptions } = this;
|
|
119
|
-
const external = Object
|
|
120
|
-
.keys({
|
|
121
|
-
...packageOptions.dependencies,
|
|
122
|
-
...packageOptions.peerDependencies
|
|
123
|
-
})
|
|
124
|
-
.map(i => new RegExp(`^${i}$`));
|
|
125
|
-
const source = workspace ? `${workspace}/${name}/**/*` : 'src/**/*';
|
|
126
|
-
const shims = workspace ? `${workspace}/shims.d.ts` : 'shims.d.ts';
|
|
127
|
-
const outDir = workspace ? `${workspace}/${name}/dist` : 'dist';
|
|
128
|
-
const builder = await rollup.rollup({
|
|
129
|
-
input,
|
|
130
|
-
external: [
|
|
131
|
-
/^node:/,
|
|
132
|
-
/^[a-zA-Z@]/,
|
|
133
|
-
...external
|
|
134
|
-
],
|
|
135
|
-
plugins: [
|
|
136
|
-
typescript({
|
|
137
|
-
include: [source, shims],
|
|
138
|
-
exclude: ['dist'],
|
|
139
|
-
compilerOptions: {
|
|
140
|
-
rootDir: '.',
|
|
141
|
-
outDir,
|
|
142
|
-
declaration: true
|
|
143
|
-
}
|
|
144
|
-
}),
|
|
145
|
-
commonjs({ extensions: ['.js', '.ts'] }),
|
|
146
|
-
pluginNodeResolve.nodeResolve(),
|
|
147
|
-
replace({
|
|
148
|
-
'1.0.0': `'${packageOptions.version}'`,
|
|
149
|
-
false: 'false',
|
|
150
|
-
true: true
|
|
151
|
-
})
|
|
152
|
-
]
|
|
153
|
-
});
|
|
154
|
-
await Promise.all(output.map(builder.write));
|
|
155
|
-
const stats = [];
|
|
156
|
-
await output.reduce((pre, cur, index) => {
|
|
157
|
-
pre
|
|
158
|
-
.then(() => fs.stat(cur.file))
|
|
159
|
-
.then((stat) => {
|
|
160
|
-
stats[index] = {
|
|
161
|
-
format: cur.format,
|
|
162
|
-
size: stat.size
|
|
163
|
-
};
|
|
164
|
-
});
|
|
165
|
-
return pre;
|
|
166
|
-
}, Promise.resolve());
|
|
167
|
-
return stats;
|
|
168
|
-
}
|
|
169
|
-
async buildTypes() {
|
|
170
|
-
const { workspace } = devShared.Locals.impl();
|
|
171
|
-
const { packageDir, packageOptions } = this;
|
|
172
|
-
if (workspace && packageOptions?.scripts?.['build:types']) {
|
|
173
|
-
await devShared.Shell.spawn(`npm`, ['run', 'build:types'], {
|
|
174
|
-
cwd: packageDir
|
|
175
|
-
});
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const config = path__namespace.resolve(packageDir, `api-extractor.json`);
|
|
179
|
-
if (fs.existsSync(config)) {
|
|
180
|
-
const result = apiExtractor.Extractor.invoke(apiExtractor.ExtractorConfig.loadFileAndPrepare(config), {
|
|
181
|
-
localBuild: true,
|
|
182
|
-
showVerboseMessages: false
|
|
183
|
-
});
|
|
184
|
-
if (!result.succeeded) {
|
|
185
|
-
devShared.Logger.error(`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`);
|
|
186
|
-
process.exitCode = 1;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
await fs.remove(`${packageDir}/dist/${workspace || 'src'}`);
|
|
190
|
-
}
|
|
191
249
|
}
|
|
192
250
|
const build = (options, commandOptions) => {
|
|
193
251
|
return new Build(options, commandOptions);
|
|
@@ -195,7 +253,7 @@ const build = (options, commandOptions) => {
|
|
|
195
253
|
|
|
196
254
|
const run = (options) => devShared.Utils.autoCatch(async () => {
|
|
197
255
|
options = {
|
|
198
|
-
|
|
256
|
+
scriptFormats: 'es,cjs',
|
|
199
257
|
...options
|
|
200
258
|
};
|
|
201
259
|
const locals = devShared.Locals.impl();
|
|
@@ -203,9 +261,9 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
|
|
|
203
261
|
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
204
262
|
}
|
|
205
263
|
const { normalizePackageFolderNames } = devShared.Locals.impl();
|
|
206
|
-
let packageFolderName = devShared.Locals.getPackageFolderName(options.packageName || '
|
|
264
|
+
let packageFolderName = devShared.Locals.getPackageFolderName(options.packageName || '*');
|
|
207
265
|
let inputs = [];
|
|
208
|
-
if (locals.workspace && packageFolderName === '
|
|
266
|
+
if (locals.workspace && packageFolderName === '*') {
|
|
209
267
|
inputs = normalizePackageFolderNames;
|
|
210
268
|
}
|
|
211
269
|
else {
|
package/dist/index.es.js
CHANGED
|
@@ -2,68 +2,192 @@ import { Locals, Shell, Logger, Utils } from '@deot/dev-shared';
|
|
|
2
2
|
import * as path from 'node:path';
|
|
3
3
|
import { createRequire } from 'node:module';
|
|
4
4
|
import fs from 'fs-extra';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import ora from 'ora';
|
|
5
7
|
import typescript from '@rollup/plugin-typescript';
|
|
6
8
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
7
9
|
import commonjs from '@rollup/plugin-commonjs';
|
|
8
10
|
import replace from '@rollup/plugin-replace';
|
|
9
11
|
import { rollup } from 'rollup';
|
|
12
|
+
import sass from 'sass';
|
|
13
|
+
import postcss from 'postcss';
|
|
14
|
+
import atImport from 'postcss-import';
|
|
15
|
+
import atUrl from 'postcss-url';
|
|
16
|
+
import flexBugs from 'postcss-flexbugs-fixes';
|
|
17
|
+
import cssnano from 'cssnano';
|
|
18
|
+
import autoprefixer from 'autoprefixer';
|
|
10
19
|
import { Extractor, ExtractorConfig } from '@microsoft/api-extractor';
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
|
|
21
|
+
const run$3 = async (options) => {
|
|
22
|
+
const { packageName, packageFolderName, packageDir, commandOptions, packageOptions } = options || {};
|
|
23
|
+
const { workspace } = Locals.impl();
|
|
24
|
+
const srcDir = path.resolve(packageDir, './src');
|
|
25
|
+
let files = fs.existsSync(srcDir)
|
|
26
|
+
? fs
|
|
27
|
+
.readdirSync(srcDir)
|
|
28
|
+
.filter((i) => /^index(.*)\.(t|j)s$/.test(i))
|
|
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());
|
|
108
|
+
return stats;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const run$2 = async (options) => {
|
|
112
|
+
const { packageDir } = options || {};
|
|
113
|
+
const srcDir = path.resolve(packageDir, './src');
|
|
114
|
+
const styles = fs.readdirSync(srcDir).filter((i) => /^index(.*)\.s?css$/.test(i));
|
|
115
|
+
const stats = [];
|
|
116
|
+
await styles
|
|
117
|
+
.reduce((preProcess, file) => {
|
|
118
|
+
preProcess = preProcess
|
|
119
|
+
.then(() => {
|
|
120
|
+
let filepath = path.resolve(srcDir, file);
|
|
121
|
+
const data = sass.compile(filepath, { style: 'compressed' });
|
|
122
|
+
return postcss()
|
|
123
|
+
.use(atImport())
|
|
124
|
+
.use(atUrl())
|
|
125
|
+
.use(flexBugs())
|
|
126
|
+
.use(cssnano())
|
|
127
|
+
.use(autoprefixer({ remove: false }))
|
|
128
|
+
.process(data.css, { from: filepath });
|
|
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
|
+
});
|
|
140
|
+
});
|
|
141
|
+
return preProcess;
|
|
142
|
+
}, Promise.resolve());
|
|
143
|
+
return stats;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const run$1 = async (options) => {
|
|
147
|
+
const { workspace } = Locals.impl();
|
|
148
|
+
const { packageDir, packageOptions } = options;
|
|
149
|
+
if (workspace && packageOptions?.scripts?.['build:types']) {
|
|
150
|
+
await Shell.spawn(`npm`, ['run', 'build:types'], {
|
|
151
|
+
cwd: packageDir
|
|
152
|
+
});
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const config = path.resolve(packageDir, `api-extractor.json`);
|
|
156
|
+
if (fs.existsSync(config)) {
|
|
157
|
+
const result = Extractor.invoke(ExtractorConfig.loadFileAndPrepare(config), {
|
|
158
|
+
localBuild: true,
|
|
159
|
+
showVerboseMessages: false
|
|
160
|
+
});
|
|
161
|
+
if (!result.succeeded) {
|
|
162
|
+
Logger.error(`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`);
|
|
163
|
+
process.exitCode = 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
await fs.remove(`${packageDir}/dist/${workspace || 'src'}`);
|
|
167
|
+
};
|
|
13
168
|
|
|
14
169
|
const require$ = createRequire(process.cwd());
|
|
15
170
|
class Build {
|
|
16
171
|
packageDir;
|
|
172
|
+
packageFolderName;
|
|
173
|
+
packageSourceDir;
|
|
17
174
|
packageName;
|
|
18
175
|
packageOptions;
|
|
19
|
-
config;
|
|
20
176
|
commandOptions;
|
|
21
|
-
constructor(
|
|
22
|
-
const { workspace, packageDir, packageName } = Locals.impl();
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
? packageDir$ + '/src/index.ts'
|
|
28
|
-
: fs.existsSync(packageDir$ + '/src/index.js')
|
|
29
|
-
? packageDir$ + '/src/index.js'
|
|
30
|
-
: '';
|
|
31
|
-
config = {
|
|
32
|
-
dir: packageDir$,
|
|
33
|
-
name: packageFolderName || 'index',
|
|
34
|
-
input,
|
|
35
|
-
output: [
|
|
36
|
-
{
|
|
37
|
-
file: packageDir$ + '/dist/index.es.js',
|
|
38
|
-
format: 'es',
|
|
39
|
-
exports: 'named',
|
|
40
|
-
sourcemap: false
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
file: packageDir$ + '/dist/index.iife.js',
|
|
44
|
-
format: 'iife',
|
|
45
|
-
name: packageName,
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
file: packageDir$ + '/dist/index.cjs.js',
|
|
49
|
-
format: 'cjs'
|
|
50
|
-
}
|
|
51
|
-
].filter(i => {
|
|
52
|
-
return commandOptions.formats.includes(i.format);
|
|
53
|
-
})
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
this.packageDir = path.resolve(packageDir, workspace ? `./${config.name}` : '');
|
|
57
|
-
this.packageName = config.name === 'index'
|
|
177
|
+
constructor(packageFolderName, commandOptions) {
|
|
178
|
+
const { workspace, packageDir, packageName, packageFolderName: packageFolderName$ } = Locals.impl();
|
|
179
|
+
this.packageFolderName = packageFolderName || '';
|
|
180
|
+
this.packageDir = path.resolve(packageDir, workspace ? `./${packageFolderName}` : '');
|
|
181
|
+
this.packageSourceDir = path.resolve(packageDir, './src');
|
|
182
|
+
this.packageName = packageFolderName === packageFolderName$
|
|
58
183
|
? packageName
|
|
59
|
-
: `${packageName}-${
|
|
184
|
+
: `${packageName}-${packageFolderName}`;
|
|
60
185
|
this.packageOptions = require$(`${this.packageDir}/package.json`);
|
|
61
|
-
this.config = config;
|
|
62
186
|
this.commandOptions = commandOptions;
|
|
63
187
|
}
|
|
64
188
|
async process() {
|
|
65
189
|
const { cwd, workspace } = Locals.impl();
|
|
66
|
-
const {
|
|
190
|
+
const { packageOptions, packageName, packageDir } = this;
|
|
67
191
|
if (workspace
|
|
68
192
|
&& packageOptions?.scripts?.build
|
|
69
193
|
&& packageDir !== cwd) {
|
|
@@ -72,18 +196,28 @@ class Build {
|
|
|
72
196
|
});
|
|
73
197
|
return;
|
|
74
198
|
}
|
|
75
|
-
|
|
199
|
+
const srcDir = path.resolve(packageDir, './src');
|
|
200
|
+
let files = fs.existsSync(srcDir)
|
|
201
|
+
? fs
|
|
202
|
+
.readdirSync(srcDir)
|
|
203
|
+
.filter((i) => /^index(.*)\.(ts|js|s?css)$/.test(i))
|
|
204
|
+
: [];
|
|
205
|
+
if (!files.length)
|
|
76
206
|
return;
|
|
77
207
|
const spinner = ora(`${packageName} Build ...`);
|
|
78
208
|
try {
|
|
79
209
|
spinner.start();
|
|
80
210
|
await fs.emptyDir(`${packageDir}/dist`);
|
|
81
|
-
const
|
|
82
|
-
await this
|
|
211
|
+
const styleStats = await run$2(this);
|
|
212
|
+
const scriptStats = await run$3(this);
|
|
213
|
+
run$1(this);
|
|
83
214
|
spinner.stop();
|
|
84
215
|
Logger.log(`${chalk.cyan(`${packageName}`)}: ${chalk.green('Success')}`);
|
|
85
|
-
|
|
86
|
-
Logger.log(`${chalk.green(stat.format.toUpperCase())}
|
|
216
|
+
scriptStats.forEach((stat) => {
|
|
217
|
+
Logger.log(`${chalk.magenta(stat.file)}: ${chalk.green(stat.format.toUpperCase())} - ${Utils.formatBytes(stat.size)}`);
|
|
218
|
+
});
|
|
219
|
+
styleStats.forEach((stat) => {
|
|
220
|
+
Logger.log(`${chalk.magenta(stat.file)}: ${Utils.formatBytes(stat.size)}`);
|
|
87
221
|
});
|
|
88
222
|
}
|
|
89
223
|
catch (e) {
|
|
@@ -91,82 +225,6 @@ class Build {
|
|
|
91
225
|
throw e;
|
|
92
226
|
}
|
|
93
227
|
}
|
|
94
|
-
async buildSources() {
|
|
95
|
-
const { workspace } = Locals.impl();
|
|
96
|
-
const { name, input, output } = this.config;
|
|
97
|
-
const { packageOptions } = this;
|
|
98
|
-
const external = Object
|
|
99
|
-
.keys({
|
|
100
|
-
...packageOptions.dependencies,
|
|
101
|
-
...packageOptions.peerDependencies
|
|
102
|
-
})
|
|
103
|
-
.map(i => new RegExp(`^${i}$`));
|
|
104
|
-
const source = workspace ? `${workspace}/${name}/**/*` : 'src/**/*';
|
|
105
|
-
const shims = workspace ? `${workspace}/shims.d.ts` : 'shims.d.ts';
|
|
106
|
-
const outDir = workspace ? `${workspace}/${name}/dist` : 'dist';
|
|
107
|
-
const builder = await rollup({
|
|
108
|
-
input,
|
|
109
|
-
external: [
|
|
110
|
-
/^node:/,
|
|
111
|
-
/^[a-zA-Z@]/,
|
|
112
|
-
...external
|
|
113
|
-
],
|
|
114
|
-
plugins: [
|
|
115
|
-
typescript({
|
|
116
|
-
include: [source, shims],
|
|
117
|
-
exclude: ['dist'],
|
|
118
|
-
compilerOptions: {
|
|
119
|
-
rootDir: '.',
|
|
120
|
-
outDir,
|
|
121
|
-
declaration: true
|
|
122
|
-
}
|
|
123
|
-
}),
|
|
124
|
-
commonjs({ extensions: ['.js', '.ts'] }),
|
|
125
|
-
nodeResolve(),
|
|
126
|
-
replace({
|
|
127
|
-
'1.0.0': `'${packageOptions.version}'`,
|
|
128
|
-
false: 'false',
|
|
129
|
-
true: true
|
|
130
|
-
})
|
|
131
|
-
]
|
|
132
|
-
});
|
|
133
|
-
await Promise.all(output.map(builder.write));
|
|
134
|
-
const stats = [];
|
|
135
|
-
await output.reduce((pre, cur, index) => {
|
|
136
|
-
pre
|
|
137
|
-
.then(() => fs.stat(cur.file))
|
|
138
|
-
.then((stat) => {
|
|
139
|
-
stats[index] = {
|
|
140
|
-
format: cur.format,
|
|
141
|
-
size: stat.size
|
|
142
|
-
};
|
|
143
|
-
});
|
|
144
|
-
return pre;
|
|
145
|
-
}, Promise.resolve());
|
|
146
|
-
return stats;
|
|
147
|
-
}
|
|
148
|
-
async buildTypes() {
|
|
149
|
-
const { workspace } = Locals.impl();
|
|
150
|
-
const { packageDir, packageOptions } = this;
|
|
151
|
-
if (workspace && packageOptions?.scripts?.['build:types']) {
|
|
152
|
-
await Shell.spawn(`npm`, ['run', 'build:types'], {
|
|
153
|
-
cwd: packageDir
|
|
154
|
-
});
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const config = path.resolve(packageDir, `api-extractor.json`);
|
|
158
|
-
if (fs.existsSync(config)) {
|
|
159
|
-
const result = Extractor.invoke(ExtractorConfig.loadFileAndPrepare(config), {
|
|
160
|
-
localBuild: true,
|
|
161
|
-
showVerboseMessages: false
|
|
162
|
-
});
|
|
163
|
-
if (!result.succeeded) {
|
|
164
|
-
Logger.error(`API Extractor completed with ${result.errorCount} errors and ${result.warningCount} warnings`);
|
|
165
|
-
process.exitCode = 1;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
await fs.remove(`${packageDir}/dist/${workspace || 'src'}`);
|
|
169
|
-
}
|
|
170
228
|
}
|
|
171
229
|
const build = (options, commandOptions) => {
|
|
172
230
|
return new Build(options, commandOptions);
|
|
@@ -174,7 +232,7 @@ const build = (options, commandOptions) => {
|
|
|
174
232
|
|
|
175
233
|
const run = (options) => Utils.autoCatch(async () => {
|
|
176
234
|
options = {
|
|
177
|
-
|
|
235
|
+
scriptFormats: 'es,cjs',
|
|
178
236
|
...options
|
|
179
237
|
};
|
|
180
238
|
const locals = Locals.impl();
|
|
@@ -182,9 +240,9 @@ const run = (options) => Utils.autoCatch(async () => {
|
|
|
182
240
|
options.dryRun = process.env.NODE_ENV === 'UNIT';
|
|
183
241
|
}
|
|
184
242
|
const { normalizePackageFolderNames } = Locals.impl();
|
|
185
|
-
let packageFolderName = Locals.getPackageFolderName(options.packageName || '
|
|
243
|
+
let packageFolderName = Locals.getPackageFolderName(options.packageName || '*');
|
|
186
244
|
let inputs = [];
|
|
187
|
-
if (locals.workspace && packageFolderName === '
|
|
245
|
+
if (locals.workspace && packageFolderName === '*') {
|
|
188
246
|
inputs = normalizePackageFolderNames;
|
|
189
247
|
}
|
|
190
248
|
else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-builder",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"main": "dist/index.es.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,14 +12,34 @@
|
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|
|
14
14
|
},
|
|
15
|
+
"peerDependencies": {
|
|
16
|
+
"typescript": "*"
|
|
17
|
+
},
|
|
18
|
+
"peerDependenciesMeta": {
|
|
19
|
+
"typescript": {
|
|
20
|
+
"optional": true
|
|
21
|
+
}
|
|
22
|
+
},
|
|
15
23
|
"dependencies": {
|
|
16
|
-
"@deot/dev-
|
|
17
|
-
"@deot/dev-shared": "^1.1.0",
|
|
24
|
+
"@deot/dev-shared": "^1.1.1",
|
|
18
25
|
"@microsoft/api-extractor": "^7.34.4",
|
|
19
26
|
"@rollup/plugin-commonjs": "^24.1.0",
|
|
20
27
|
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
21
28
|
"@rollup/plugin-replace": "^5.0.2",
|
|
22
|
-
"@rollup/plugin-typescript": "11.1.0",
|
|
23
|
-
"
|
|
29
|
+
"@rollup/plugin-typescript": "^11.1.0",
|
|
30
|
+
"autoprefixer": "^10.4.14",
|
|
31
|
+
"chalk": "^5.2.0",
|
|
32
|
+
"cssnano": "^5.1.15",
|
|
33
|
+
"fs-extra": "^11.1.1",
|
|
34
|
+
"ora": "^6.1.2",
|
|
35
|
+
"postcss": "^8.4.21",
|
|
36
|
+
"postcss-flexbugs-fixes": "^5.0.2",
|
|
37
|
+
"postcss-import": "^15.1.0",
|
|
38
|
+
"postcss-url": "^10.1.3",
|
|
39
|
+
"rollup": "^3.20.5",
|
|
40
|
+
"sass": "^1.60.0"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"typescript": "^5.0.4"
|
|
24
44
|
}
|
|
25
45
|
}
|