@cmmn/tools 1.4.1 → 1.4.2

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.
@@ -1,211 +1,211 @@
1
- import commonjs from '@rollup/plugin-commonjs';
2
- import nodeResolve from '@rollup/plugin-node-resolve';
3
- import {terser} from "rollup-plugin-terser"
4
- import {visualizer} from 'rollup-plugin-visualizer';
5
- import styles from "rollup-plugin-styles";
6
- import {string} from "rollup-plugin-string";
7
- import serve from 'rollup-plugin-serve';
8
- import builtins from 'rollup-plugin-node-builtins';
9
- import livereload from 'rollup-plugin-livereload';
10
- import fs from "fs";
11
- import path from "path";
12
- import html from '@open-wc/rollup-plugin-html';
13
- import json from '@rollup/plugin-json';
14
- import alias from '@rollup/plugin-alias';
15
-
16
- /**
17
- * @typedef {import(rollup).RollupOptions} RollupOptions
18
- * @typedef {import(rollup).OutputOptions} OutputOptions
19
- */
20
-
21
- export class ConfigCreator {
22
-
23
- /**
24
- * @type {{
25
- * minify: boolean,
26
- * input: string,
27
- * devServer: boolean,
28
- * module: string,
29
- * external: string[],
30
- * stats: boolean,
31
- * name: string,
32
- * outDir: string,
33
- * html: string,
34
- * browser: boolean,
35
- * dedupe: string[]
36
- * }}
37
- */
38
- options;
39
-
40
- /**
41
- * @type {string}
42
- */
43
- root = process.cwd();
44
-
45
-
46
- constructor(options) {
47
- this.options = {
48
- ...options
49
- };
50
- }
51
-
52
- setRootDir(rootDir) {
53
- this.root = rootDir;
54
- }
55
-
56
- get outDir() {
57
- return path.join(this.root, this.options.outDir);
58
- }
59
-
60
- getOutputFileName(module, minify) {
61
- switch (module) {
62
- case "cjs":
63
- return `[name]${minify ? '.min' : ''}.cjs`;
64
- case "es":
65
- return `[name]${minify ? '.min' : ''}.js`;
66
- default:
67
- return `[name]-${module}${minify ? '.min' : ''}.js`;
68
- }
69
- }
70
-
71
- /**
72
- *
73
- * @returns {OutputOptions}
74
- */
75
- get output() {
76
- // const output = `${this.options.name ?? 'index'}-${this.options.module}${this.options.minify ? '.min' : ''}.js`;
77
- return this.options.module.split(',').map(module => ({
78
- entryFileNames: this.getOutputFileName(module, this.options.minify),
79
- // file: output,
80
- dir: this.outDir,
81
- sourcemap: true,
82
- format: module,
83
- name: 'global',
84
- }));
85
- }
86
-
87
- get html() {
88
- return html({
89
- publicPath: '/',
90
- dir: this.outDir,
91
- template: () => fs.readFileSync(path.join(this.root, this.options.html), 'utf8')
92
- });
93
- }
94
-
95
- get devServer() {
96
- return serve({
97
- open: false,
98
- contentBase: [this.outDir, path.join(this.root, 'assets')],
99
- port: this.options.port ?? 3000,
100
- historyApiFallback: true
101
- });
102
- }
103
-
104
- get livereload() {
105
- return livereload({
106
- watch: [this.outDir, path.join(this.root, 'assets')],
107
- verbose: false, // Disable console output
108
- // other livereload options
109
- port: 12345,
110
- delay: 300,
111
- })
112
- }
113
-
114
- get visualizer() {
115
- return visualizer({
116
- open: true,
117
- sourcemap: true,
118
- template: 'treemap',
119
- brotliSize: true,
120
-
121
- filename: path.join(this.outDir, '/stats.html')
122
- })
123
- }
124
-
125
- get plugins() {
126
- const result = [
127
- nodeResolve({
128
- browser: this.options.browser,
129
- dedupe: this.options.dedupe || []
130
- }),
131
- commonjs({
132
- requireReturnsDefault: "namespace",
133
- dynamicRequireTargets: [
134
- 'node_modules/ulid/*.js'
135
- ]
136
- }),
137
- builtins(),
138
- styles({
139
- mode: "emit",
140
- }),
141
- string({
142
- include: /\.(html|svg|less|css)$/,
143
- }),
144
- json(),
145
-
146
- ];
147
- if (this.options.alias) {
148
- result.unshift(alias({
149
- entries: this.options.alias
150
- }));
151
- console.log(this.options.alias)
152
- }
153
- if (this.options.html || this.options.input.endsWith('.html')) {
154
- result.push(this.html);
155
- }
156
- if (this.options.minify) {
157
- result.push(terser({
158
- module: true,
159
- ecma: 2020,
160
- compress: true,
161
- keep_classnames: false,
162
- keep_fnames: false,
163
- mangle: true,
164
- output: {
165
- comments: false
166
- }
167
- }));
168
- }
169
- if (this.options.devServer) {
170
- result.push(this.devServer, this.livereload);
171
- }
172
- if (this.options.stats) {
173
- result.push(this.visualizer);
174
- }
175
- return result;
176
- }
177
-
178
- /**
179
- * @returns {RollupOptions[]}
180
- */
181
- getConfig() {
182
- Object.assign(this.options, {
183
- module: this.options.module || 'es',
184
- external: this.options.external || [],
185
- name: this.options.name || 'index',
186
- outDir: this.options.outDir || 'dist'
187
- });
188
- if (this.options.external && typeof this.options.external === "string")
189
- this.options.external = [this.options.external]
190
- console.log(this.options);
191
- return [{
192
- input: {
193
- [this.options.name]: path.join(this.root, this.options.input)
194
- },
195
- output: this.output,
196
- external: (this.options.external || []).map(s => new RegExp(s)),
197
- onwarn(warning) {
198
- // Silence circular dependency warning for moment package
199
- if (
200
- warning.code === 'CIRCULAR_DEPENDENCY'
201
- ) {
202
- return
203
- }
204
-
205
- console.warn(`(!) ${warning.message}`)
206
- },
207
- plugins: this.plugins,
208
- treeshake: this.options.minify ? "smallest" : "recommended",
209
- }]
210
- }
211
- }
1
+ import commonjs from '@rollup/plugin-commonjs';
2
+ import nodeResolve from '@rollup/plugin-node-resolve';
3
+ import {terser} from "rollup-plugin-terser"
4
+ import {visualizer} from 'rollup-plugin-visualizer';
5
+ import styles from "rollup-plugin-styles";
6
+ import {string} from "rollup-plugin-string";
7
+ import serve from 'rollup-plugin-serve';
8
+ import builtins from 'rollup-plugin-node-builtins';
9
+ import livereload from 'rollup-plugin-livereload';
10
+ import fs from "fs";
11
+ import path from "path";
12
+ import html from '@open-wc/rollup-plugin-html';
13
+ import json from '@rollup/plugin-json';
14
+ import alias from '@rollup/plugin-alias';
15
+
16
+ /**
17
+ * @typedef {import(rollup).RollupOptions} RollupOptions
18
+ * @typedef {import(rollup).OutputOptions} OutputOptions
19
+ */
20
+
21
+ export class ConfigCreator {
22
+
23
+ /**
24
+ * @type {{
25
+ * minify: boolean,
26
+ * input: string,
27
+ * devServer: boolean,
28
+ * module: string,
29
+ * external: string[],
30
+ * stats: boolean,
31
+ * name: string,
32
+ * outDir: string,
33
+ * html: string,
34
+ * browser: boolean,
35
+ * dedupe: string[]
36
+ * }}
37
+ */
38
+ options;
39
+
40
+ /**
41
+ * @type {string}
42
+ */
43
+ root = process.cwd();
44
+
45
+
46
+ constructor(options) {
47
+ this.options = {
48
+ ...options
49
+ };
50
+ }
51
+
52
+ setRootDir(rootDir) {
53
+ this.root = rootDir;
54
+ }
55
+
56
+ get outDir() {
57
+ return path.join(this.root, this.options.outDir);
58
+ }
59
+
60
+ getOutputFileName(module, minify) {
61
+ switch (module) {
62
+ case "cjs":
63
+ return `[name]${minify ? '.min' : ''}.cjs`;
64
+ case "es":
65
+ return `[name]${minify ? '.min' : ''}.js`;
66
+ default:
67
+ return `[name]-${module}${minify ? '.min' : ''}.js`;
68
+ }
69
+ }
70
+
71
+ /**
72
+ *
73
+ * @returns {OutputOptions}
74
+ */
75
+ get output() {
76
+ // const output = `${this.options.name ?? 'index'}-${this.options.module}${this.options.minify ? '.min' : ''}.js`;
77
+ return this.options.module.split(',').map(module => ({
78
+ entryFileNames: this.getOutputFileName(module, this.options.minify),
79
+ // file: output,
80
+ dir: this.outDir,
81
+ sourcemap: true,
82
+ format: module,
83
+ name: this.options.global ?? 'global',
84
+ }));
85
+ }
86
+
87
+ get html() {
88
+ return html({
89
+ publicPath: '/',
90
+ dir: this.outDir,
91
+ template: () => fs.readFileSync(path.join(this.root, this.options.html), 'utf8')
92
+ });
93
+ }
94
+
95
+ get devServer() {
96
+ return serve({
97
+ open: false,
98
+ contentBase: [this.outDir, path.join(this.root, 'assets')],
99
+ port: this.options.port ?? 3000,
100
+ historyApiFallback: true
101
+ });
102
+ }
103
+
104
+ get livereload() {
105
+ return livereload({
106
+ watch: [this.outDir, path.join(this.root, 'assets')],
107
+ verbose: false, // Disable console output
108
+ // other livereload options
109
+ port: 12345,
110
+ delay: 300,
111
+ })
112
+ }
113
+
114
+ get visualizer() {
115
+ return visualizer({
116
+ open: true,
117
+ sourcemap: true,
118
+ template: 'treemap',
119
+ brotliSize: true,
120
+
121
+ filename: path.join(this.outDir, '/stats.html')
122
+ })
123
+ }
124
+
125
+ get plugins() {
126
+ const result = [
127
+ nodeResolve({
128
+ browser: this.options.browser,
129
+ dedupe: this.options.dedupe || []
130
+ }),
131
+ commonjs({
132
+ requireReturnsDefault: "namespace",
133
+ dynamicRequireTargets: [
134
+ 'node_modules/ulid/*.js'
135
+ ]
136
+ }),
137
+ builtins(),
138
+ styles({
139
+ mode: "emit",
140
+ }),
141
+ string({
142
+ include: /\.(html|svg|less|css)$/,
143
+ }),
144
+ json(),
145
+
146
+ ];
147
+ if (this.options.alias) {
148
+ result.unshift(alias({
149
+ entries: this.options.alias
150
+ }));
151
+ console.log(this.options.alias)
152
+ }
153
+ if (this.options.html || this.options.input.endsWith('.html')) {
154
+ result.push(this.html);
155
+ }
156
+ if (this.options.minify) {
157
+ result.push(terser({
158
+ module: true,
159
+ ecma: 2020,
160
+ compress: true,
161
+ keep_classnames: false,
162
+ keep_fnames: false,
163
+ mangle: true,
164
+ output: {
165
+ comments: false
166
+ }
167
+ }));
168
+ }
169
+ if (this.options.devServer) {
170
+ result.push(this.devServer, this.livereload);
171
+ }
172
+ if (this.options.stats) {
173
+ result.push(this.visualizer);
174
+ }
175
+ return result;
176
+ }
177
+
178
+ /**
179
+ * @returns {RollupOptions[]}
180
+ */
181
+ getConfig() {
182
+ Object.assign(this.options, {
183
+ module: this.options.module || 'es',
184
+ external: this.options.external || [],
185
+ name: this.options.name || 'index',
186
+ outDir: this.options.outDir || 'dist'
187
+ });
188
+ if (this.options.external && typeof this.options.external === "string")
189
+ this.options.external = [this.options.external]
190
+ console.log(this.options);
191
+ return [{
192
+ input: {
193
+ [this.options.name]: path.join(this.root, this.options.input)
194
+ },
195
+ output: this.output,
196
+ external: (this.options.external || []).map(s => new RegExp(s)),
197
+ onwarn(warning) {
198
+ // Silence circular dependency warning for moment package
199
+ if (
200
+ warning.code === 'CIRCULAR_DEPENDENCY'
201
+ ) {
202
+ return
203
+ }
204
+
205
+ console.warn(`(!) ${warning.message}`)
206
+ },
207
+ plugins: this.plugins,
208
+ treeshake: this.options.minify ? "smallest" : "recommended",
209
+ }]
210
+ }
211
+ }
@@ -1,33 +1,33 @@
1
- import ts from "ttypescript";
2
- import {resolve} from 'path';
3
-
4
- const rootDir = process.cwd();
5
-
6
- export function compile(...flags) {
7
-
8
- const host = ts.createSolutionBuilderWithWatchHost(ts.sys, createProgram);
9
- host.useCaseSensitiveFileNames();
10
-
11
- const builderFactory = flags.includes('--watch') ?
12
- ts.createSolutionBuilderWithWatch :
13
- ts.createSolutionBuilder;
14
-
15
- const builder = builderFactory(host, [rootDir], {
16
- incremental: true,
17
- dry: false
18
- }, {
19
- excludeDirectories: ["node_modules", "dist"]
20
- });
21
- builder.clean(rootDir);
22
- builder.build(rootDir);
23
- }
24
-
25
- function createProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences) {
26
- options.outDir = resolve(options.configFilePath, '../dist/esm');
27
- options.declarationDir = resolve(options.configFilePath, '../dist/typings');
28
- options.baseUrl = resolve(options.configFilePath, '../');
29
- console.log('build', options.configFilePath);
30
- return ts.createEmitAndSemanticDiagnosticsBuilderProgram(
31
- rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences
32
- )
33
- }
1
+ import ts from "ttypescript";
2
+ import {resolve} from 'path';
3
+
4
+ const rootDir = process.cwd();
5
+
6
+ export function compile(...flags) {
7
+
8
+ const host = ts.createSolutionBuilderWithWatchHost(ts.sys, createProgram);
9
+ host.useCaseSensitiveFileNames();
10
+
11
+ const builderFactory = flags.includes('--watch') ?
12
+ ts.createSolutionBuilderWithWatch :
13
+ ts.createSolutionBuilder;
14
+
15
+ const builder = builderFactory(host, [rootDir], {
16
+ incremental: true,
17
+ dry: false
18
+ }, {
19
+ excludeDirectories: ["node_modules", "dist"]
20
+ });
21
+ builder.clean(rootDir);
22
+ builder.build(rootDir);
23
+ }
24
+
25
+ function createProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences) {
26
+ options.outDir = resolve(options.configFilePath, '../dist/esm');
27
+ options.declarationDir = resolve(options.configFilePath, '../dist/typings');
28
+ options.baseUrl = resolve(options.configFilePath, '../');
29
+ console.log('build', options.configFilePath);
30
+ return ts.createEmitAndSemanticDiagnosticsBuilderProgram(
31
+ rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences
32
+ )
33
+ }
@@ -1,48 +1,48 @@
1
- {
2
- "compilerOptions": {
3
- "module": "esnext",
4
- "moduleResolution": "Node",
5
- "target": "ES2019",
6
- "composite": true,
7
- "sourceMap": true,
8
- "baseUrl": "./",
9
- "experimentalDecorators": true,
10
- "checkJs": false,
11
- "outDir": "./dist/esm",
12
- "skipLibCheck": true,
13
- "skipDefaultLibCheck": true,
14
- "allowJs": true,
15
- "allowSyntheticDefaultImports": true,
16
- "emitDecoratorMetadata": true ,
17
- "noEmitHelpers": true,
18
- "declarationDir": "./dist/typings",
19
- "declaration": true,
20
- "types": [
21
- "@cmmn/tools"
22
- ],
23
- "lib": [
24
- "ES2020.BigInt",
25
- "ESNext",
26
- "DOM"
27
- ],
28
- "plugins": [
29
- {
30
- "transform": "@cmmn/tools/plugins/absolute-plugin.cjs",
31
- "after": true
32
- },
33
- // Transform paths in output .js files
34
- {
35
- "transform": "typescript-transform-paths"
36
- },
37
- // Transform paths in output .d.ts files (Include this line if you output declarations files)
38
- {
39
- "transform": "typescript-transform-paths",
40
- "afterDeclarations": true
41
- }
42
- ]
43
- },
44
- "exclude": [
45
- "node_modules",
46
- "dist"
47
- ]
48
- }
1
+ {
2
+ "compilerOptions": {
3
+ "module": "esnext",
4
+ "moduleResolution": "Node",
5
+ "target": "ES2019",
6
+ "composite": true,
7
+ "sourceMap": true,
8
+ "baseUrl": "./",
9
+ "experimentalDecorators": true,
10
+ "checkJs": false,
11
+ "outDir": "./dist/esm",
12
+ "skipLibCheck": true,
13
+ "skipDefaultLibCheck": true,
14
+ "allowJs": true,
15
+ "allowSyntheticDefaultImports": true,
16
+ "emitDecoratorMetadata": true ,
17
+ "noEmitHelpers": true,
18
+ "declarationDir": "./dist/typings",
19
+ "declaration": true,
20
+ "types": [
21
+ "@cmmn/tools"
22
+ ],
23
+ "lib": [
24
+ "ES2020.BigInt",
25
+ "ESNext",
26
+ "DOM"
27
+ ],
28
+ "plugins": [
29
+ {
30
+ "transform": "@cmmn/tools/plugins/absolute-plugin.cjs",
31
+ "after": true
32
+ },
33
+ // Transform paths in output .js files
34
+ {
35
+ "transform": "typescript-transform-paths"
36
+ },
37
+ // Transform paths in output .d.ts files (Include this line if you output declarations files)
38
+ {
39
+ "transform": "typescript-transform-paths",
40
+ "afterDeclarations": true
41
+ }
42
+ ]
43
+ },
44
+ "exclude": [
45
+ "node_modules",
46
+ "dist"
47
+ ]
48
+ }
@@ -1,19 +1,19 @@
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
+ 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 +1,16 @@
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
- }
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
+ }