@cmmn/tools 1.4.17 → 1.5.11
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 +18 -18
- package/bundle/bundle.js +132 -132
- package/bundle/rollup.config.js +255 -256
- package/compile/compile.js +33 -33
- package/compile/tsconfig.json +48 -48
- package/compile/typings.d.ts +19 -19
- package/gen/component.ts.tpl +16 -16
- package/gen/gen.js +27 -27
- package/gen/style.less.tpl +3 -3
- package/gen/template.ts.tpl +8 -8
- package/package.json +7 -6
- package/plugins/absolute-plugin.cjs +98 -98
- package/readme.md +30 -30
- package/test/index.d.ts +3 -2
- package/test/index.js +5 -4
- package/test/jest.config.js +45 -45
package/bin.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {bundle} from "./bundle/bundle.js";
|
|
4
|
-
import {compile} from "./compile/compile.js";
|
|
5
|
-
import {gen} from "./gen/gen.js";
|
|
6
|
-
|
|
7
|
-
const [action, ...args] = process.argv.slice(2);
|
|
8
|
-
|
|
9
|
-
const actions = {
|
|
10
|
-
bundle, compile, gen
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (action in actions) {
|
|
14
|
-
actions[action](...args);
|
|
15
|
-
} else {
|
|
16
|
-
console.log(`cmmn bundle [-b] [index.ts] [--watch] [--run] [--prod]`);
|
|
17
|
-
console.log(`cmmn compile [-b] [--watch]`);
|
|
18
|
-
console.log(`cmmn gen AppRoot . [--nested]`);
|
|
19
|
-
}
|
|
2
|
+
|
|
3
|
+
import {bundle} from "./bundle/bundle.js";
|
|
4
|
+
import {compile} from "./compile/compile.js";
|
|
5
|
+
import {gen} from "./gen/gen.js";
|
|
6
|
+
|
|
7
|
+
const [action, ...args] = process.argv.slice(2);
|
|
8
|
+
|
|
9
|
+
const actions = {
|
|
10
|
+
bundle, compile, gen
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (action in actions) {
|
|
14
|
+
actions[action](...args);
|
|
15
|
+
} else {
|
|
16
|
+
console.log(`cmmn bundle [-b] [index.ts] [--watch] [--run] [--prod]`);
|
|
17
|
+
console.log(`cmmn compile [-b] [--watch]`);
|
|
18
|
+
console.log(`cmmn gen AppRoot . [--nested]`);
|
|
19
|
+
}
|
package/bundle/bundle.js
CHANGED
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
import {ConfigCreator} from "./rollup.config.js";
|
|
2
|
-
import {rollup, watch} from "rollup";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
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
|
-
}
|
|
49
|
-
|
|
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
|
-
|
|
66
|
-
export async function bundle(...options) {
|
|
67
|
-
const configs = getConfigs({
|
|
68
|
-
input: options.filter(x => !x.startsWith('-'))[0],
|
|
69
|
-
project: options.includes('-b'),
|
|
70
|
-
minify: options.includes('--prod'),
|
|
71
|
-
devServer: options.includes('--run'),
|
|
72
|
-
stats: options.includes('--stats'),
|
|
73
|
-
});
|
|
74
|
-
if (!options.includes('--watch')) {
|
|
75
|
-
for (let config of configs) {
|
|
76
|
-
for (let key in config.input){
|
|
77
|
-
// console.log(`1. ${key} (${config.input[key]})`);
|
|
78
|
-
}
|
|
79
|
-
const build = await rollup(config);
|
|
80
|
-
for (let out of config.output){
|
|
81
|
-
console.log(`SUCCESS: ${out.dir} ${out.entryFileNames.replace('[name]', Object.keys(config.input)[0])}`);
|
|
82
|
-
await build.write(out);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const watcher = watch(configs);
|
|
88
|
-
watcher.on('event', (event) => {
|
|
89
|
-
switch (event.code) {
|
|
90
|
-
case 'START':
|
|
91
|
-
console.clear();
|
|
92
|
-
console.log('START BUNDLING');
|
|
93
|
-
break;
|
|
94
|
-
case 'END':
|
|
95
|
-
console.log(`FINISH at ${new Date().toTimeString().substring(0,8)}`);
|
|
96
|
-
break;
|
|
97
|
-
case 'BUNDLE_START':
|
|
98
|
-
for (let key in event.input){
|
|
99
|
-
console.log(`\t${key} -> ${event.output}`);
|
|
100
|
-
}
|
|
101
|
-
break;
|
|
102
|
-
case 'BUNDLE_END':
|
|
103
|
-
for (let key in event.input){
|
|
104
|
-
console.log(`\t${key} -> ${event.output}, (${event.duration / 1000}s)`);
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
|
|
108
|
-
case 'ERROR':
|
|
109
|
-
switch (event.error.code) {
|
|
110
|
-
case 'PARSE_ERROR':
|
|
111
|
-
console.warn('Error parsing files:');
|
|
112
|
-
console.log(`\t${event.error.parserError.message}`);
|
|
113
|
-
console.log(`\tat: ${event.error.id}`);
|
|
114
|
-
console.log(`\tline: ${event.error.frame}`);
|
|
115
|
-
break;
|
|
116
|
-
case 'UNRESOLVED_IMPORT':
|
|
117
|
-
console.warn('UNRESOLVED_IMPORT:\t',event.error.message);
|
|
118
|
-
break;
|
|
119
|
-
case 'MISSING_EXPORT':
|
|
120
|
-
console.warn('MISSING_EXPORT: \t', event.error.message);
|
|
121
|
-
break;
|
|
122
|
-
default:
|
|
123
|
-
console.warn('Unknown error:', event.error.code);
|
|
124
|
-
console.error(event.error);
|
|
125
|
-
break;
|
|
126
|
-
}
|
|
127
|
-
break;
|
|
128
|
-
default:
|
|
129
|
-
console.warn('WARNING:', event)
|
|
130
|
-
}
|
|
131
|
-
});
|
|
132
|
-
}
|
|
1
|
+
import {ConfigCreator} from "./rollup.config.js";
|
|
2
|
+
import {rollup, watch} from "rollup";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
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
|
+
}
|
|
49
|
+
|
|
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
|
+
|
|
66
|
+
export async function bundle(...options) {
|
|
67
|
+
const configs = getConfigs({
|
|
68
|
+
input: options.filter(x => !x.startsWith('-'))[0],
|
|
69
|
+
project: options.includes('-b'),
|
|
70
|
+
minify: options.includes('--prod'),
|
|
71
|
+
devServer: options.includes('--run'),
|
|
72
|
+
stats: options.includes('--stats'),
|
|
73
|
+
});
|
|
74
|
+
if (!options.includes('--watch')) {
|
|
75
|
+
for (let config of configs) {
|
|
76
|
+
for (let key in config.input){
|
|
77
|
+
// console.log(`1. ${key} (${config.input[key]})`);
|
|
78
|
+
}
|
|
79
|
+
const build = await rollup(config);
|
|
80
|
+
for (let out of config.output){
|
|
81
|
+
console.log(`SUCCESS: ${out.dir} ${out.entryFileNames.replace('[name]', Object.keys(config.input)[0])}`);
|
|
82
|
+
await build.write(out);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const watcher = watch(configs);
|
|
88
|
+
watcher.on('event', (event) => {
|
|
89
|
+
switch (event.code) {
|
|
90
|
+
case 'START':
|
|
91
|
+
console.clear();
|
|
92
|
+
console.log('START BUNDLING');
|
|
93
|
+
break;
|
|
94
|
+
case 'END':
|
|
95
|
+
console.log(`FINISH at ${new Date().toTimeString().substring(0,8)}`);
|
|
96
|
+
break;
|
|
97
|
+
case 'BUNDLE_START':
|
|
98
|
+
for (let key in event.input){
|
|
99
|
+
console.log(`\t${key} -> ${event.output}`);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case 'BUNDLE_END':
|
|
103
|
+
for (let key in event.input){
|
|
104
|
+
console.log(`\t${key} -> ${event.output}, (${event.duration / 1000}s)`);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case 'ERROR':
|
|
109
|
+
switch (event.error.code) {
|
|
110
|
+
case 'PARSE_ERROR':
|
|
111
|
+
console.warn('Error parsing files:');
|
|
112
|
+
console.log(`\t${event.error.parserError.message}`);
|
|
113
|
+
console.log(`\tat: ${event.error.id}`);
|
|
114
|
+
console.log(`\tline: ${event.error.frame}`);
|
|
115
|
+
break;
|
|
116
|
+
case 'UNRESOLVED_IMPORT':
|
|
117
|
+
console.warn('UNRESOLVED_IMPORT:\t',event.error.message);
|
|
118
|
+
break;
|
|
119
|
+
case 'MISSING_EXPORT':
|
|
120
|
+
console.warn('MISSING_EXPORT: \t', event.error.message);
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
console.warn('Unknown error:', event.error.code);
|
|
124
|
+
console.error(event.error);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
default:
|
|
129
|
+
console.warn('WARNING:', event)
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
}
|