@cmmn/tools 2.2.3 → 3.0.0-alpha-1
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/.swcrc +20 -0
- package/dist/esm/bin.js +9 -0
- package/dist/esm/bin.js.map +1 -0
- package/dist/esm/bundlers/createBundler.js +9 -0
- package/dist/esm/bundlers/createBundler.js.map +1 -0
- package/dist/esm/bundlers/plugins/minify.js +34 -0
- package/dist/esm/bundlers/plugins/minify.js.map +1 -0
- package/dist/esm/bundlers/plugins/wasm.js +43 -0
- package/dist/esm/bundlers/plugins/wasm.js.map +1 -0
- package/dist/esm/bundlers/rolldown-bundler.js +153 -0
- package/dist/esm/bundlers/rolldown-bundler.js.map +1 -0
- package/dist/esm/bundlers/types.js +3 -0
- package/dist/esm/bundlers/types.js.map +1 -0
- package/dist/esm/bundlers/vite.builder.js +117 -0
- package/dist/esm/bundlers/vite.builder.js.map +1 -0
- package/dist/esm/bundlers/vite.bundler.js +56 -0
- package/dist/esm/bundlers/vite.bundler.js.map +1 -0
- package/dist/esm/commands/bundle.js +100 -0
- package/dist/esm/commands/bundle.js.map +1 -0
- package/dist/esm/commands/cert.js +26 -0
- package/dist/esm/commands/cert.js.map +1 -0
- package/dist/esm/commands/ci.js +14 -0
- package/dist/esm/commands/ci.js.map +1 -0
- package/dist/esm/commands/clean.js +18 -0
- package/dist/esm/commands/clean.js.map +1 -0
- package/dist/esm/commands/compile.js +60 -0
- package/dist/esm/commands/compile.js.map +1 -0
- package/dist/esm/commands/deploy.js +61 -0
- package/dist/esm/commands/deploy.js.map +1 -0
- package/dist/esm/commands/dev.js +36 -0
- package/dist/esm/commands/dev.js.map +1 -0
- package/dist/esm/commands/format.js +44 -0
- package/dist/esm/commands/format.js.map +1 -0
- package/dist/esm/commands/gen.js +36 -0
- package/dist/esm/commands/gen.js.map +1 -0
- package/dist/esm/commands/host.js +21 -0
- package/dist/esm/commands/host.js.map +1 -0
- package/dist/esm/commands/index.js +12 -0
- package/dist/esm/commands/index.js.map +1 -0
- package/dist/esm/commands/lint.js +45 -0
- package/dist/esm/commands/lint.js.map +1 -0
- package/dist/esm/commands/nginx.js +62 -0
- package/dist/esm/commands/nginx.js.map +1 -0
- package/dist/esm/commands/publish.js +37 -0
- package/dist/esm/commands/publish.js.map +1 -0
- package/dist/esm/commands/typings.js +66 -0
- package/dist/esm/commands/typings.js.map +1 -0
- package/dist/esm/commands/version.js +34 -0
- package/dist/esm/commands/version.js.map +1 -0
- package/dist/esm/dev-server/asset-collection.js +18 -0
- package/dist/esm/dev-server/asset-collection.js.map +1 -0
- package/dist/esm/dev-server/bundle.json.builder.js +47 -0
- package/dist/esm/dev-server/bundle.json.builder.js.map +1 -0
- package/dist/esm/dev-server/dependencyServer.js +96 -0
- package/dist/esm/dev-server/dependencyServer.js.map +1 -0
- package/dist/esm/dev-server/dev-server.js +49 -0
- package/dist/esm/dev-server/dev-server.js.map +1 -0
- package/dist/esm/dev-server/plugins/minify.js +34 -0
- package/dist/esm/dev-server/plugins/minify.js.map +1 -0
- package/dist/esm/dev-server/plugins/wasm.js +30 -0
- package/dist/esm/dev-server/plugins/wasm.js.map +1 -0
- package/dist/esm/dev-server/resolver.js +55 -0
- package/dist/esm/dev-server/resolver.js.map +1 -0
- package/dist/esm/dev-server/rolldown-dependency-builder.js +150 -0
- package/dist/esm/dev-server/rolldown-dependency-builder.js.map +1 -0
- package/dist/esm/dev-server/target-runnner.js +72 -0
- package/dist/esm/dev-server/target-runnner.js.map +1 -0
- package/dist/esm/dev-server/target-web-server.js +78 -0
- package/dist/esm/dev-server/target-web-server.js.map +1 -0
- package/dist/esm/dev-server/targetServer.js +29 -0
- package/dist/esm/dev-server/targetServer.js.map +1 -0
- package/dist/esm/dev-server/vite.builder.js +183 -0
- package/dist/esm/dev-server/vite.builder.js.map +1 -0
- package/dist/esm/dev-server/wasm-resolver.js +25 -0
- package/dist/esm/dev-server/wasm-resolver.js.map +1 -0
- package/dist/esm/helpers/fastify-compress.js +26 -0
- package/dist/esm/helpers/fastify-compress.js.map +1 -0
- package/dist/esm/helpers/flags.js +22 -0
- package/dist/esm/helpers/flags.js.map +1 -0
- package/dist/esm/helpers/getProjects.js +49 -0
- package/dist/esm/helpers/getProjects.js.map +1 -0
- package/dist/esm/helpers/getTSConfig.js +32 -0
- package/dist/esm/helpers/getTSConfig.js.map +1 -0
- package/dist/esm/helpers/target.js +230 -0
- package/dist/esm/helpers/target.js.map +1 -0
- package/dist/esm/helpers/terminal.js +117 -0
- package/dist/esm/helpers/terminal.js.map +1 -0
- package/dist/esm/helpers/ts-resolve-plugin.js +139 -0
- package/dist/esm/helpers/ts-resolve-plugin.js.map +1 -0
- package/dist/esm/helpers/watcher.js +35 -0
- package/dist/esm/helpers/watcher.js.map +1 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/model/bundle.js +75 -0
- package/dist/esm/model/bundle.js.map +1 -0
- package/dist/esm/model/flags.js +27 -0
- package/dist/esm/model/flags.js.map +1 -0
- package/dist/esm/model/monorepo.js +74 -0
- package/dist/esm/model/monorepo.js.map +1 -0
- package/dist/esm/model/pack.js +131 -0
- package/dist/esm/model/pack.js.map +1 -0
- package/dist/esm/model/resolver.js +100 -0
- package/dist/esm/model/resolver.js.map +1 -0
- package/dist/esm/model/target.js +111 -0
- package/dist/esm/model/target.js.map +1 -0
- package/dist/esm/servers/bundle-server.js +20 -0
- package/dist/esm/servers/bundle-server.js.map +1 -0
- package/dist/esm/servers/dev-server.js +70 -0
- package/dist/esm/servers/dev-server.js.map +1 -0
- package/dist/esm/servers/pack-server.js +20 -0
- package/dist/esm/servers/pack-server.js.map +1 -0
- package/dist/esm/servers/target-runnner.js +80 -0
- package/dist/esm/servers/target-runnner.js.map +1 -0
- package/dist/esm/servers/vite-dev-server.js +61 -0
- package/dist/esm/servers/vite-dev-server.js.map +1 -0
- package/dist/esm/specs/dependency-builder-specs.js +164 -0
- package/dist/esm/specs/dependency-builder-specs.js.map +1 -0
- package/dist/esm/specs/dev-server.specs.js +73 -0
- package/dist/esm/specs/dev-server.specs.js.map +1 -0
- package/dist/esm/specs/monorepo.specs.js +35 -0
- package/dist/esm/specs/monorepo.specs.js.map +1 -0
- package/dist/esm/specs/resolver.specs.js +57 -0
- package/dist/esm/specs/resolver.specs.js.map +1 -0
- package/dist/esm/specs/rolldown.specs.js +278 -0
- package/dist/esm/specs/rolldown.specs.js.map +1 -0
- package/dist/esm/specs/target-specs.js +108 -0
- package/dist/esm/specs/target-specs.js.map +1 -0
- package/dist/esm/specs/vite-bundler.specs.js +75 -0
- package/dist/esm/specs/vite-bundler.specs.js.map +1 -0
- package/dist/esm/test/test.js +30 -0
- package/dist/esm/test/test.js.map +1 -0
- package/dist/ts.buildinfo +1 -0
- package/dist/typings/bin.d.ts +2 -0
- package/dist/typings/bundlers/plugins/minify.d.ts +6 -0
- package/dist/typings/bundlers/plugins/wasm.d.ts +5 -0
- package/dist/typings/bundlers/rolldown-bundler.d.ts +18 -0
- package/dist/typings/bundlers/types.d.ts +4 -0
- package/dist/typings/bundlers/vite.builder.d.ts +12 -0
- package/dist/typings/bundlers/vite.bundler.d.ts +9 -0
- package/dist/typings/commands/bundle.d.ts +2 -0
- package/dist/typings/commands/cert.d.ts +1 -0
- package/dist/typings/commands/clean.d.ts +2 -0
- package/dist/typings/commands/compile.d.ts +2 -0
- package/dist/typings/commands/dev.d.ts +2 -0
- package/dist/typings/commands/format.d.ts +5 -0
- package/dist/typings/commands/gen.d.ts +1 -0
- package/dist/typings/commands/host.d.ts +1 -0
- package/dist/typings/commands/index.d.ts +10 -0
- package/dist/typings/commands/lint.d.ts +5 -0
- package/dist/typings/commands/nginx.d.ts +6 -0
- package/dist/typings/commands/publish.d.ts +2 -0
- package/dist/typings/commands/typings.d.ts +4 -0
- package/dist/typings/commands/version.d.ts +1 -0
- package/dist/typings/helpers/fastify-compress.d.ts +6 -0
- package/dist/typings/helpers/getTSConfig.d.ts +11 -0
- package/dist/typings/helpers/terminal.d.ts +22 -0
- package/dist/typings/helpers/watcher.d.ts +7 -0
- package/dist/typings/index.d.ts +4 -0
- package/dist/typings/model/bundle.d.ts +34 -0
- package/dist/typings/model/flags.d.ts +15 -0
- package/dist/typings/model/monorepo.d.ts +18 -0
- package/dist/typings/model/pack.d.ts +45 -0
- package/dist/typings/model/resolver.d.ts +38 -0
- package/dist/typings/model/target.d.ts +27 -0
- package/dist/typings/servers/bundle-server.d.ts +10 -0
- package/dist/typings/servers/dev-server.d.ts +16 -0
- package/dist/typings/servers/pack-server.d.ts +9 -0
- package/dist/typings/servers/target-runnner.d.ts +13 -0
- package/dist/typings/servers/vite-dev-server.d.ts +18 -0
- package/dist/typings/specs/dev-server.specs.d.ts +1 -0
- package/dist/typings/specs/monorepo.specs.d.ts +1 -0
- package/dist/typings/specs/resolver.specs.d.ts +1 -0
- package/dist/typings/specs/rolldown.specs.d.ts +1 -0
- package/dist/typings/specs/target-specs.d.ts +1 -0
- package/dist/typings/specs/vite-bundler.specs.d.ts +1 -0
- package/dist/typings/test/test.d.ts +16 -0
- package/{compile → helpers}/tsconfig.json +12 -9
- package/node/hooks-dev.js +72 -0
- package/node/register-dev.js +3 -0
- package/node/register.js +14 -0
- package/package.json +50 -40
- package/readme.md +2 -2
- package/tsconfig.json +14 -0
- package/LICENSE +0 -21
- package/bin.js +0 -21
- package/bundle/bundle.js +0 -46
- package/bundle/esbuild.config.js +0 -178
- package/bundle/getConfigs.js +0 -62
- package/compile/compile.js +0 -53
- package/compile/ts-resolve-plugin.js +0 -235
- package/compile/typings.d.ts +0 -19
- package/gen/component.ts.tpl +0 -16
- package/gen/gen.js +0 -27
- package/gen/style.less.tpl +0 -3
- package/gen/template.ts.tpl +0 -8
- package/helpers/getTSConfig.js +0 -19
- package/serve/readme.md +0 -8
- package/serve/serve.js +0 -109
- package/spawn/index.js +0 -81
- package/test/index.d.ts +0 -18
- package/test/index.js +0 -16
- package/test/jest.config.js +0 -32
- package/test/pathsToModuleNameMapper.js +0 -46
package/tsconfig.json
ADDED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Andrey
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/bin.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import {bundle} from "./bundle/bundle.js";
|
|
4
|
-
import {serve} from "./serve/serve.js";
|
|
5
|
-
import {compile} from "./compile/compile.js";
|
|
6
|
-
import {gen} from "./gen/gen.js";
|
|
7
|
-
import {spawn} from "./spawn/index.js";
|
|
8
|
-
|
|
9
|
-
const [action, ...args] = process.argv.slice(2);
|
|
10
|
-
|
|
11
|
-
const actions = {
|
|
12
|
-
bundle, compile, gen, serve, spawn
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
if (action in actions) {
|
|
16
|
-
actions[action](...args);
|
|
17
|
-
} else {
|
|
18
|
-
console.log(`cmmn bundle [-b] [index.ts] [--watch] [--run] [--prod]`);
|
|
19
|
-
console.log(`cmmn compile [-b] [--watch]`);
|
|
20
|
-
console.log(`cmmn gen AppRoot . [--nested]`);
|
|
21
|
-
}
|
package/bundle/bundle.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import esbuild from "esbuild";
|
|
2
|
-
import {getConfigOptions} from "./getConfigs.js";
|
|
3
|
-
import {ConfigCreator} from "./esbuild.config.js";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
import path, {relative} from "path";
|
|
6
|
-
|
|
7
|
-
export async function bundle(...options) {
|
|
8
|
-
const configOptions = await getConfigOptions({
|
|
9
|
-
minify: options.includes('--minify'),
|
|
10
|
-
prod: options.includes('--prod'),
|
|
11
|
-
stats: options.includes('--stats'),
|
|
12
|
-
noSideEffects: options.includes('--no-side-effects')
|
|
13
|
-
});
|
|
14
|
-
const configs = configOptions.flatMap(x => new ConfigCreator(x).getConfig());
|
|
15
|
-
const contexts = [];
|
|
16
|
-
for (let config of configs){
|
|
17
|
-
contexts.push([config, await esbuild.context(config)]);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (options.includes('--watch')) {
|
|
21
|
-
for (let [config, context] of contexts) {
|
|
22
|
-
await context.watch();
|
|
23
|
-
}
|
|
24
|
-
console.log('bundled. Continue watching...');
|
|
25
|
-
}else {
|
|
26
|
-
const logs = [];
|
|
27
|
-
for (let [config, context] of contexts) {
|
|
28
|
-
const project = path.relative(process.cwd(), config.absWorkingDir);
|
|
29
|
-
const result = await context.rebuild().catch(err => {
|
|
30
|
-
err.message = project + ": " + err.message;
|
|
31
|
-
throw err;
|
|
32
|
-
});
|
|
33
|
-
const name = config.entryPoints[0].out;
|
|
34
|
-
let log = logs.find(x => x.project === project && x.name === name);
|
|
35
|
-
if (!log){
|
|
36
|
-
logs.push(log = {project, name});
|
|
37
|
-
}
|
|
38
|
-
for (let [name, value] of Object.entries(result.metafile.outputs)) {
|
|
39
|
-
if (!name.endsWith('js')) continue;
|
|
40
|
-
log[config.format+"."+config.platform] = `${(value.bytes/(2**10)).toFixed(1)} Kb`;
|
|
41
|
-
}
|
|
42
|
-
await context.dispose();
|
|
43
|
-
}
|
|
44
|
-
console.table(logs);
|
|
45
|
-
}
|
|
46
|
-
}
|
package/bundle/esbuild.config.js
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import { lessLoader } from 'esbuild-plugin-less';
|
|
4
|
-
import {platform} from "os";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {import(rollup).RollupOptions} RollupOptions
|
|
8
|
-
* @typedef {import(rollup).OutputOptions} OutputOptions
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
export class ConfigCreator {
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @type {{
|
|
15
|
-
* minify: boolean,
|
|
16
|
-
* input: string,
|
|
17
|
-
* devServer: boolean,
|
|
18
|
-
* module: string,
|
|
19
|
-
* external: string[],
|
|
20
|
-
* stats: boolean,
|
|
21
|
-
* name: string,
|
|
22
|
-
* styles: 'modules' | null,
|
|
23
|
-
* outDir: string,
|
|
24
|
-
* html: string,
|
|
25
|
-
* browser: boolean,
|
|
26
|
-
* platform: string,
|
|
27
|
-
* dedupe: string[],
|
|
28
|
-
* target: string
|
|
29
|
-
* prod: boolean,
|
|
30
|
-
* inject: string
|
|
31
|
-
* noSideEffects: boolean
|
|
32
|
-
* }}
|
|
33
|
-
*/
|
|
34
|
-
options;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
|
-
root = process.cwd();
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
constructor(options) {
|
|
43
|
-
this.options = {
|
|
44
|
-
module: 'es',
|
|
45
|
-
external: [],
|
|
46
|
-
name: 'index',
|
|
47
|
-
outDir: 'dist/bundle',
|
|
48
|
-
platform: 'node,browser',
|
|
49
|
-
...options
|
|
50
|
-
};
|
|
51
|
-
if (options.rootDir)
|
|
52
|
-
this.root = options.rootDir;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
get outDir() {
|
|
56
|
-
return path.join(this.root, this.options.outDir);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
get importMaps(){
|
|
60
|
-
return JSON.stringify({
|
|
61
|
-
imports: Object.fromEntries(this.options.external
|
|
62
|
-
.map(key => key.replace('*', '/'))
|
|
63
|
-
.map(key => [key, `/node_modules/${this.options.alias?.[key] ?? key}`]))
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
getHtmlPlugin(){
|
|
67
|
-
if (!this.options.html)
|
|
68
|
-
return [];
|
|
69
|
-
return [
|
|
70
|
-
{
|
|
71
|
-
name: 'esbuild-html-plugin',
|
|
72
|
-
setup: (build) => { build.onEnd(async result => {
|
|
73
|
-
if (!result.metafile)
|
|
74
|
-
return;
|
|
75
|
-
const injectStyles = [];
|
|
76
|
-
const injectScripts = [
|
|
77
|
-
`<script type="importmap">${this.importMaps}</script>`
|
|
78
|
-
];
|
|
79
|
-
for (let [key, value] of Object.entries(result.metafile.outputs)){
|
|
80
|
-
if (value.entryPoint !== this.options.input) continue;
|
|
81
|
-
const file = path.relative(this.outDir, path.join(this.root, key));
|
|
82
|
-
injectScripts.push(`<script type="module" src="/${file}"></script>`)
|
|
83
|
-
if (value.cssBundle) {
|
|
84
|
-
const file = path.relative(this.outDir, path.join(this.root, value.cssBundle));
|
|
85
|
-
injectStyles.push(`<link rel="stylesheet" href="/${file}"></link>`)
|
|
86
|
-
}
|
|
87
|
-
const html = await fs.promises.readFile(path.join(this.root, this.options.html));
|
|
88
|
-
await fs.promises.writeFile(
|
|
89
|
-
path.join(this.outDir, 'index.html'),
|
|
90
|
-
html.toString()
|
|
91
|
-
.replace('</head>', `${injectStyles.map(x => `\t${x}\n`).join('')}</head>`)
|
|
92
|
-
.replace('</body>', `${injectScripts.map(x => `\t${x}\n`).join('')}</body>`)
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
}); }
|
|
96
|
-
}
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get platforms(){
|
|
102
|
-
return this.options.platform.split(',');
|
|
103
|
-
}
|
|
104
|
-
get modules(){
|
|
105
|
-
return this.options.module.split(',');
|
|
106
|
-
}
|
|
107
|
-
getOutExtension(format, platform){
|
|
108
|
-
const ext = (this.options.minify ? '.min' : '') + ({
|
|
109
|
-
es: '.js',
|
|
110
|
-
cjs: '.cjs'
|
|
111
|
-
}[format] ?? '.js');
|
|
112
|
-
if (this.platforms.length == 1)
|
|
113
|
-
return ext;
|
|
114
|
-
return "."+platform+ext;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* @returns {RollupOptions[]}
|
|
118
|
-
*/
|
|
119
|
-
getConfig() {
|
|
120
|
-
if (this.options.external && typeof this.options.external === "string")
|
|
121
|
-
this.options.external = [this.options.external]
|
|
122
|
-
// console.log(this.options.name, this.options);
|
|
123
|
-
return this.modules.flatMap(format => this.platforms.map(platform => ({
|
|
124
|
-
entryPoints: [
|
|
125
|
-
{ out: this.options.name, in: this.options.input }
|
|
126
|
-
],
|
|
127
|
-
bundle: true,
|
|
128
|
-
minify: this.options.minify,
|
|
129
|
-
sourcemap: this.options.prod ? false : 'external',
|
|
130
|
-
target: ['chrome88', 'safari14', 'firefox88'],
|
|
131
|
-
outdir: 'dist/bundle',
|
|
132
|
-
metafile: true,
|
|
133
|
-
absWorkingDir: this.root,
|
|
134
|
-
treeShaking: this.options.prod,
|
|
135
|
-
format: ({
|
|
136
|
-
es: 'esm'
|
|
137
|
-
})[format] ?? format,
|
|
138
|
-
outExtension: {
|
|
139
|
-
'.js': this.getOutExtension(format, platform),
|
|
140
|
-
'.css': this.options.minify ? '.min.css' : '.css'
|
|
141
|
-
},
|
|
142
|
-
footer:{
|
|
143
|
-
js: `//# sourceMappingURL=./${this.options.name+this.getOutExtension(format, platform)}.map`
|
|
144
|
-
},
|
|
145
|
-
platform: platform,
|
|
146
|
-
tsconfig: 'tsconfig.json',
|
|
147
|
-
external: [
|
|
148
|
-
"*.woff2", "*.woff",
|
|
149
|
-
...(platform !== "node" && this.options.minify ? [] : this.options.external)
|
|
150
|
-
],
|
|
151
|
-
define: {
|
|
152
|
-
'process.env.NODE_ENV': '"production"',
|
|
153
|
-
PRODUCTION: this.options.prod ? "true": "false"
|
|
154
|
-
},
|
|
155
|
-
publicPath: '/',
|
|
156
|
-
alias: this.options.alias,
|
|
157
|
-
plugins: [
|
|
158
|
-
lessLoader(),
|
|
159
|
-
...this.getHtmlPlugin(),
|
|
160
|
-
...(this.options.noSideEffects ? [{
|
|
161
|
-
name: 'no-side-effects',
|
|
162
|
-
setup(build){
|
|
163
|
-
build.onResolve({ filter: /.*/ }, async args => {
|
|
164
|
-
if (args.pluginData) return // Ignore this if we called ourselves
|
|
165
|
-
|
|
166
|
-
const { path, ...rest } = args
|
|
167
|
-
rest.pluginData = true // Avoid infinite recursion
|
|
168
|
-
const result = await build.resolve(path, rest)
|
|
169
|
-
|
|
170
|
-
result.sideEffects = false
|
|
171
|
-
return result
|
|
172
|
-
})
|
|
173
|
-
}
|
|
174
|
-
}] : [])
|
|
175
|
-
],
|
|
176
|
-
})));
|
|
177
|
-
}
|
|
178
|
-
}
|
package/bundle/getConfigs.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import {getTSConfig} from "../helpers/getTSConfig.js";
|
|
4
|
-
|
|
5
|
-
function getProjectConfig(rootDir, cmmn, options) {
|
|
6
|
-
return {
|
|
7
|
-
...options,
|
|
8
|
-
...cmmn,
|
|
9
|
-
rootDir: rootDir
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async function *getDependencyOrder(rootDir, visited = []) {
|
|
14
|
-
const tsConfig = getTSConfig(rootDir)
|
|
15
|
-
for (let reference of tsConfig.references ?? []){
|
|
16
|
-
const refRoot = path.resolve(rootDir, reference.path);
|
|
17
|
-
if (visited.includes(refRoot))
|
|
18
|
-
continue;
|
|
19
|
-
visited.push(refRoot)
|
|
20
|
-
for await (let dep of await getDependencyOrder(refRoot, visited)){
|
|
21
|
-
yield dep;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
yield rootDir;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
async function getPackageConfigs(rootDir, options, name = null, visited = []) {
|
|
29
|
-
const pckPath = path.join(rootDir, 'package.json');
|
|
30
|
-
if (!fs.existsSync(pckPath))
|
|
31
|
-
return [];
|
|
32
|
-
const results = [];
|
|
33
|
-
const pkg = JSON.parse(await fs.promises.readFile(pckPath));
|
|
34
|
-
if (pkg.cmmn) {
|
|
35
|
-
if (name) {
|
|
36
|
-
results.push(getProjectConfig(rootDir, pkg.cmmn[name], {
|
|
37
|
-
...options,
|
|
38
|
-
name,
|
|
39
|
-
package: pkg.name,
|
|
40
|
-
}));
|
|
41
|
-
} else {
|
|
42
|
-
for (let name in pkg.cmmn) {
|
|
43
|
-
results.push(getProjectConfig(rootDir, pkg.cmmn[name], {
|
|
44
|
-
...options,
|
|
45
|
-
name,
|
|
46
|
-
package: pkg.name,
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return results;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
export async function getConfigOptions(options) {
|
|
56
|
-
const result = []
|
|
57
|
-
for await (let project of getDependencyOrder(process.cwd())){
|
|
58
|
-
const configs = await getPackageConfigs(project, options);
|
|
59
|
-
result.push(...configs);
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
}
|
package/compile/compile.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import {resolve, relative} from 'node:path';
|
|
3
|
-
import fs from "node:fs";
|
|
4
|
-
import { tsResolvePlugin } from "./ts-resolve-plugin.js";
|
|
5
|
-
|
|
6
|
-
const rootDir = process.cwd();
|
|
7
|
-
|
|
8
|
-
export function compile(...flags) {
|
|
9
|
-
|
|
10
|
-
const host = ts.createSolutionBuilderWithWatchHost(ts.sys, createProgram);
|
|
11
|
-
host.getCustomTransformers = (pkg) => ({
|
|
12
|
-
before: [
|
|
13
|
-
tsResolvePlugin
|
|
14
|
-
],
|
|
15
|
-
afterDeclarations: [
|
|
16
|
-
tsResolvePlugin
|
|
17
|
-
]
|
|
18
|
-
});
|
|
19
|
-
host.useCaseSensitiveFileNames();
|
|
20
|
-
|
|
21
|
-
const builderFactory = flags.includes('--watch') ?
|
|
22
|
-
ts.createSolutionBuilderWithWatch :
|
|
23
|
-
ts.createSolutionBuilder;
|
|
24
|
-
|
|
25
|
-
const builder = builderFactory(host, [rootDir], {
|
|
26
|
-
incremental: true,
|
|
27
|
-
dry: false,
|
|
28
|
-
assumeChangesOnlyAffectDirectDependencies: true
|
|
29
|
-
}, {
|
|
30
|
-
excludeDirectories: ["node_modules", "dist"],
|
|
31
|
-
});
|
|
32
|
-
builder.clean(rootDir);
|
|
33
|
-
builder.build(rootDir);
|
|
34
|
-
}
|
|
35
|
-
const cleanedBaseDirs = new Set();
|
|
36
|
-
function createProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences) {
|
|
37
|
-
options.outDir = resolve(options.configFilePath, '../dist/esm');
|
|
38
|
-
options.declarationDir = resolve(options.configFilePath, '../dist/typings');
|
|
39
|
-
options.baseUrl = resolve(options.configFilePath, '../');
|
|
40
|
-
options.tsBuildInfoFile = resolve(options.configFilePath, '../dist/ts.buildinfo');
|
|
41
|
-
// options.excludeDirectories.baseUrl = options.baseUrl;
|
|
42
|
-
// options.includeDirectories.baseUrl = options.baseUrl;
|
|
43
|
-
if (!cleanedBaseDirs.has(options.baseUrl)){
|
|
44
|
-
fs.rmSync(options.outDir, {recursive: true, force: true});
|
|
45
|
-
fs.rmSync(options.declarationDir, {recursive: true, force: true});
|
|
46
|
-
fs.rmSync(options.tsBuildInfoFile, {force: true});
|
|
47
|
-
cleanedBaseDirs.add(options.baseUrl);
|
|
48
|
-
}
|
|
49
|
-
console.log('\t', relative(process.cwd(), options.baseUrl));
|
|
50
|
-
return ts.createEmitAndSemanticDiagnosticsBuilderProgram(
|
|
51
|
-
rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences
|
|
52
|
-
)
|
|
53
|
-
}
|
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import { ImportPathsResolver } from '@zerollup/ts-helpers'
|
|
5
|
-
|
|
6
|
-
class Visitor {
|
|
7
|
-
/**
|
|
8
|
-
* @type {ImportPathsResolver}
|
|
9
|
-
*/
|
|
10
|
-
resolver;
|
|
11
|
-
/**
|
|
12
|
-
* @type {ts.TransformationContext}
|
|
13
|
-
*/
|
|
14
|
-
context;
|
|
15
|
-
/**
|
|
16
|
-
* @type {ts.CompilerOptions}
|
|
17
|
-
*/
|
|
18
|
-
options;
|
|
19
|
-
/**
|
|
20
|
-
* @type {{
|
|
21
|
-
* copy: RegExp;
|
|
22
|
-
* import: RegExp;
|
|
23
|
-
* }}
|
|
24
|
-
*/
|
|
25
|
-
config;
|
|
26
|
-
/**
|
|
27
|
-
*
|
|
28
|
-
* @param context {ts.TransformationContext}
|
|
29
|
-
*/
|
|
30
|
-
constructor(context, config) {
|
|
31
|
-
this.context = context;
|
|
32
|
-
this.options = context.getCompilerOptions();
|
|
33
|
-
this.resolver = new ImportPathsResolver({
|
|
34
|
-
paths: this.options.paths,
|
|
35
|
-
baseUrl: this.options.baseUrl,
|
|
36
|
-
exclude: []
|
|
37
|
-
});
|
|
38
|
-
this.config = {
|
|
39
|
-
copy: /\.(less|css|scss|sass|png|jpg|ico)$/,
|
|
40
|
-
import: /\.(txt|sql|svg|html)$/,
|
|
41
|
-
...config
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
findFile(importPath, sourceFile) {
|
|
45
|
-
const sourceFileDir = path.dirname(sourceFile.fileName);
|
|
46
|
-
|
|
47
|
-
return [
|
|
48
|
-
importPath,
|
|
49
|
-
importPath + "/index.ts",
|
|
50
|
-
importPath + ".ts",
|
|
51
|
-
importPath + ".tsx",
|
|
52
|
-
importPath + "/index.js",
|
|
53
|
-
importPath + ".js",
|
|
54
|
-
importPath + ".jsx",
|
|
55
|
-
importPath.replace(/\.js$/, ".ts")
|
|
56
|
-
].find(x => fs.existsSync(path.resolve(sourceFileDir, x)))?.replace(/(\.ts)x?$/, '.js');
|
|
57
|
-
}
|
|
58
|
-
resolveFile(importPath, sourceFile){
|
|
59
|
-
const sourceFileDir = path.dirname(sourceFile.fileName);
|
|
60
|
-
const existed = this.findFile(importPath, sourceFile);
|
|
61
|
-
if (existed) return existed;
|
|
62
|
-
const suggestions = this.resolver.getImportSuggestions(importPath, sourceFileDir) ?? [];
|
|
63
|
-
for (let suggestion of suggestions) {
|
|
64
|
-
const existed = this.findFile(suggestion, sourceFile)
|
|
65
|
-
if (existed) return existed;
|
|
66
|
-
}
|
|
67
|
-
return importPath;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @param importPath {string}
|
|
71
|
-
* @param sourceFile {ts.SourceFile}
|
|
72
|
-
*/
|
|
73
|
-
resolve(importPath, sourceFile){
|
|
74
|
-
importPath = this.resolveFile(importPath, sourceFile);
|
|
75
|
-
const sourceFileDir = path.dirname(sourceFile.fileName);
|
|
76
|
-
const absSource = path.join(this.options.outDir, path.relative(this.options.baseUrl, sourceFileDir));
|
|
77
|
-
const abs = path.resolve(sourceFileDir, importPath);
|
|
78
|
-
if (this.config.import.test(importPath)) {
|
|
79
|
-
const content = fs.readFileSync(path.resolve(sourceFileDir, importPath), 'utf-8');
|
|
80
|
-
const outFile = path.resolve(absSource, importPath).replaceAll(path.sep, '/') + '.js';
|
|
81
|
-
fs.mkdirSync(path.dirname(outFile), {recursive: true});
|
|
82
|
-
fs.writeFileSync(outFile, 'export default `'+content.replaceAll('`','\\`')+'`', 'utf-8');
|
|
83
|
-
return importPath.replaceAll(path.sep, '/') + ".js";
|
|
84
|
-
}
|
|
85
|
-
if (this.config.copy.test(importPath)) {
|
|
86
|
-
return path.relative(absSource,abs).replaceAll(path.sep, '/');
|
|
87
|
-
}
|
|
88
|
-
return importPath.replaceAll(path.sep, '/');
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
visitSourceFile = sourceFile => ts.visitEachChild(sourceFile, node => this.visit(node,sourceFile), this.context);
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* @param node {ts.Node}
|
|
95
|
-
* @param sourceFile {ts.SourceFile}
|
|
96
|
-
*/
|
|
97
|
-
visit(node,sourceFile){
|
|
98
|
-
// if (node && node.kind == SyntaxKind.ImportDeclaration) {
|
|
99
|
-
// return visitImportNode(node as ts.ImportDeclaration);
|
|
100
|
-
// }
|
|
101
|
-
if (!node)
|
|
102
|
-
return ts.visitEachChild(node, this.visit, this.context);
|
|
103
|
-
if (ts.isCallExpression(node)) {
|
|
104
|
-
const result = this.visitRequireNode(node, sourceFile);
|
|
105
|
-
if (result)
|
|
106
|
-
return result;
|
|
107
|
-
}
|
|
108
|
-
if (ts.isImportDeclaration(node)) {
|
|
109
|
-
const result = this.visitImportNode(node, sourceFile);
|
|
110
|
-
if (result)
|
|
111
|
-
return result;
|
|
112
|
-
}
|
|
113
|
-
if (ts.isExportDeclaration(node)) {
|
|
114
|
-
const result = this.visitExportNode(node, sourceFile);
|
|
115
|
-
if (result)
|
|
116
|
-
return result;
|
|
117
|
-
}
|
|
118
|
-
return ts.visitEachChild(node, node => this.visit(node, sourceFile), this.context);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @param exportNode {ts.ExportDeclaration}
|
|
124
|
-
* @param sourceFile {ts.SourceFile}
|
|
125
|
-
*/
|
|
126
|
-
visitExportNode(exportNode, sourceFile) {
|
|
127
|
-
if (exportNode.typeOnly){
|
|
128
|
-
console.log('type olnly')
|
|
129
|
-
return ;
|
|
130
|
-
}
|
|
131
|
-
const file = exportNode.moduleSpecifier?.text ?? exportNode.text;
|
|
132
|
-
if (!file)
|
|
133
|
-
return;
|
|
134
|
-
|
|
135
|
-
const resolved = this.resolve(file, sourceFile);
|
|
136
|
-
|
|
137
|
-
const newNode = this.context.factory.updateExportDeclaration(
|
|
138
|
-
exportNode,
|
|
139
|
-
exportNode.decorators,
|
|
140
|
-
exportNode.modifiers,
|
|
141
|
-
exportNode.exportClause,
|
|
142
|
-
this.context.factory.createStringLiteral(resolved),
|
|
143
|
-
exportNode.typeOnly
|
|
144
|
-
);
|
|
145
|
-
if (newNode.flags !== exportNode.flags) {
|
|
146
|
-
newNode.flags = exportNode.flags
|
|
147
|
-
}
|
|
148
|
-
return newNode;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @param importNode {ts.ImportDeclaration}
|
|
153
|
-
* @param sourceFile {ts.SourceFile}
|
|
154
|
-
*/
|
|
155
|
-
visitImportNode(importNode, sourceFile) {
|
|
156
|
-
const file = importNode.moduleSpecifier?.text;
|
|
157
|
-
if (!file)
|
|
158
|
-
return;
|
|
159
|
-
const resolved = this.resolve(file, sourceFile);
|
|
160
|
-
|
|
161
|
-
const newNode = this.context.factory.updateImportDeclaration(
|
|
162
|
-
importNode,
|
|
163
|
-
importNode.modifiers,
|
|
164
|
-
importNode.importClause,
|
|
165
|
-
this.context.factory.createStringLiteral(resolved),
|
|
166
|
-
importNode.assertClause,
|
|
167
|
-
);
|
|
168
|
-
newNode.flags = importNode.flags;
|
|
169
|
-
return newNode;
|
|
170
|
-
// const caseSensitiveFileNames = this.context.getEmitHost().useCaseSensitiveFileNames();
|
|
171
|
-
// const formatPath = caseSensitiveFileNames ? x => x : x => x.toLowerCase();
|
|
172
|
-
// const sourceFileDir = path.dirname(sourceFile.path);
|
|
173
|
-
// const abs = formatPath(path.resolve(sourceFileDir, formatPath(file)));
|
|
174
|
-
// if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
|
|
175
|
-
// const absSource = formatPath(path.join(this.options.outDir, formatPath(path.relative(this.options.baseUrl, sourceFileDir))));
|
|
176
|
-
// const relFile = path.relative(absSource, abs).replaceAll(path.sep, '/');
|
|
177
|
-
// return this.context.factory.updateImportDeclaration(
|
|
178
|
-
// importNode,
|
|
179
|
-
// importNode.decorators,
|
|
180
|
-
// importNode.modifiers,
|
|
181
|
-
// importNode.importClause,
|
|
182
|
-
// importNode.assertClause,
|
|
183
|
-
// this.context.factory.createStringLiteral(relFile)
|
|
184
|
-
// );
|
|
185
|
-
// }
|
|
186
|
-
// if (/\.(json|tsx?|jsx?)$/.test(file))
|
|
187
|
-
// return;
|
|
188
|
-
// if (fs.existsSync(abs + '.ts') || fs.existsSync(abs + '.tsx')) {
|
|
189
|
-
// return this.context.factory.updateImportDeclaration(
|
|
190
|
-
// importNode,
|
|
191
|
-
// importNode.decorators,
|
|
192
|
-
// importNode.modifiers,
|
|
193
|
-
// importNode.importClause,
|
|
194
|
-
// importNode.assertClause,
|
|
195
|
-
// this.context.factory.createStringLiteral(file + '.js')
|
|
196
|
-
// );
|
|
197
|
-
// }
|
|
198
|
-
// if (fs.existsSync(abs + '/')) {
|
|
199
|
-
// const indexFile = `${file}/index.js`;
|
|
200
|
-
// return this.context.factory.updateImportDeclaration(
|
|
201
|
-
// importNode,
|
|
202
|
-
// importNode.decorators,
|
|
203
|
-
// importNode.modifiers,
|
|
204
|
-
// importNode.importClause,
|
|
205
|
-
// importNode.assertClause,
|
|
206
|
-
// this.context.factory.createStringLiteral(indexFile)
|
|
207
|
-
// );
|
|
208
|
-
// }
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* @param importNode {ts.Node}
|
|
213
|
-
* @param sourceFile {ts.SourceFile}
|
|
214
|
-
*/
|
|
215
|
-
visitRequireNode(importNode, sourceFile) {
|
|
216
|
-
if (importNode.expression.kind !== ts.SyntaxKind.Identifier ||
|
|
217
|
-
importNode.expression.escapedText !== "require") {
|
|
218
|
-
return;
|
|
219
|
-
}
|
|
220
|
-
const file = importNode.arguments[0].text;
|
|
221
|
-
const resolved = this.resolve(file, sourceFile);
|
|
222
|
-
return this.context.factory.updateCallExpression(
|
|
223
|
-
importNode,
|
|
224
|
-
importNode.expression,
|
|
225
|
-
undefined,
|
|
226
|
-
[this.context.factory.createStringLiteral(resolved)]
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export const tsResolvePlugin = function (contextOrOptions) {
|
|
232
|
-
if(!contextOrOptions.getCompilerOptions)
|
|
233
|
-
return context => new Visitor(context, contextOrOptions).visitSourceFile;
|
|
234
|
-
return new Visitor(contextOrOptions).visitSourceFile;
|
|
235
|
-
};
|
package/compile/typings.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
declare module "*.less"{
|
|
2
|
-
const style: string;
|
|
3
|
-
export default style;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
declare module "*.svg"{
|
|
7
|
-
const style: string;
|
|
8
|
-
export default style;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
declare module "*.css"{
|
|
12
|
-
const style: string;
|
|
13
|
-
export default style;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
declare module "*.html"{
|
|
17
|
-
const style: string;
|
|
18
|
-
export default style;
|
|
19
|
-
}
|
package/gen/component.ts.tpl
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {component, HtmlComponent, property} from "@cmmn/ui";
|
|
2
|
-
import {template, IState, IEvents} from "./$name$.template";
|
|
3
|
-
import style from "./$name$.style.less";
|
|
4
|
-
import {Injectable} from "@cmmn/core";
|
|
5
|
-
|
|
6
|
-
@Injectable(true)
|
|
7
|
-
@component({name: '$name$', template, style})
|
|
8
|
-
export class $Name$Component extends HtmlComponent<IState, IEvents> {
|
|
9
|
-
|
|
10
|
-
@property()
|
|
11
|
-
private property!: any;
|
|
12
|
-
|
|
13
|
-
get State() {
|
|
14
|
-
return this.property;
|
|
15
|
-
}
|
|
16
|
-
}
|