@cmmn/tools 1.6.6 → 1.6.9
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 +14 -17
- package/compile/tsconfig.json +5 -0
- package/package.json +4 -2
- package/plugins/absolute-plugin.cjs +2 -2
- package/readme.md +3 -1
- package/serve/serve.js +21 -0
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
|
@@ -15,6 +15,7 @@ import json from '@rollup/plugin-json';
|
|
|
15
15
|
import alias from '@rollup/plugin-alias';
|
|
16
16
|
import replace from '@rollup/plugin-replace';
|
|
17
17
|
import sourcemaps from 'rollup-plugin-sourcemaps';
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* @typedef {import(rollup).RollupOptions} RollupOptions
|
|
20
21
|
* @typedef {import(rollup).OutputOptions} OutputOptions
|
|
@@ -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,10 +140,7 @@ 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
145
|
sourcemaps(),
|
|
146
146
|
builtins(),
|
|
@@ -199,7 +199,7 @@ export class ConfigCreator {
|
|
|
199
199
|
}
|
|
200
200
|
}));
|
|
201
201
|
}
|
|
202
|
-
if (this.options.devServer) {
|
|
202
|
+
if (this.options.devServer && this.options.port) {
|
|
203
203
|
result.push(this.devServer, this.livereload);
|
|
204
204
|
}
|
|
205
205
|
return result;
|
|
@@ -217,12 +217,6 @@ export class ConfigCreator {
|
|
|
217
217
|
* @returns {RollupOptions[]}
|
|
218
218
|
*/
|
|
219
219
|
getConfig() {
|
|
220
|
-
Object.assign(this.options, {
|
|
221
|
-
module: this.options.module || 'es',
|
|
222
|
-
external: this.options.external || [],
|
|
223
|
-
name: this.options.name || 'index',
|
|
224
|
-
outDir: this.options.outDir || 'dist'
|
|
225
|
-
});
|
|
226
220
|
if (this.options.external && typeof this.options.external === "string")
|
|
227
221
|
this.options.external = [this.options.external]
|
|
228
222
|
console.log(this.options.name, this.options);
|
|
@@ -251,6 +245,9 @@ export class ConfigCreator {
|
|
|
251
245
|
},
|
|
252
246
|
plugins: this.plugins,
|
|
253
247
|
treeshake: this.options.minify ? "smallest" : "recommended",
|
|
248
|
+
watch: {
|
|
249
|
+
exclude: this.getExternals().concat(path.join(this.root, this.outDir)),
|
|
250
|
+
}
|
|
254
251
|
}]
|
|
255
252
|
}
|
|
256
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.9",
|
|
4
4
|
"description": "Compilation, bundling, code generator, testing.",
|
|
5
5
|
"main": "dist/rollup.config.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"gen/*",
|
|
35
35
|
"compile/*",
|
|
36
36
|
"bundle/*",
|
|
37
|
+
"serve/*",
|
|
37
38
|
"plugins/*",
|
|
38
39
|
"test/*"
|
|
39
40
|
],
|
|
@@ -66,6 +67,7 @@
|
|
|
66
67
|
"rollup-plugin-styles": "^4",
|
|
67
68
|
"rollup-plugin-terser": "^7",
|
|
68
69
|
"rollup-plugin-visualizer": "^5.5.4",
|
|
70
|
+
"servor": "4.x.x",
|
|
69
71
|
"sinon": "10.x.x",
|
|
70
72
|
"ts-jest": "27.x.x",
|
|
71
73
|
"ttypescript": "1.5.13",
|
|
@@ -74,5 +76,5 @@
|
|
|
74
76
|
},
|
|
75
77
|
"author": "",
|
|
76
78
|
"license": "ISC",
|
|
77
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "5b28fdf72e182a3c775b0012bb1c3248fc1955ec"
|
|
78
80
|
}
|
|
@@ -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);
|
package/readme.md
CHANGED
package/serve/serve.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {getConfigOptions} from "../bundle/getConfigs.js";
|
|
2
|
+
import servor from "servor";
|
|
3
|
+
import {relative, join} from "path";
|
|
4
|
+
|
|
5
|
+
export function serve(...options) {
|
|
6
|
+
const configs = getConfigOptions({
|
|
7
|
+
project: options.includes('-b'),
|
|
8
|
+
});
|
|
9
|
+
configs.filter(x => x.port).forEach(x => {
|
|
10
|
+
const root = relative(process.cwd(), join(x.rootDir, x.outDir));
|
|
11
|
+
console.log(`serve ${root} at localhost:${x.port}`);
|
|
12
|
+
servor({
|
|
13
|
+
root,
|
|
14
|
+
fallback: 'index.html',
|
|
15
|
+
reload: true,
|
|
16
|
+
port: x.port
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
}
|