@cmmn/tools 1.6.5 → 1.6.8
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/bin.js +2 -1
- package/bundle/bundle.js +4 -63
- package/bundle/getConfigs.js +60 -0
- package/bundle/rollup.config.js +18 -20
- package/compile/tsconfig.json +5 -0
- package/package.json +4 -2
- package/plugins/absolute-plugin.cjs +2 -2
- package/readme.md +3 -1
package/bin.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import {bundle} from "./bundle/bundle.js";
|
|
4
|
+
import {serve} from "./serve/serve.js";
|
|
4
5
|
import {compile} from "./compile/compile.js";
|
|
5
6
|
import {gen} from "./gen/gen.js";
|
|
6
7
|
|
|
7
8
|
const [action, ...args] = process.argv.slice(2);
|
|
8
9
|
|
|
9
10
|
const actions = {
|
|
10
|
-
bundle, compile, gen
|
|
11
|
+
bundle, compile, gen, serve
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
if (action in actions) {
|
package/bundle/bundle.js
CHANGED
|
@@ -1,76 +1,17 @@
|
|
|
1
|
-
import {ConfigCreator} from "./rollup.config.js";
|
|
2
1
|
import {rollup, watch} from "rollup";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import fg from "fast-glob";
|
|
6
|
-
|
|
7
|
-
function getProjectConfig(rootDir, cmmn, options) {
|
|
8
|
-
const configCreator = new ConfigCreator({
|
|
9
|
-
...options,
|
|
10
|
-
...cmmn,
|
|
11
|
-
});
|
|
12
|
-
configCreator.setRootDir(rootDir);
|
|
13
|
-
return configCreator.getConfig();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getPackageConfigs(rootDir, options, name = null) {
|
|
17
|
-
const pckPath = path.join(rootDir, 'package.json');
|
|
18
|
-
if (!fs.existsSync(pckPath))
|
|
19
|
-
return [];
|
|
20
|
-
const results = [];
|
|
21
|
-
const pkg = JSON.parse(fs.readFileSync(pckPath));
|
|
22
|
-
if (name) {
|
|
23
|
-
results.push(...getProjectConfig(rootDir, pkg.cmmn[name], {
|
|
24
|
-
...options,
|
|
25
|
-
name
|
|
26
|
-
}));
|
|
27
|
-
} else {
|
|
28
|
-
for (let name in pkg.cmmn) {
|
|
29
|
-
results.push(...getProjectConfig(rootDir, pkg.cmmn[name], {
|
|
30
|
-
...options,
|
|
31
|
-
name
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return results;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function getLernaSubPackages(lernaFile, options) {
|
|
39
|
-
const config = JSON.parse(fs.readFileSync(lernaFile, 'utf8'));
|
|
40
|
-
const packages = config.packages;
|
|
41
|
-
const dirs = packages.flatMap(pkg => fg.sync([pkg], {
|
|
42
|
-
absolute: true,
|
|
43
|
-
globstar: true,
|
|
44
|
-
onlyDirectories: true,
|
|
45
|
-
cwd: path.dirname(lernaFile)
|
|
46
|
-
}));
|
|
47
|
-
return dirs.flatMap(dir => getPackageConfigs(dir, options));
|
|
48
|
-
}
|
|
2
|
+
import {getConfigOptions} from "./getConfigs.js";
|
|
3
|
+
import {ConfigCreator} from "./rollup.config.js";
|
|
49
4
|
|
|
50
|
-
function getConfigs(options) {
|
|
51
|
-
if (!options.input || options.project) {
|
|
52
|
-
const rootDir = process.cwd();
|
|
53
|
-
const lernaPath = path.join(rootDir, 'lerna.json');
|
|
54
|
-
if (fs.existsSync(lernaPath)) {
|
|
55
|
-
return getLernaSubPackages(lernaPath, options);
|
|
56
|
-
}
|
|
57
|
-
return getPackageConfigs(process.cwd(), options);
|
|
58
|
-
}
|
|
59
|
-
if (!options.input.includes('.') || !fs.existsSync(options.input)) {
|
|
60
|
-
return getPackageConfigs(process.cwd(), options, options.input);
|
|
61
|
-
}
|
|
62
|
-
const creator = new ConfigCreator(options);
|
|
63
|
-
return creator.getConfig();
|
|
64
|
-
}
|
|
65
5
|
|
|
66
6
|
export async function bundle(...options) {
|
|
67
|
-
const
|
|
7
|
+
const configOptions = getConfigOptions({
|
|
68
8
|
input: options.filter(x => !x.startsWith('-'))[0],
|
|
69
9
|
project: options.includes('-b'),
|
|
70
10
|
minify: options.includes('--prod'),
|
|
71
11
|
devServer: options.includes('--run'),
|
|
72
12
|
stats: options.includes('--stats'),
|
|
73
13
|
});
|
|
14
|
+
const configs = configOptions.flatMap(x => new ConfigCreator(x).getConfig());
|
|
74
15
|
if (!options.includes('--watch')) {
|
|
75
16
|
for (let config of configs) {
|
|
76
17
|
for (let key in config.input){
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fg from "fast-glob";
|
|
4
|
+
|
|
5
|
+
function getProjectConfig(rootDir, cmmn, options) {
|
|
6
|
+
return {
|
|
7
|
+
...options,
|
|
8
|
+
...cmmn,
|
|
9
|
+
rootDir: rootDir
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getPackageConfigs(rootDir, options, name = null) {
|
|
14
|
+
const pckPath = path.join(rootDir, 'package.json');
|
|
15
|
+
if (!fs.existsSync(pckPath))
|
|
16
|
+
return [];
|
|
17
|
+
const results = [];
|
|
18
|
+
const pkg = JSON.parse(fs.readFileSync(pckPath));
|
|
19
|
+
if (name) {
|
|
20
|
+
results.push(getProjectConfig(rootDir, pkg.cmmn[name], {
|
|
21
|
+
...options,
|
|
22
|
+
name
|
|
23
|
+
}));
|
|
24
|
+
} else {
|
|
25
|
+
for (let name in pkg.cmmn) {
|
|
26
|
+
results.push(getProjectConfig(rootDir, pkg.cmmn[name], {
|
|
27
|
+
...options,
|
|
28
|
+
name
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return results;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getLernaSubPackages(lernaFile, options) {
|
|
36
|
+
const config = JSON.parse(fs.readFileSync(lernaFile, 'utf8'));
|
|
37
|
+
const packages = config.packages;
|
|
38
|
+
const dirs = packages.flatMap(pkg => fg.sync([pkg], {
|
|
39
|
+
absolute: true,
|
|
40
|
+
globstar: true,
|
|
41
|
+
onlyDirectories: true,
|
|
42
|
+
cwd: path.dirname(lernaFile)
|
|
43
|
+
}));
|
|
44
|
+
return dirs.flatMap(dir => getPackageConfigs(dir, options));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function getConfigOptions(options) {
|
|
48
|
+
if (!options.input || options.project) {
|
|
49
|
+
const rootDir = process.cwd();
|
|
50
|
+
const lernaPath = path.join(rootDir, 'lerna.json');
|
|
51
|
+
if (fs.existsSync(lernaPath)) {
|
|
52
|
+
return getLernaSubPackages(lernaPath, options);
|
|
53
|
+
}
|
|
54
|
+
return getPackageConfigs(process.cwd(), options);
|
|
55
|
+
}
|
|
56
|
+
if (!options.input.includes('.') || !fs.existsSync(options.input)) {
|
|
57
|
+
return getPackageConfigs(process.cwd(), options, options.input);
|
|
58
|
+
}
|
|
59
|
+
return [options];
|
|
60
|
+
}
|
package/bundle/rollup.config.js
CHANGED
|
@@ -14,6 +14,7 @@ import html from '@open-wc/rollup-plugin-html';
|
|
|
14
14
|
import json from '@rollup/plugin-json';
|
|
15
15
|
import alias from '@rollup/plugin-alias';
|
|
16
16
|
import replace from '@rollup/plugin-replace';
|
|
17
|
+
import sourcemaps from 'rollup-plugin-sourcemaps';
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* @typedef {import(rollup).RollupOptions} RollupOptions
|
|
@@ -48,12 +49,14 @@ export class ConfigCreator {
|
|
|
48
49
|
|
|
49
50
|
constructor(options) {
|
|
50
51
|
this.options = {
|
|
52
|
+
module: 'es',
|
|
53
|
+
external: [],
|
|
54
|
+
name: 'index',
|
|
55
|
+
outDir: 'dist/bundle',
|
|
51
56
|
...options
|
|
52
57
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
setRootDir(rootDir) {
|
|
56
|
-
this.root = rootDir;
|
|
58
|
+
if (options.rootDir)
|
|
59
|
+
this.root = options.rootDir;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
get outDir() {
|
|
@@ -100,14 +103,14 @@ export class ConfigCreator {
|
|
|
100
103
|
return serve({
|
|
101
104
|
open: false,
|
|
102
105
|
contentBase: [this.outDir, path.join(this.root, 'assets')],
|
|
103
|
-
port: this.options.port
|
|
106
|
+
port: this.options.port,
|
|
104
107
|
historyApiFallback: true
|
|
105
108
|
});
|
|
106
109
|
}
|
|
107
110
|
|
|
108
111
|
get livereload() {
|
|
109
112
|
return livereload({
|
|
110
|
-
watch: [this.outDir, path.join(this.root, 'assets')],
|
|
113
|
+
watch: [this.outDir, path.join(this.root, 'assets'), this.options.html],
|
|
111
114
|
verbose: false, // Disable console output
|
|
112
115
|
// other livereload options
|
|
113
116
|
port: 12345,
|
|
@@ -137,11 +140,9 @@ export class ConfigCreator {
|
|
|
137
140
|
dedupe: this.options.dedupe || []
|
|
138
141
|
}),
|
|
139
142
|
commonjs({
|
|
140
|
-
requireReturnsDefault: "namespace"
|
|
141
|
-
dynamicRequireTargets: [
|
|
142
|
-
'node_modules/ulid/*.js'
|
|
143
|
-
]
|
|
143
|
+
requireReturnsDefault: "namespace"
|
|
144
144
|
}),
|
|
145
|
+
sourcemaps(),
|
|
145
146
|
builtins(),
|
|
146
147
|
/*this.options.styles === 'modules' ? postCSS({
|
|
147
148
|
mode: [
|
|
@@ -182,6 +183,9 @@ export class ConfigCreator {
|
|
|
182
183
|
if (this.options.html || this.options.input.endsWith('.html')) {
|
|
183
184
|
result.push(this.html);
|
|
184
185
|
}
|
|
186
|
+
if (this.options.stats) {
|
|
187
|
+
result.push(this.visualizer);
|
|
188
|
+
}
|
|
185
189
|
if (this.options.minify) {
|
|
186
190
|
result.push(terser({
|
|
187
191
|
module: true,
|
|
@@ -195,12 +199,9 @@ export class ConfigCreator {
|
|
|
195
199
|
}
|
|
196
200
|
}));
|
|
197
201
|
}
|
|
198
|
-
if (this.options.devServer) {
|
|
202
|
+
if (this.options.devServer && this.options.port) {
|
|
199
203
|
result.push(this.devServer, this.livereload);
|
|
200
204
|
}
|
|
201
|
-
if (this.options.stats) {
|
|
202
|
-
result.push(this.visualizer);
|
|
203
|
-
}
|
|
204
205
|
return result;
|
|
205
206
|
}
|
|
206
207
|
|
|
@@ -216,12 +217,6 @@ export class ConfigCreator {
|
|
|
216
217
|
* @returns {RollupOptions[]}
|
|
217
218
|
*/
|
|
218
219
|
getConfig() {
|
|
219
|
-
Object.assign(this.options, {
|
|
220
|
-
module: this.options.module || 'es',
|
|
221
|
-
external: this.options.external || [],
|
|
222
|
-
name: this.options.name || 'index',
|
|
223
|
-
outDir: this.options.outDir || 'dist'
|
|
224
|
-
});
|
|
225
220
|
if (this.options.external && typeof this.options.external === "string")
|
|
226
221
|
this.options.external = [this.options.external]
|
|
227
222
|
console.log(this.options.name, this.options);
|
|
@@ -250,6 +245,9 @@ export class ConfigCreator {
|
|
|
250
245
|
},
|
|
251
246
|
plugins: this.plugins,
|
|
252
247
|
treeshake: this.options.minify ? "smallest" : "recommended",
|
|
248
|
+
watch: {
|
|
249
|
+
exclude: this.getExternals().concat(path.join(this.root, this.outDir)),
|
|
250
|
+
}
|
|
253
251
|
}]
|
|
254
252
|
}
|
|
255
253
|
}
|
package/compile/tsconfig.json
CHANGED
|
@@ -10,8 +10,13 @@
|
|
|
10
10
|
"checkJs": false,
|
|
11
11
|
"outDir": "./dist/esm",
|
|
12
12
|
"skipLibCheck": true,
|
|
13
|
+
"incremental": true,
|
|
14
|
+
"disableSolutionSearching": true,
|
|
15
|
+
"assumeChangesOnlyAffectDirectDependencies": true,
|
|
13
16
|
"skipDefaultLibCheck": true,
|
|
14
17
|
"allowJs": true,
|
|
18
|
+
"disableReferencedProjectLoad": true,
|
|
19
|
+
"disableSourceOfProjectReferenceRedirect": true,
|
|
15
20
|
"allowSyntheticDefaultImports": true,
|
|
16
21
|
"emitDecoratorMetadata": true ,
|
|
17
22
|
"noEmitHelpers": true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmmn/tools",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.8",
|
|
4
4
|
"description": "Compilation, bundling, code generator, testing.",
|
|
5
5
|
"main": "dist/rollup.config.js",
|
|
6
6
|
"type": "module",
|
|
@@ -61,10 +61,12 @@
|
|
|
61
61
|
"rollup-plugin-node-globals": "^1.4.0",
|
|
62
62
|
"rollup-plugin-postcss": "4.x.x",
|
|
63
63
|
"rollup-plugin-serve": "^1.1.0",
|
|
64
|
+
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
64
65
|
"rollup-plugin-string": "^3.0.0",
|
|
65
66
|
"rollup-plugin-styles": "^4",
|
|
66
67
|
"rollup-plugin-terser": "^7",
|
|
67
68
|
"rollup-plugin-visualizer": "^5.5.4",
|
|
69
|
+
"servor": "4.x.x",
|
|
68
70
|
"sinon": "10.x.x",
|
|
69
71
|
"ts-jest": "27.x.x",
|
|
70
72
|
"ttypescript": "1.5.13",
|
|
@@ -73,5 +75,5 @@
|
|
|
73
75
|
},
|
|
74
76
|
"author": "",
|
|
75
77
|
"license": "ISC",
|
|
76
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "f4e9729796c27c9c9f42b30082b44e8afa6d62c4"
|
|
77
79
|
}
|
|
@@ -8,7 +8,7 @@ function visitExportNode(exportNode, sourceFile) {
|
|
|
8
8
|
return ;
|
|
9
9
|
}
|
|
10
10
|
const file = exportNode.moduleSpecifier?.text ?? exportNode.test;
|
|
11
|
-
if (!file)
|
|
11
|
+
if (!file || !file.startsWith('.'))
|
|
12
12
|
return;
|
|
13
13
|
const sourceFileDir = path.dirname(sourceFile.path);
|
|
14
14
|
const abs = path.resolve(sourceFileDir, file);
|
|
@@ -28,7 +28,7 @@ function visitExportNode(exportNode, sourceFile) {
|
|
|
28
28
|
|
|
29
29
|
function visitImportNode(importNode, sourceFile, options) {
|
|
30
30
|
const file = importNode.moduleSpecifier?.text;
|
|
31
|
-
if (!file)
|
|
31
|
+
if (!file || !file.startsWith('.'))
|
|
32
32
|
return;
|
|
33
33
|
const sourceFileDir = path.dirname(sourceFile.path);
|
|
34
34
|
const abs = path.resolve(sourceFileDir, file);
|