@cmmn/tools 1.6.7 → 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 +11 -11
- package/compile/tsconfig.json +5 -0
- package/package.json +3 -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
|
@@ -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() {
|
|
@@ -107,7 +110,7 @@ export class ConfigCreator {
|
|
|
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,
|
|
@@ -214,12 +217,6 @@ export class ConfigCreator {
|
|
|
214
217
|
* @returns {RollupOptions[]}
|
|
215
218
|
*/
|
|
216
219
|
getConfig() {
|
|
217
|
-
Object.assign(this.options, {
|
|
218
|
-
module: this.options.module || 'es',
|
|
219
|
-
external: this.options.external || [],
|
|
220
|
-
name: this.options.name || 'index',
|
|
221
|
-
outDir: this.options.outDir || 'dist'
|
|
222
|
-
});
|
|
223
220
|
if (this.options.external && typeof this.options.external === "string")
|
|
224
221
|
this.options.external = [this.options.external]
|
|
225
222
|
console.log(this.options.name, this.options);
|
|
@@ -248,6 +245,9 @@ export class ConfigCreator {
|
|
|
248
245
|
},
|
|
249
246
|
plugins: this.plugins,
|
|
250
247
|
treeshake: this.options.minify ? "smallest" : "recommended",
|
|
248
|
+
watch: {
|
|
249
|
+
exclude: this.getExternals().concat(path.join(this.root, this.outDir)),
|
|
250
|
+
}
|
|
251
251
|
}]
|
|
252
252
|
}
|
|
253
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",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"rollup-plugin-styles": "^4",
|
|
67
67
|
"rollup-plugin-terser": "^7",
|
|
68
68
|
"rollup-plugin-visualizer": "^5.5.4",
|
|
69
|
+
"servor": "4.x.x",
|
|
69
70
|
"sinon": "10.x.x",
|
|
70
71
|
"ts-jest": "27.x.x",
|
|
71
72
|
"ttypescript": "1.5.13",
|
|
@@ -74,5 +75,5 @@
|
|
|
74
75
|
},
|
|
75
76
|
"author": "",
|
|
76
77
|
"license": "ISC",
|
|
77
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "f4e9729796c27c9c9f42b30082b44e8afa6d62c4"
|
|
78
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);
|