@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.
package/gen/gen.js CHANGED
@@ -1,27 +1,27 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import {fileURLToPath} from 'url';
4
- import {execSync} from "child_process";
5
-
6
- const currentDir = '__dirname' in global ? __dirname : path.dirname(fileURLToPath(import.meta.url));
7
-
8
- const templateTpl = fs.readFileSync(path.join(currentDir, './template.ts.tpl'), 'utf8');
9
- const componentTpl = fs.readFileSync(path.join(currentDir, './component.ts.tpl'), 'utf8');
10
- const styleTpl = fs.readFileSync(path.join(currentDir, './style.less.tpl'), 'utf8');
11
-
12
-
13
- export function gen(name, directory, nested = false) {
14
- const Name = name.replace(/^./, c => c.toUpperCase());
15
- name = Name.replace(/[A-Z]/g, (c, i) => (i ? '-' : '') + c.toLowerCase());
16
- process.chdir(directory);
17
- if (nested) {
18
- fs.mkdirSync(name);
19
- process.chdir(name);
20
- }
21
- fs.writeFileSync(name + '.component.ts', componentTpl.replace(/\$Name\$/g, Name).replace(/\$name\$/g, name), 'utf8');
22
- fs.writeFileSync(name + '.template.ts', templateTpl.replace(/\$Name\$/g, Name).replace(/\$name\$/g, name), 'utf8');
23
- fs.writeFileSync(name + '.style.less', styleTpl.replace(/\$Name\$/g, Name).replace(/\$name\$/g, name), 'utf8');
24
- execSync(`git add ${name}.component.ts`);
25
- execSync(`git add ${name}.template.ts`);
26
- execSync(`git add ${name}.style.less`);
27
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import {fileURLToPath} from 'url';
4
+ import {execSync} from "child_process";
5
+
6
+ const currentDir = '__dirname' in global ? __dirname : path.dirname(fileURLToPath(import.meta.url));
7
+
8
+ const templateTpl = fs.readFileSync(path.join(currentDir, './template.ts.tpl'), 'utf8');
9
+ const componentTpl = fs.readFileSync(path.join(currentDir, './component.ts.tpl'), 'utf8');
10
+ const styleTpl = fs.readFileSync(path.join(currentDir, './style.less.tpl'), 'utf8');
11
+
12
+
13
+ export function gen(name, directory, nested = false) {
14
+ const Name = name.replace(/^./, c => c.toUpperCase());
15
+ name = Name.replace(/[A-Z]/g, (c, i) => (i ? '-' : '') + c.toLowerCase());
16
+ process.chdir(directory);
17
+ if (nested) {
18
+ fs.mkdirSync(name);
19
+ process.chdir(name);
20
+ }
21
+ fs.writeFileSync(name + '.component.ts', componentTpl.replace(/\$Name\$/g, Name).replace(/\$name\$/g, name), 'utf8');
22
+ fs.writeFileSync(name + '.template.ts', templateTpl.replace(/\$Name\$/g, Name).replace(/\$name\$/g, name), 'utf8');
23
+ fs.writeFileSync(name + '.style.less', styleTpl.replace(/\$Name\$/g, Name).replace(/\$name\$/g, name), 'utf8');
24
+ execSync(`git add ${name}.component.ts`);
25
+ execSync(`git add ${name}.template.ts`);
26
+ execSync(`git add ${name}.style.less`);
27
+ }
@@ -1,3 +1,3 @@
1
- $name$ {
2
- display: block;
3
- }
1
+ $name$ {
2
+ display: block;
3
+ }
@@ -1,8 +1,8 @@
1
- import {ITemplate} from "@cmmn/ui";
2
-
3
- export const template: ITemplate<IState, IEvents> = (html, state, events) => html`
4
- `;
5
-
6
- export type IState = {}
7
-
8
- export type IEvents = {}
1
+ import {ITemplate} from "@cmmn/ui";
2
+
3
+ export const template: ITemplate<IState, IEvents> = (html, state, events) => html`
4
+ `;
5
+
6
+ export type IState = {}
7
+
8
+ export type IEvents = {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmmn/tools",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Compilation, bundling, code generator, testing.",
5
5
  "main": "dist/rollup.config.js",
6
6
  "type": "module",
@@ -60,10 +60,10 @@
60
60
  "rollup-plugin-visualizer": "^5.5.4",
61
61
  "ts-jest": "27.x.x",
62
62
  "ttypescript": "1.5.13",
63
- "typescript": "4.4.3",
63
+ "typescript": "4.x.x",
64
64
  "typescript-transform-paths": "^3.3.1"
65
65
  },
66
66
  "author": "",
67
67
  "license": "ISC",
68
- "gitHead": "d1405a0626569d43adc867fe660f4df8b5c3b492"
68
+ "gitHead": "824d290afabaa3a44ccb98322cb1758825bd9efb"
69
69
  }
@@ -1,96 +1,96 @@
1
- const ts = require("typescript");
2
- const path = require("path");
3
- const fs = require("fs");
4
-
5
- function visitExportNode(exportNode, sourceFile) {
6
- if (exportNode.typeOnly){
7
- console.log('type olnly')
8
- return ;
9
- }
10
- const file = exportNode.moduleSpecifier?.text ?? exportNode.test;
11
- if (!file)
12
- return;
13
- const sourceFileDir = path.dirname(sourceFile.path);
14
- const abs = path.resolve(sourceFileDir, file);
15
- if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
16
- const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
17
- const relFile = path.relative(absSource, abs)
18
- return ts.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, ts.createStringLiteral(relFile), exportNode.typeOnly);
19
- }
20
- if (fs.existsSync(abs + '.ts')) {
21
- return ts.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, ts.createStringLiteral(file + '.js'), exportNode.typeOnly);
22
- }
23
- if (fs.existsSync(abs + '/')) {
24
- const indexFile = `${file}/index.js`;
25
- return ts.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, ts.createStringLiteral(indexFile), exportNode.typeOnly);
26
- }
27
- }
28
-
29
- function visitImportNode(importNode, sourceFile, options) {
30
- const file = importNode.moduleSpecifier?.text;
31
- if (!file)
32
- return;
33
- const sourceFileDir = path.dirname(sourceFile.path);
34
- const abs = path.resolve(sourceFileDir, file);
35
- if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
36
- const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
37
- const relFile = path.relative(absSource, abs)
38
- return ts.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, ts.createStringLiteral(relFile));
39
- }
40
- if (fs.existsSync(abs + '.ts')) {
41
- return ts.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, ts.createStringLiteral(file + '.js'));
42
- }
43
- if (fs.existsSync(abs + '/')) {
44
- const indexFile = `${file}/index.js`;
45
- return ts.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, ts.createStringLiteral(indexFile));
46
- }
47
- }
48
-
49
- function visitRequireNode(importNode, sourceFile) {
50
- if (!(importNode.expression.kind == ts.SyntaxKind.Identifier &&
51
- importNode.expression.escapedText == "require")) {
52
- return;
53
- }
54
- const file = importNode.arguments[0].text;
55
- if (/\.(less|css|scss|sass|svg|png|html)/.test(file)) {
56
- const sourceFileDir = path.dirname(sourceFile.path);
57
- const abs = path.join(sourceFileDir, file);
58
- const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
59
- const relFile = path.relative(absSource, abs)
60
- return ts.updateCall(importNode, importNode.expression, undefined, [ts.createStringLiteral(relFile)]);
61
- }
62
- }
63
-
64
- const lessToStringTransformer = function (context) {
65
- const options = context.getCompilerOptions();
66
- return (sourceFile) => {
67
- function visitor(node) {
68
- // if (node && node.kind == ts.SyntaxKind.ImportDeclaration) {
69
- // return visitImportNode(node as ts.ImportDeclaration);
70
- // }
71
- if (!node)
72
- return ts.visitEachChild(node, visitor, context);
73
- if (ts.isCallExpression(node)) {
74
- const result = visitRequireNode(node, sourceFile);
75
- if (result)
76
- return result;
77
- }
78
- if (ts.isImportDeclaration(node)) {
79
- const result = visitImportNode(node, sourceFile, options);
80
- if (result)
81
- return result;
82
- }
83
- if (ts.isExportDeclaration(node)) {
84
- const result = visitExportNode(node, sourceFile);
85
- if (result)
86
- return result;
87
- }
88
- return ts.visitEachChild(node, visitor, context);
89
- }
90
-
91
- return ts.visitEachChild(sourceFile, visitor, context);
92
- };
93
- };
94
- exports.default = function (program, pluginOptions) {
95
- return lessToStringTransformer;
96
- }
1
+ const ts = require("typescript");
2
+ const path = require("path");
3
+ const fs = require("fs");
4
+
5
+ function visitExportNode(exportNode, sourceFile) {
6
+ if (exportNode.typeOnly){
7
+ console.log('type olnly')
8
+ return ;
9
+ }
10
+ const file = exportNode.moduleSpecifier?.text ?? exportNode.test;
11
+ if (!file)
12
+ return;
13
+ const sourceFileDir = path.dirname(sourceFile.path);
14
+ const abs = path.resolve(sourceFileDir, file);
15
+ if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
16
+ const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
17
+ const relFile = path.relative(absSource, abs)
18
+ return ts.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, ts.createStringLiteral(relFile), exportNode.typeOnly);
19
+ }
20
+ if (fs.existsSync(abs + '.ts')) {
21
+ return ts.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, ts.createStringLiteral(file + '.js'), exportNode.typeOnly);
22
+ }
23
+ if (fs.existsSync(abs + '/')) {
24
+ const indexFile = `${file}/index.js`;
25
+ return ts.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, ts.createStringLiteral(indexFile), exportNode.typeOnly);
26
+ }
27
+ }
28
+
29
+ function visitImportNode(importNode, sourceFile, options) {
30
+ const file = importNode.moduleSpecifier?.text;
31
+ if (!file)
32
+ return;
33
+ const sourceFileDir = path.dirname(sourceFile.path);
34
+ const abs = path.resolve(sourceFileDir, file);
35
+ if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
36
+ const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
37
+ const relFile = path.relative(absSource, abs)
38
+ return ts.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, ts.createStringLiteral(relFile));
39
+ }
40
+ if (fs.existsSync(abs + '.ts')) {
41
+ return ts.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, ts.createStringLiteral(file + '.js'));
42
+ }
43
+ if (fs.existsSync(abs + '/')) {
44
+ const indexFile = `${file}/index.js`;
45
+ return ts.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, ts.createStringLiteral(indexFile));
46
+ }
47
+ }
48
+
49
+ function visitRequireNode(importNode, sourceFile) {
50
+ if (!(importNode.expression.kind == ts.SyntaxKind.Identifier &&
51
+ importNode.expression.escapedText == "require")) {
52
+ return;
53
+ }
54
+ const file = importNode.arguments[0].text;
55
+ if (/\.(less|css|scss|sass|svg|png|html)/.test(file)) {
56
+ const sourceFileDir = path.dirname(sourceFile.path);
57
+ const abs = path.join(sourceFileDir, file);
58
+ const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
59
+ const relFile = path.relative(absSource, abs)
60
+ return ts.updateCall(importNode, importNode.expression, undefined, [ts.createStringLiteral(relFile)]);
61
+ }
62
+ }
63
+
64
+ const lessToStringTransformer = function (context) {
65
+ const options = context.getCompilerOptions();
66
+ return (sourceFile) => {
67
+ function visitor(node) {
68
+ // if (node && node.kind == ts.SyntaxKind.ImportDeclaration) {
69
+ // return visitImportNode(node as ts.ImportDeclaration);
70
+ // }
71
+ if (!node)
72
+ return ts.visitEachChild(node, visitor, context);
73
+ if (ts.isCallExpression(node)) {
74
+ const result = visitRequireNode(node, sourceFile);
75
+ if (result)
76
+ return result;
77
+ }
78
+ if (ts.isImportDeclaration(node)) {
79
+ const result = visitImportNode(node, sourceFile, options);
80
+ if (result)
81
+ return result;
82
+ }
83
+ if (ts.isExportDeclaration(node)) {
84
+ const result = visitExportNode(node, sourceFile);
85
+ if (result)
86
+ return result;
87
+ }
88
+ return ts.visitEachChild(node, visitor, context);
89
+ }
90
+
91
+ return ts.visitEachChild(sourceFile, visitor, context);
92
+ };
93
+ };
94
+ exports.default = function (program, pluginOptions) {
95
+ return lessToStringTransformer;
96
+ }
package/readme.md CHANGED
@@ -1,31 +1,31 @@
1
- ## Builder and bundler for your projects
2
-
3
- ### Use cases:
4
- * `cmmn compile [target] [-b] [--watch]`
5
- > Runs typescript compiler
6
-
7
- * `cmmn bundle [target] [-b] [--watch] [--run] [--prod]`
8
- > Runs rollup bundler
9
-
10
- * `cmmn gen name directory [-n]`
11
- > Generates component with template at directory
12
-
13
- * default `jest.config.js`:
14
- ```typescript
15
- import config from "@cmmn/tools/test/config";
16
- export default config;
17
- ```
18
-
19
- * tests: `some.spec.ts`
20
- ```typescript
21
- import {suite, test, expect} from "@cmmn/tools/test";
22
-
23
- @suite
24
- export class SomeSpec {
25
-
26
- @test
27
- equalsTest() {
28
- expect(1).toBe(2);
29
- }
30
- }
1
+ ## Builder and bundler for your projects
2
+
3
+ ### Use cases:
4
+ * `cmmn compile [target] [-b] [--watch]`
5
+ > Runs typescript compiler
6
+
7
+ * `cmmn bundle [target] [-b] [--watch] [--run] [--prod]`
8
+ > Runs rollup bundler
9
+
10
+ * `cmmn gen name directory [-n]`
11
+ > Generates component with template at directory
12
+
13
+ * default `jest.config.js`:
14
+ ```typescript
15
+ import config from "@cmmn/tools/test/config";
16
+ export default config;
17
+ ```
18
+
19
+ * tests: `some.spec.ts`
20
+ ```typescript
21
+ import {suite, test, expect} from "@cmmn/tools/test";
22
+
23
+ @suite
24
+ export class SomeSpec {
25
+
26
+ @test
27
+ equalsTest() {
28
+ expect(1).toBe(2);
29
+ }
30
+ }
31
31
  ```
package/test/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export {suite, test, timeout,} from "@testdeck/jest";
1
+ export {suite, test, timeout,} from "@testdeck/jest";
2
2
  export {expect,} from "@jest/globals";
package/test/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export {suite, test, timeout,} from "@testdeck/jest";
2
- import * as globals from "@jest/globals";
3
-
4
- const {expect} = globals;
1
+ export {suite, test, timeout,} from "@testdeck/jest";
2
+ import * as globals from "@jest/globals";
3
+
4
+ const {expect} = globals;
5
5
  export {expect};
@@ -1,46 +1,46 @@
1
- import ts from "typescript";
2
- import {pathsToModuleNameMapper} from "ts-jest";
3
-
4
- const options = getTSConfig();
5
-
6
- export default {
7
- transform: {
8
- '^.+\\.tsx?$': ['@swc/jest', {
9
- jsc: {
10
- parser: {
11
- syntax: "typescript",
12
- // tsx: true, // If you use react
13
- dynamicImport: true,
14
- decorators: true,
15
- },
16
- target: "es2021",
17
- transform: {
18
- decoratorMetadata: true,
19
- },
20
- paths: options.paths,
21
- baseUrl: '.'
22
- },
23
- }],
24
- },
25
- roots: [process.cwd()],
26
- moduleNameMapper: pathsToModuleNameMapper(options.paths ?? {}, {
27
- prefix: '<rootDir>'
28
- }),
29
- extensionsToTreatAsEsm: ['.ts', '.tsx', '.jsx?'],
30
- }
31
-
32
-
33
- function getTSConfig() {
34
- const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists, 'tsconfig.json');
35
- const readConfigFileResult = ts.readConfigFile(configPath, ts.sys.readFile);
36
- if (readConfigFileResult.error) {
37
- throw new Error(ts.formatDiagnostic(readConfigFileResult.error, formatHost));
38
- }
39
- const jsonConfig = readConfigFileResult.config;
40
- const convertResult = ts.convertCompilerOptionsFromJson(jsonConfig.compilerOptions, './');
41
- if (convertResult.errors && convertResult.errors.length > 0) {
42
- throw new Error(ts.formatDiagnostics(convertResult.errors, formatHost));
43
- }
44
- const compilerOptions = convertResult.options;
45
- return compilerOptions;
1
+ import ts from "typescript";
2
+ import {pathsToModuleNameMapper} from "ts-jest";
3
+
4
+ const options = getTSConfig();
5
+
6
+ export default {
7
+ transform: {
8
+ '^.+\\.tsx?$': ['@swc/jest', {
9
+ jsc: {
10
+ parser: {
11
+ syntax: "typescript",
12
+ // tsx: true, // If you use react
13
+ dynamicImport: true,
14
+ decorators: true,
15
+ },
16
+ target: "es2021",
17
+ transform: {
18
+ decoratorMetadata: true,
19
+ },
20
+ paths: options.paths,
21
+ baseUrl: '.'
22
+ },
23
+ }],
24
+ },
25
+ roots: [process.cwd()],
26
+ moduleNameMapper: pathsToModuleNameMapper(options.paths ?? {}, {
27
+ prefix: '<rootDir>'
28
+ }),
29
+ extensionsToTreatAsEsm: ['.ts', '.tsx', '.jsx?'],
30
+ }
31
+
32
+
33
+ function getTSConfig() {
34
+ const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists, 'tsconfig.json');
35
+ const readConfigFileResult = ts.readConfigFile(configPath, ts.sys.readFile);
36
+ if (readConfigFileResult.error) {
37
+ throw new Error(ts.formatDiagnostic(readConfigFileResult.error, formatHost));
38
+ }
39
+ const jsonConfig = readConfigFileResult.config;
40
+ const convertResult = ts.convertCompilerOptionsFromJson(jsonConfig.compilerOptions, './');
41
+ if (convertResult.errors && convertResult.errors.length > 0) {
42
+ throw new Error(ts.formatDiagnostics(convertResult.errors, formatHost));
43
+ }
44
+ const compilerOptions = convertResult.options;
45
+ return compilerOptions;
46
46
  }