@cmmn/tools 2.2.3 → 3.0.0-alpha-4

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.
Files changed (205) hide show
  1. package/.swcrc +20 -0
  2. package/dist/bundle/index.js +913 -0
  3. package/dist/bundle/test.js +32 -0
  4. package/dist/esm/bin.js +9 -0
  5. package/dist/esm/bin.js.map +1 -0
  6. package/dist/esm/bundlers/createBundler.js +9 -0
  7. package/dist/esm/bundlers/createBundler.js.map +1 -0
  8. package/dist/esm/bundlers/plugins/minify.js +34 -0
  9. package/dist/esm/bundlers/plugins/minify.js.map +1 -0
  10. package/dist/esm/bundlers/plugins/wasm.js +43 -0
  11. package/dist/esm/bundlers/plugins/wasm.js.map +1 -0
  12. package/dist/esm/bundlers/rolldown-bundler.js +153 -0
  13. package/dist/esm/bundlers/rolldown-bundler.js.map +1 -0
  14. package/dist/esm/bundlers/types.js +3 -0
  15. package/dist/esm/bundlers/types.js.map +1 -0
  16. package/dist/esm/bundlers/vite.builder.js +117 -0
  17. package/dist/esm/bundlers/vite.builder.js.map +1 -0
  18. package/dist/esm/bundlers/vite.bundler.js +56 -0
  19. package/dist/esm/bundlers/vite.bundler.js.map +1 -0
  20. package/dist/esm/commands/bundle.js +102 -0
  21. package/dist/esm/commands/bundle.js.map +1 -0
  22. package/dist/esm/commands/cert.js +26 -0
  23. package/dist/esm/commands/cert.js.map +1 -0
  24. package/dist/esm/commands/ci.js +14 -0
  25. package/dist/esm/commands/ci.js.map +1 -0
  26. package/dist/esm/commands/clean.js +18 -0
  27. package/dist/esm/commands/clean.js.map +1 -0
  28. package/dist/esm/commands/compile.js +60 -0
  29. package/dist/esm/commands/compile.js.map +1 -0
  30. package/dist/esm/commands/deploy.js +61 -0
  31. package/dist/esm/commands/deploy.js.map +1 -0
  32. package/dist/esm/commands/dev.js +37 -0
  33. package/dist/esm/commands/dev.js.map +1 -0
  34. package/dist/esm/commands/format.js +44 -0
  35. package/dist/esm/commands/format.js.map +1 -0
  36. package/dist/esm/commands/gen.js +36 -0
  37. package/dist/esm/commands/gen.js.map +1 -0
  38. package/dist/esm/commands/host.js +21 -0
  39. package/dist/esm/commands/host.js.map +1 -0
  40. package/dist/esm/commands/index.js +12 -0
  41. package/dist/esm/commands/index.js.map +1 -0
  42. package/dist/esm/commands/lint.js +45 -0
  43. package/dist/esm/commands/lint.js.map +1 -0
  44. package/dist/esm/commands/nginx.js +62 -0
  45. package/dist/esm/commands/nginx.js.map +1 -0
  46. package/dist/esm/commands/publish.js +37 -0
  47. package/dist/esm/commands/publish.js.map +1 -0
  48. package/dist/esm/commands/typings.js +66 -0
  49. package/dist/esm/commands/typings.js.map +1 -0
  50. package/dist/esm/commands/version.js +34 -0
  51. package/dist/esm/commands/version.js.map +1 -0
  52. package/dist/esm/dev-server/asset-collection.js +18 -0
  53. package/dist/esm/dev-server/asset-collection.js.map +1 -0
  54. package/dist/esm/dev-server/bundle.json.builder.js +47 -0
  55. package/dist/esm/dev-server/bundle.json.builder.js.map +1 -0
  56. package/dist/esm/dev-server/dependencyServer.js +96 -0
  57. package/dist/esm/dev-server/dependencyServer.js.map +1 -0
  58. package/dist/esm/dev-server/dev-server.js +49 -0
  59. package/dist/esm/dev-server/dev-server.js.map +1 -0
  60. package/dist/esm/dev-server/plugins/minify.js +34 -0
  61. package/dist/esm/dev-server/plugins/minify.js.map +1 -0
  62. package/dist/esm/dev-server/plugins/wasm.js +30 -0
  63. package/dist/esm/dev-server/plugins/wasm.js.map +1 -0
  64. package/dist/esm/dev-server/resolver.js +55 -0
  65. package/dist/esm/dev-server/resolver.js.map +1 -0
  66. package/dist/esm/dev-server/rolldown-dependency-builder.js +150 -0
  67. package/dist/esm/dev-server/rolldown-dependency-builder.js.map +1 -0
  68. package/dist/esm/dev-server/target-runnner.js +72 -0
  69. package/dist/esm/dev-server/target-runnner.js.map +1 -0
  70. package/dist/esm/dev-server/target-web-server.js +78 -0
  71. package/dist/esm/dev-server/target-web-server.js.map +1 -0
  72. package/dist/esm/dev-server/targetServer.js +29 -0
  73. package/dist/esm/dev-server/targetServer.js.map +1 -0
  74. package/dist/esm/dev-server/vite.builder.js +183 -0
  75. package/dist/esm/dev-server/vite.builder.js.map +1 -0
  76. package/dist/esm/dev-server/wasm-resolver.js +25 -0
  77. package/dist/esm/dev-server/wasm-resolver.js.map +1 -0
  78. package/dist/esm/helpers/fastify-compress.js +26 -0
  79. package/dist/esm/helpers/fastify-compress.js.map +1 -0
  80. package/dist/esm/helpers/flags.js +22 -0
  81. package/dist/esm/helpers/flags.js.map +1 -0
  82. package/dist/esm/helpers/getProjects.js +49 -0
  83. package/dist/esm/helpers/getProjects.js.map +1 -0
  84. package/dist/esm/helpers/getTSConfig.js +32 -0
  85. package/dist/esm/helpers/getTSConfig.js.map +1 -0
  86. package/dist/esm/helpers/target.js +230 -0
  87. package/dist/esm/helpers/target.js.map +1 -0
  88. package/dist/esm/helpers/terminal.js +117 -0
  89. package/dist/esm/helpers/terminal.js.map +1 -0
  90. package/dist/esm/helpers/ts-resolve-plugin.js +139 -0
  91. package/dist/esm/helpers/ts-resolve-plugin.js.map +1 -0
  92. package/dist/esm/helpers/watcher.js +35 -0
  93. package/dist/esm/helpers/watcher.js.map +1 -0
  94. package/dist/esm/index.js +5 -0
  95. package/dist/esm/index.js.map +1 -0
  96. package/dist/esm/model/bundle.js +75 -0
  97. package/dist/esm/model/bundle.js.map +1 -0
  98. package/dist/esm/model/flags.js +27 -0
  99. package/dist/esm/model/flags.js.map +1 -0
  100. package/dist/esm/model/monorepo.js +74 -0
  101. package/dist/esm/model/monorepo.js.map +1 -0
  102. package/dist/esm/model/pack.js +134 -0
  103. package/dist/esm/model/pack.js.map +1 -0
  104. package/dist/esm/model/resolver.js +100 -0
  105. package/dist/esm/model/resolver.js.map +1 -0
  106. package/dist/esm/model/target.js +111 -0
  107. package/dist/esm/model/target.js.map +1 -0
  108. package/dist/esm/servers/bundle-server.js +20 -0
  109. package/dist/esm/servers/bundle-server.js.map +1 -0
  110. package/dist/esm/servers/dev-server.js +70 -0
  111. package/dist/esm/servers/dev-server.js.map +1 -0
  112. package/dist/esm/servers/pack-server.js +20 -0
  113. package/dist/esm/servers/pack-server.js.map +1 -0
  114. package/dist/esm/servers/target-runnner.js +80 -0
  115. package/dist/esm/servers/target-runnner.js.map +1 -0
  116. package/dist/esm/servers/vite-dev-server.js +61 -0
  117. package/dist/esm/servers/vite-dev-server.js.map +1 -0
  118. package/dist/esm/specs/dependency-builder-specs.js +164 -0
  119. package/dist/esm/specs/dependency-builder-specs.js.map +1 -0
  120. package/dist/esm/specs/dev-server.specs.js +73 -0
  121. package/dist/esm/specs/dev-server.specs.js.map +1 -0
  122. package/dist/esm/specs/monorepo.specs.js +35 -0
  123. package/dist/esm/specs/monorepo.specs.js.map +1 -0
  124. package/dist/esm/specs/resolver.specs.js +57 -0
  125. package/dist/esm/specs/resolver.specs.js.map +1 -0
  126. package/dist/esm/specs/rolldown.specs.js +278 -0
  127. package/dist/esm/specs/rolldown.specs.js.map +1 -0
  128. package/dist/esm/specs/target-specs.js +108 -0
  129. package/dist/esm/specs/target-specs.js.map +1 -0
  130. package/dist/esm/specs/vite-bundler.specs.js +77 -0
  131. package/dist/esm/specs/vite-bundler.specs.js.map +1 -0
  132. package/dist/esm/test/test.js +30 -0
  133. package/dist/esm/test/test.js.map +1 -0
  134. package/dist/ts.buildinfo +1 -0
  135. package/dist/typings/bin.d.ts +2 -0
  136. package/dist/typings/bundlers/plugins/minify.d.ts +6 -0
  137. package/dist/typings/bundlers/plugins/wasm.d.ts +5 -0
  138. package/dist/typings/bundlers/rolldown-bundler.d.ts +18 -0
  139. package/dist/typings/bundlers/types.d.ts +4 -0
  140. package/dist/typings/bundlers/vite.builder.d.ts +12 -0
  141. package/dist/typings/bundlers/vite.bundler.d.ts +9 -0
  142. package/dist/typings/commands/bundle.d.ts +2 -0
  143. package/dist/typings/commands/cert.d.ts +1 -0
  144. package/dist/typings/commands/clean.d.ts +2 -0
  145. package/dist/typings/commands/compile.d.ts +2 -0
  146. package/dist/typings/commands/dev.d.ts +2 -0
  147. package/dist/typings/commands/format.d.ts +5 -0
  148. package/dist/typings/commands/gen.d.ts +1 -0
  149. package/dist/typings/commands/host.d.ts +1 -0
  150. package/dist/typings/commands/index.d.ts +10 -0
  151. package/dist/typings/commands/lint.d.ts +5 -0
  152. package/dist/typings/commands/nginx.d.ts +6 -0
  153. package/dist/typings/commands/publish.d.ts +2 -0
  154. package/dist/typings/commands/typings.d.ts +4 -0
  155. package/dist/typings/commands/version.d.ts +1 -0
  156. package/dist/typings/helpers/fastify-compress.d.ts +6 -0
  157. package/dist/typings/helpers/getTSConfig.d.ts +11 -0
  158. package/dist/typings/helpers/terminal.d.ts +22 -0
  159. package/dist/typings/helpers/watcher.d.ts +7 -0
  160. package/dist/typings/index.d.ts +4 -0
  161. package/dist/typings/model/bundle.d.ts +34 -0
  162. package/dist/typings/model/flags.d.ts +15 -0
  163. package/dist/typings/model/monorepo.d.ts +18 -0
  164. package/dist/typings/model/pack.d.ts +45 -0
  165. package/dist/typings/model/resolver.d.ts +38 -0
  166. package/dist/typings/model/target.d.ts +27 -0
  167. package/dist/typings/servers/bundle-server.d.ts +10 -0
  168. package/dist/typings/servers/dev-server.d.ts +16 -0
  169. package/dist/typings/servers/pack-server.d.ts +9 -0
  170. package/dist/typings/servers/target-runnner.d.ts +13 -0
  171. package/dist/typings/servers/vite-dev-server.d.ts +18 -0
  172. package/dist/typings/specs/dev-server.specs.d.ts +1 -0
  173. package/dist/typings/specs/monorepo.specs.d.ts +1 -0
  174. package/dist/typings/specs/resolver.specs.d.ts +1 -0
  175. package/dist/typings/specs/rolldown.specs.d.ts +1 -0
  176. package/dist/typings/specs/target-specs.d.ts +1 -0
  177. package/dist/typings/specs/vite-bundler.specs.d.ts +1 -0
  178. package/dist/typings/test/test.d.ts +16 -0
  179. package/{compile → helpers}/tsconfig.json +12 -9
  180. package/node/hooks-dev.js +72 -0
  181. package/node/register-dev.js +3 -0
  182. package/node/register.js +14 -0
  183. package/package.json +51 -40
  184. package/readme.md +2 -2
  185. package/tsconfig.json +14 -0
  186. package/LICENSE +0 -21
  187. package/bin.js +0 -21
  188. package/bundle/bundle.js +0 -46
  189. package/bundle/esbuild.config.js +0 -178
  190. package/bundle/getConfigs.js +0 -62
  191. package/compile/compile.js +0 -53
  192. package/compile/ts-resolve-plugin.js +0 -235
  193. package/compile/typings.d.ts +0 -19
  194. package/gen/component.ts.tpl +0 -16
  195. package/gen/gen.js +0 -27
  196. package/gen/style.less.tpl +0 -3
  197. package/gen/template.ts.tpl +0 -8
  198. package/helpers/getTSConfig.js +0 -19
  199. package/serve/readme.md +0 -8
  200. package/serve/serve.js +0 -109
  201. package/spawn/index.js +0 -81
  202. package/test/index.d.ts +0 -18
  203. package/test/index.js +0 -16
  204. package/test/jest.config.js +0 -32
  205. package/test/pathsToModuleNameMapper.js +0 -46
package/readme.md CHANGED
@@ -8,11 +8,11 @@
8
8
  > Runs rollup bundler
9
9
 
10
10
  * `cmmn gen name directory [-n]`
11
- > Generates component with template at directory
11
+ > Generates decorators with template at directory
12
12
 
13
13
  * default `jest.config.js`:
14
14
  ```typescript
15
- import config from "@cmmn/tools/test/config";
15
+ import config from "@cmmn/tools/client/config";
16
16
  export default config;
17
17
  ```
18
18
 
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "extends": "@cmmn/tools/tsconfig.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "allowJs": true
6
+ },
7
+ "exclude": [
8
+ "node_modules",
9
+ "dist",
10
+ "node",
11
+ "helpers/tsconfig.json",
12
+ ".swcrc"
13
+ ]
14
+ }
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
- }
@@ -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
- }
@@ -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
- }
@@ -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
- };
@@ -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
- }
@@ -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
- }