@cmmn/tools 1.0.3
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/absolute-plugin.cjs +36 -0
- package/bin.js +12 -0
- package/bundle/bundle.js +53 -0
- package/bundle/rollup.config.js +78 -0
- package/compile/compile.js +47 -0
- package/package.json +38 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const ts = require("typescript");
|
|
2
|
+
const path_1 = require("path");
|
|
3
|
+
|
|
4
|
+
function visitRequireNode(importNode) {
|
|
5
|
+
if (importNode.expression.kind == ts.SyntaxKind.Identifier &&
|
|
6
|
+
importNode.expression.escapedText == "require") {
|
|
7
|
+
const file = importNode.arguments[0].text;
|
|
8
|
+
if (/\.(less|css|scss|sass|svg|png|html)/.test(file)) {
|
|
9
|
+
const currentFileName = importNode.getSourceFile().fileName;
|
|
10
|
+
const absolute = path_1.join(path_1.dirname(currentFileName), file);
|
|
11
|
+
return ts.updateCall(importNode, importNode.expression, undefined, [ts.createStringLiteral(absolute)]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const lessToStringTransformer = function (context) {
|
|
18
|
+
return (sourceFile) => {
|
|
19
|
+
function visitor(node) {
|
|
20
|
+
// if (node && node.kind == ts.SyntaxKind.ImportDeclaration) {
|
|
21
|
+
// return visitImportNode(node as ts.ImportDeclaration);
|
|
22
|
+
// }
|
|
23
|
+
if (node && ts.isCallExpression(node)) {
|
|
24
|
+
const result = visitRequireNode(node);
|
|
25
|
+
if (result)
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
return ts.visitEachChild(node, visitor, context);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return ts.visitEachChild(sourceFile, visitor, context);
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.default = function (program, pluginOptions) {
|
|
35
|
+
return lessToStringTransformer;
|
|
36
|
+
}
|
package/bin.js
ADDED
package/bundle/bundle.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {getConfig} from "./rollup.config.js";
|
|
2
|
+
import {rollup, watch} from "rollup";
|
|
3
|
+
|
|
4
|
+
export async function bundle(target, ...options) {
|
|
5
|
+
const config = getConfig({
|
|
6
|
+
input: target,
|
|
7
|
+
minify: options.includes('--prop'),
|
|
8
|
+
devServer: options.includes('--run')
|
|
9
|
+
});
|
|
10
|
+
config.onwarn = function (message){
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
if (options.includes('--watch')) {
|
|
14
|
+
const watcher = watch(config);
|
|
15
|
+
watcher.on('event', (event) => {
|
|
16
|
+
switch (event.code){
|
|
17
|
+
case 'START':
|
|
18
|
+
console.clear();
|
|
19
|
+
console.log('START BUNDLING');
|
|
20
|
+
break;
|
|
21
|
+
case 'END':
|
|
22
|
+
console.log('FINISH');
|
|
23
|
+
break;
|
|
24
|
+
case 'BUNDLE_START':
|
|
25
|
+
console.log(`1. ${event.input} -> ${event.output}`);
|
|
26
|
+
break;
|
|
27
|
+
case 'BUNDLE_END':
|
|
28
|
+
console.log(`1. ${event.input} -> ${event.output}, (${event.duration/1000}s)`);
|
|
29
|
+
break;
|
|
30
|
+
|
|
31
|
+
case 'ERROR':
|
|
32
|
+
switch (event.error.code){
|
|
33
|
+
case 'PARSE_ERROR':
|
|
34
|
+
console.warn('Error parsing files:');
|
|
35
|
+
console.log(`\t${event.error.parserError.message}`);
|
|
36
|
+
console.log(`\tat: ${event.error.id}`);
|
|
37
|
+
console.log(`\tline: ${event.error.frame}`);
|
|
38
|
+
break;
|
|
39
|
+
case 'UNRESOLVED_IMPORT':
|
|
40
|
+
console.error(event.error.message);
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
console.warn('Unknown error:', event.error.code);
|
|
44
|
+
console.error(event.error);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
} else {
|
|
51
|
+
const build = await rollup(config);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
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 less from 'rollup-plugin-less';
|
|
6
|
+
import { string } from "rollup-plugin-string";
|
|
7
|
+
import serve from 'rollup-plugin-serve'
|
|
8
|
+
|
|
9
|
+
export const getConfig = ({minify, input, devServer}) => {
|
|
10
|
+
if (minify){
|
|
11
|
+
return {
|
|
12
|
+
input,
|
|
13
|
+
output: {
|
|
14
|
+
file: 'dist/index.min.js',
|
|
15
|
+
format: 'cjs'
|
|
16
|
+
},
|
|
17
|
+
plugins: [
|
|
18
|
+
commonjs(),
|
|
19
|
+
nodeResolve({
|
|
20
|
+
browser: true,
|
|
21
|
+
}),
|
|
22
|
+
terser({
|
|
23
|
+
}),
|
|
24
|
+
visualizer({
|
|
25
|
+
open: true,
|
|
26
|
+
template: 'sunburst',
|
|
27
|
+
brotliSize: true,
|
|
28
|
+
filename: 'dist/stats.html'
|
|
29
|
+
}),
|
|
30
|
+
|
|
31
|
+
]
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return ({
|
|
35
|
+
input,
|
|
36
|
+
output: [
|
|
37
|
+
{
|
|
38
|
+
file: 'dist/index-cjs.js',
|
|
39
|
+
sourcemap: true,
|
|
40
|
+
format: 'cjs',
|
|
41
|
+
exports: 'auto',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
file: 'dist/index-umd.js',
|
|
45
|
+
sourcemap: true,
|
|
46
|
+
format: 'umd',
|
|
47
|
+
name: 'global'
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
file: 'dist/index-es.js',
|
|
51
|
+
sourcemap: true,
|
|
52
|
+
exports: 'auto',
|
|
53
|
+
format: 'es'
|
|
54
|
+
}
|
|
55
|
+
],
|
|
56
|
+
// prettier-ignore
|
|
57
|
+
plugins: [
|
|
58
|
+
nodeResolve({
|
|
59
|
+
browser: true,
|
|
60
|
+
}),
|
|
61
|
+
commonjs({
|
|
62
|
+
|
|
63
|
+
}),
|
|
64
|
+
less({
|
|
65
|
+
insert: true
|
|
66
|
+
}),
|
|
67
|
+
string({
|
|
68
|
+
include: /\.(html|svg)$/,
|
|
69
|
+
}),
|
|
70
|
+
...[devServer ? serve({
|
|
71
|
+
open: false,
|
|
72
|
+
contentBase: ['dist', 'assets'],
|
|
73
|
+
port: 3001,
|
|
74
|
+
historyApiFallback: true
|
|
75
|
+
}) : '']
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export function compile(target, options) {
|
|
4
|
+
const config = {
|
|
5
|
+
declaration: true,
|
|
6
|
+
declarationDir: "dist/typings",
|
|
7
|
+
experimentalDecorators: true,
|
|
8
|
+
emitDecoratorMetadata: true,
|
|
9
|
+
module: ts.ModuleKind.ES2020,
|
|
10
|
+
moduleResolution: ts.ModuleResolutionKind.NodeJs,
|
|
11
|
+
lib: ["lib.es2020.d.ts", "lib.dom.d.ts"],
|
|
12
|
+
noEmitHelpers: false,
|
|
13
|
+
noImplicitAny: true,
|
|
14
|
+
downlevelIteration: true,
|
|
15
|
+
noImplicitOverride: true,
|
|
16
|
+
noImplicitReturns: true,
|
|
17
|
+
outDir: "dist/esm",
|
|
18
|
+
target: ts.ScriptTarget.ES2018
|
|
19
|
+
}
|
|
20
|
+
// Note that there is another overload for `createWatchCompilerHost` that takes
|
|
21
|
+
// a set of root files.
|
|
22
|
+
const host = ts.createWatchCompilerHost(
|
|
23
|
+
[ target ],
|
|
24
|
+
config,
|
|
25
|
+
ts.sys
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
// You can technically override any given hook on the host, though you probably
|
|
29
|
+
// don't need to.
|
|
30
|
+
// Note that we're assuming `origCreateProgram` and `origPostProgramCreate`
|
|
31
|
+
// doesn't use `this` at all.
|
|
32
|
+
const origCreateProgram = host.createProgram;
|
|
33
|
+
host.createProgram = (rootNames, options, host, oldProgram) => {
|
|
34
|
+
console.log("** We're about to create the program! **");
|
|
35
|
+
return origCreateProgram(rootNames, options, host, oldProgram);
|
|
36
|
+
};
|
|
37
|
+
const origPostProgramCreate = host.afterProgramCreate;
|
|
38
|
+
|
|
39
|
+
host.afterProgramCreate = program => {
|
|
40
|
+
console.log("** We finished making the program! **");
|
|
41
|
+
origPostProgramCreate(program);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// `createWatchProgram` creates an initial program, watches files, and updates
|
|
45
|
+
// the program over time.
|
|
46
|
+
ts.createWatchProgram(host);
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@cmmn/tools",
|
|
3
|
+
"version": "1.0.3",
|
|
4
|
+
"description": "di, base extensions, useful functions",
|
|
5
|
+
"main": "dist/rollup.config.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {},
|
|
11
|
+
"bin": {
|
|
12
|
+
"cmmn": "bin.js"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"bin.js",
|
|
16
|
+
"absolute-plugin.cjs",
|
|
17
|
+
"bundle/*",
|
|
18
|
+
"compile/*"
|
|
19
|
+
],
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"typescript": "4.4.3"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@rollup/plugin-commonjs": "^21",
|
|
25
|
+
"@rollup/plugin-node-resolve": "^13",
|
|
26
|
+
"@rollup/plugin-typescript": "^8",
|
|
27
|
+
"rollup": "^2",
|
|
28
|
+
"rollup-plugin-less": "^1.1.3",
|
|
29
|
+
"rollup-plugin-serve": "^1.1.0",
|
|
30
|
+
"rollup-plugin-string": "^3.0.0",
|
|
31
|
+
"rollup-plugin-terser": "^7",
|
|
32
|
+
"rollup-plugin-visualizer": "^5.5.4",
|
|
33
|
+
"typescript": "4.4.3"
|
|
34
|
+
},
|
|
35
|
+
"author": "",
|
|
36
|
+
"license": "ISC",
|
|
37
|
+
"gitHead": "a96e009d45a7e453cb419989710f16f30e5d8290"
|
|
38
|
+
}
|