maishu-scripts 1.2.0 → 1.2.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/out/modules/actions/biel-compile.js +27 -5
- package/out/modules/actions/copy-file.js +28 -2
- package/out/modules/actions/ts-compile.js +29 -7
- package/out/modules/compile.d.ts +2 -2
- package/out/modules/compile.js +48 -12
- package/out/modules/import-path-rewrite.js +25 -2
- package/out/modules/project-compiler.js +32 -6
- package/out/modules/run.d.ts +1 -1
- package/out/modules/run.js +8 -6
- package/package.json +7 -4
- package/src/modules/actions/copy-file.ts +4 -0
- package/src/modules/compile.ts +18 -4
- package/src/modules/project-compiler.ts +1 -1
- package/src/modules/run.ts +3 -3
- package/out/main.js +0 -9
- package/out/modules/compile/biel-compile.d.ts +0 -7
- package/out/modules/compile/biel-compile.js +0 -133
- package/out/modules/compile/ts-compile.d.ts +0 -10
- package/out/modules/compile/ts-compile.js +0 -74
- package/out/start.d.ts +0 -1
- package/out/start.js +0 -9
|
@@ -1,9 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compileFile =
|
|
4
|
-
const babel = require("@babel/core");
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
const path = require("path");
|
|
26
|
+
exports.compileFile = compileFile;
|
|
27
|
+
const babel = __importStar(require("@babel/core"));
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
7
30
|
const errors_1 = require("../errors");
|
|
8
31
|
const project_compiler_1 = require("../project-compiler");
|
|
9
32
|
const outExt = project_compiler_1.ProjectCompiler.tsOutExt;
|
|
@@ -80,7 +103,6 @@ async function compileFile(sourcePath, outputPath, projectPath) {
|
|
|
80
103
|
fs.mkdirSync(outDirPath, { recursive: true });
|
|
81
104
|
fs.writeFileSync(targetPath, r.code);
|
|
82
105
|
}
|
|
83
|
-
exports.compileFile = compileFile;
|
|
84
106
|
function extname(file) {
|
|
85
107
|
// let ext = /\.[a-zA-Z]+/.exec(file)?.[0] || '';
|
|
86
108
|
let ext = path.extname(file);
|
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
const errors_1 = require("../errors");
|
|
4
|
-
const fs = require("fs");
|
|
5
|
-
const path = require("path");
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
6
29
|
let copyFile = (filePath, outPath, projectPath) => {
|
|
7
30
|
if (!filePath)
|
|
8
31
|
throw errors_1.errors.argumentNull("filePath");
|
|
9
32
|
if (!outPath)
|
|
10
33
|
throw errors_1.errors.argumentNull("outPath");
|
|
34
|
+
if (!fs.existsSync(filePath)) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
11
37
|
let out = filePath.replace(path.dirname(filePath), outPath);
|
|
12
38
|
let outDirPath = path.resolve(out, "..");
|
|
13
39
|
fs.mkdirSync(outDirPath, { recursive: true });
|
|
@@ -1,10 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
26
|
+
exports.compileFile = compileFile;
|
|
27
|
+
exports.getTypescriptConfig = getTypescriptConfig;
|
|
28
|
+
exports.findTypeScriptConfigPath = findTypeScriptConfigPath;
|
|
29
|
+
const ts = __importStar(require("typescript"));
|
|
5
30
|
const errors_1 = require("../errors");
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
const path = require("path");
|
|
31
|
+
const fs = __importStar(require("fs"));
|
|
32
|
+
const path = __importStar(require("path"));
|
|
8
33
|
const project_compiler_1 = require("../project-compiler");
|
|
9
34
|
const TS_CONFIG_FILE = 'tsconfig.json';
|
|
10
35
|
/**
|
|
@@ -34,7 +59,6 @@ async function compileFile(filePath, outDir, projectPath) {
|
|
|
34
59
|
fs.mkdirSync(outDirPath, { recursive: true });
|
|
35
60
|
fs.writeFileSync(targetPath, result.outputText);
|
|
36
61
|
}
|
|
37
|
-
exports.compileFile = compileFile;
|
|
38
62
|
function getTypescriptConfig(projectPath, directoryPath) {
|
|
39
63
|
let configPath = findTypeScriptConfigPath(projectPath, directoryPath);
|
|
40
64
|
let compilerOptions;
|
|
@@ -48,7 +72,6 @@ function getTypescriptConfig(projectPath, directoryPath) {
|
|
|
48
72
|
}
|
|
49
73
|
return compilerOptions;
|
|
50
74
|
}
|
|
51
|
-
exports.getTypescriptConfig = getTypescriptConfig;
|
|
52
75
|
function findTypeScriptConfigPath(projectPath, directoryPath) {
|
|
53
76
|
if (!path.isAbsolute(directoryPath)) {
|
|
54
77
|
directoryPath = path.join(projectPath, directoryPath);
|
|
@@ -64,7 +87,6 @@ function findTypeScriptConfigPath(projectPath, directoryPath) {
|
|
|
64
87
|
let parentPath = path.resolve(directoryPath, "..");
|
|
65
88
|
return findTypeScriptConfigPath(projectPath, parentPath);
|
|
66
89
|
}
|
|
67
|
-
exports.findTypeScriptConfigPath = findTypeScriptConfigPath;
|
|
68
90
|
function defaultCompilerOptions() {
|
|
69
91
|
let r = {
|
|
70
92
|
module: ts.ModuleKind.CommonJS,
|
package/out/modules/compile.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** 将 sourceDir 目录下所有文件生成到 outDir */
|
|
2
|
-
export declare function generateCode(sourceDir: string, outDir: string, projectPath: string): void;
|
|
2
|
+
export declare function generateCode(sourceDir: string, outDir: string, projectPath: string, callback?: (filePath: string, outDir: string, projectPath: string) => void): void;
|
|
3
3
|
/** 监听 sourceRoot 目录下所有文件变化,并生成到 outRoot */
|
|
4
|
-
export declare function watchDirectory(sourceRoot: string, outRoot: string, projectPath: string): void;
|
|
4
|
+
export declare function watchDirectory(sourceRoot: string, outRoot: string, projectPath: string, callback?: (filePath: string, outDir: string, projectPath: string) => void): void;
|
|
5
5
|
export declare function isIgnoredFile(filePath: string): boolean;
|
package/out/modules/compile.js
CHANGED
|
@@ -1,21 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
29
|
+
exports.generateCode = generateCode;
|
|
30
|
+
exports.watchDirectory = watchDirectory;
|
|
31
|
+
exports.isIgnoredFile = isIgnoredFile;
|
|
32
|
+
const fs = __importStar(require("fs"));
|
|
33
|
+
const node_watch_1 = __importDefault(require("node-watch"));
|
|
34
|
+
const path = __importStar(require("path"));
|
|
7
35
|
const errors_1 = require("./errors");
|
|
8
36
|
const biel_compile_1 = require("./actions/biel-compile");
|
|
9
|
-
const copy_file_1 = require("./actions/copy-file");
|
|
37
|
+
const copy_file_1 = __importDefault(require("./actions/copy-file"));
|
|
10
38
|
const skipFiles = ["\\S+\\.d\\.tsx?$", "\\S+\\.test\\.tsx?$", "\\S+\\.spec\\.tsx?$"];
|
|
11
|
-
const extCopy = [".js", ".html", ".css", ".jpg", ".png", ".gif"];
|
|
39
|
+
const extCopy = [".js", ".html", ".css", ".jpg", ".png", ".gif", ".scss", ".less"];
|
|
12
40
|
let fileActions = {
|
|
13
41
|
".ts": biel_compile_1.compileFile,
|
|
14
42
|
".tsx": biel_compile_1.compileFile,
|
|
15
43
|
};
|
|
16
44
|
extCopy.forEach(ext => fileActions[ext] = copy_file_1.default);
|
|
17
45
|
/** 将 sourceDir 目录下所有文件生成到 outDir */
|
|
18
|
-
function generateCode(sourceDir, outDir, projectPath) {
|
|
46
|
+
function generateCode(sourceDir, outDir, projectPath, callback) {
|
|
19
47
|
if (!sourceDir)
|
|
20
48
|
throw errors_1.errors.argumentNull("sourceDir");
|
|
21
49
|
if (!outDir)
|
|
@@ -39,6 +67,9 @@ function generateCode(sourceDir, outDir, projectPath) {
|
|
|
39
67
|
let action = fileActions[ext];
|
|
40
68
|
if (action) {
|
|
41
69
|
action(filePath, outDir, projectPath);
|
|
70
|
+
if (callback) {
|
|
71
|
+
callback(filePath, outDir, projectPath);
|
|
72
|
+
}
|
|
42
73
|
}
|
|
43
74
|
}
|
|
44
75
|
let dirs = fs.readdirSync(sourceDir);
|
|
@@ -50,9 +81,8 @@ function generateCode(sourceDir, outDir, projectPath) {
|
|
|
50
81
|
}
|
|
51
82
|
}
|
|
52
83
|
}
|
|
53
|
-
exports.generateCode = generateCode;
|
|
54
84
|
/** 监听 sourceRoot 目录下所有文件变化,并生成到 outRoot */
|
|
55
|
-
function watchDirectory(sourceRoot, outRoot, projectPath) {
|
|
85
|
+
function watchDirectory(sourceRoot, outRoot, projectPath, callback) {
|
|
56
86
|
if (!sourceRoot)
|
|
57
87
|
throw errors_1.errors.argumentNull("sourceRoot");
|
|
58
88
|
if (!outRoot)
|
|
@@ -62,12 +92,19 @@ function watchDirectory(sourceRoot, outRoot, projectPath) {
|
|
|
62
92
|
(0, node_watch_1.default)(sourceRoot, { recursive: true }, async (evt, name) => {
|
|
63
93
|
let action = fileActions[extname(name)];
|
|
64
94
|
let outPath = path.dirname(name).replace(sourceRoot, outRoot);
|
|
65
|
-
if (action) {
|
|
95
|
+
if (!action) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
66
99
|
action(name, outPath, projectPath);
|
|
100
|
+
if (callback)
|
|
101
|
+
callback(name, outPath, projectPath);
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
console.error(e);
|
|
67
105
|
}
|
|
68
106
|
});
|
|
69
107
|
}
|
|
70
|
-
exports.watchDirectory = watchDirectory;
|
|
71
108
|
// export function copyFile(filePath: string, outDir: string) {
|
|
72
109
|
// if (!filePath) throw errors.argumentNull("filePath");
|
|
73
110
|
// if (!outDir) throw errors.argumentNull("outDir");
|
|
@@ -82,7 +119,6 @@ function isIgnoredFile(filePath) {
|
|
|
82
119
|
let isSkip = skipFiles.some(pattern => new RegExp(pattern).test(filePath));
|
|
83
120
|
return isSkip;
|
|
84
121
|
}
|
|
85
|
-
exports.isIgnoredFile = isIgnoredFile;
|
|
86
122
|
function extname(file) {
|
|
87
123
|
// let ext = /\.[a-zA-Z]+/.exec(file)?.[0] || '';
|
|
88
124
|
let ext = path.extname(file);
|
|
@@ -1,8 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.ImportPathRewrite = void 0;
|
|
4
|
-
const path = require("path");
|
|
5
|
-
const fs = require("fs");
|
|
27
|
+
const path = __importStar(require("path"));
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
6
29
|
// const outExt = ".js";
|
|
7
30
|
class ImportPathRewrite {
|
|
8
31
|
filePath;
|
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
29
|
exports.ProjectCompiler = void 0;
|
|
4
|
-
const
|
|
30
|
+
const nodemon_1 = __importDefault(require("nodemon"));
|
|
5
31
|
const errors_1 = require("./errors");
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
const babel = require("@babel/core");
|
|
32
|
+
const fs = __importStar(require("fs"));
|
|
33
|
+
const path = __importStar(require("path"));
|
|
34
|
+
const babel = __importStar(require("@babel/core"));
|
|
9
35
|
const import_path_rewrite_1 = require("./import-path-rewrite");
|
|
10
|
-
const node_watch_1 = require("node-watch");
|
|
36
|
+
const node_watch_1 = __importDefault(require("node-watch"));
|
|
11
37
|
const tsOutExt = ".js";
|
|
12
38
|
class ProjectCompiler {
|
|
13
39
|
projectPath;
|
|
@@ -220,7 +246,7 @@ class ProjectCompiler {
|
|
|
220
246
|
});
|
|
221
247
|
}
|
|
222
248
|
run() {
|
|
223
|
-
|
|
249
|
+
(0, nodemon_1.default)({
|
|
224
250
|
script: `./${this.outputDirectoryName}/main.js`,
|
|
225
251
|
watch: [`./${this.outputDirectoryName}/`],
|
|
226
252
|
});
|
package/out/modules/run.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function run(
|
|
1
|
+
export declare function run(): void;
|
package/out/modules/run.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.run =
|
|
4
|
-
const
|
|
5
|
-
function run(
|
|
6
|
-
|
|
6
|
+
exports.run = run;
|
|
7
|
+
const nodemon_1 = __importDefault(require("nodemon"));
|
|
8
|
+
function run() {
|
|
9
|
+
(0, nodemon_1.default)({
|
|
7
10
|
script: "./out/main.js", //!args ? "./out/main.js" : "./out/main.js " + args,
|
|
8
11
|
watch: ["./out/"],
|
|
9
|
-
|
|
12
|
+
ignoreRoot: ['./out/static/'],
|
|
10
13
|
});
|
|
11
14
|
}
|
|
12
|
-
exports.run = run;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "maishu-scripts",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "用于对 node 项目进行代码生成,打包,运行",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@babel/core": "^7.24.3",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"babel-plugin-transform-typescript-metadata": "^0.3.2",
|
|
12
12
|
"maishu-toolkit": "^1.12.6",
|
|
13
13
|
"node-watch": "^0.7.4",
|
|
14
|
-
"nodemon": "^3.1.
|
|
14
|
+
"nodemon": "^3.1.4",
|
|
15
15
|
"typescript": "^5.4.5"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
@@ -25,5 +25,8 @@
|
|
|
25
25
|
"files": [
|
|
26
26
|
"out",
|
|
27
27
|
"src"
|
|
28
|
-
]
|
|
29
|
-
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -7,6 +7,10 @@ let copyFile: FileAction = (filePath: string, outPath: string, projectPath: stri
|
|
|
7
7
|
if (!filePath) throw errors.argumentNull("filePath");
|
|
8
8
|
if (!outPath) throw errors.argumentNull("outPath");
|
|
9
9
|
|
|
10
|
+
if (!fs.existsSync(filePath)) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
let out = filePath.replace(path.dirname(filePath), outPath);
|
|
11
15
|
let outDirPath = path.resolve(out, "..");
|
|
12
16
|
|
package/src/modules/compile.ts
CHANGED
|
@@ -7,7 +7,7 @@ import copyFile from "./actions/copy-file";
|
|
|
7
7
|
import { FileAction } from "../types";
|
|
8
8
|
|
|
9
9
|
const skipFiles = ["\\S+\\.d\\.tsx?$", "\\S+\\.test\\.tsx?$", "\\S+\\.spec\\.tsx?$"]
|
|
10
|
-
const extCopy = [".js", ".html", ".css", ".jpg", ".png", ".gif"];
|
|
10
|
+
const extCopy = [".js", ".html", ".css", ".jpg", ".png", ".gif", ".scss", ".less"];
|
|
11
11
|
|
|
12
12
|
let fileActions: { [ext: string]: FileAction } = {
|
|
13
13
|
".ts": bielCompileFile,
|
|
@@ -17,7 +17,9 @@ let fileActions: { [ext: string]: FileAction } = {
|
|
|
17
17
|
extCopy.forEach(ext => fileActions[ext] = copyFile);
|
|
18
18
|
|
|
19
19
|
/** 将 sourceDir 目录下所有文件生成到 outDir */
|
|
20
|
-
export function generateCode(sourceDir: string, outDir: string, projectPath: string
|
|
20
|
+
export function generateCode(sourceDir: string, outDir: string, projectPath: string,
|
|
21
|
+
callback?: (filePath: string, outDir: string, projectPath: string) => void
|
|
22
|
+
) {
|
|
21
23
|
|
|
22
24
|
if (!sourceDir) throw errors.argumentNull("sourceDir");
|
|
23
25
|
if (!outDir) throw errors.argumentNull("outDir");
|
|
@@ -43,6 +45,9 @@ export function generateCode(sourceDir: string, outDir: string, projectPath: str
|
|
|
43
45
|
let action = fileActions[ext];
|
|
44
46
|
if (action) {
|
|
45
47
|
action(filePath, outDir, projectPath);
|
|
48
|
+
if (callback) {
|
|
49
|
+
callback(filePath, outDir, projectPath);
|
|
50
|
+
}
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
|
|
@@ -57,7 +62,7 @@ export function generateCode(sourceDir: string, outDir: string, projectPath: str
|
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
/** 监听 sourceRoot 目录下所有文件变化,并生成到 outRoot */
|
|
60
|
-
export function watchDirectory(sourceRoot: string, outRoot: string, projectPath: string) {
|
|
65
|
+
export function watchDirectory(sourceRoot: string, outRoot: string, projectPath: string, callback?: (filePath: string, outDir: string, projectPath: string) => void) {
|
|
61
66
|
if (!sourceRoot) throw errors.argumentNull("sourceRoot");
|
|
62
67
|
if (!outRoot) throw errors.argumentNull("outRoot");
|
|
63
68
|
if (!projectPath) throw errors.argumentNull("projectPath");
|
|
@@ -65,8 +70,17 @@ export function watchDirectory(sourceRoot: string, outRoot: string, projectPath:
|
|
|
65
70
|
watch(sourceRoot, { recursive: true }, async (evt, name) => {
|
|
66
71
|
let action = fileActions[extname(name)];
|
|
67
72
|
let outPath = path.dirname(name).replace(sourceRoot, outRoot);
|
|
68
|
-
if (action) {
|
|
73
|
+
if (!action) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
try {
|
|
69
78
|
action(name, outPath, projectPath);
|
|
79
|
+
if (callback)
|
|
80
|
+
callback(name, outPath, projectPath);
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
console.error(e);
|
|
70
84
|
}
|
|
71
85
|
})
|
|
72
86
|
}
|
package/src/modules/run.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import nodemon from "nodemon";
|
|
2
2
|
|
|
3
|
-
export function run(
|
|
3
|
+
export function run() {
|
|
4
4
|
nodemon({
|
|
5
5
|
script: "./out/main.js",//!args ? "./out/main.js" : "./out/main.js " + args,
|
|
6
6
|
watch: ["./out/"],
|
|
7
|
-
|
|
7
|
+
ignoreRoot: ['./out/static/'],
|
|
8
8
|
})
|
|
9
9
|
}
|
package/out/main.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const core_1 = require("@nestjs/core");
|
|
4
|
-
const app_module_1 = require("./app.module");
|
|
5
|
-
async function bootstrap() {
|
|
6
|
-
const app = await core_1.NestFactory.create(app_module_1.AppModule);
|
|
7
|
-
await app.listen(3000);
|
|
8
|
-
}
|
|
9
|
-
bootstrap();
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compileFile = void 0;
|
|
4
|
-
const babel = require("@babel/core");
|
|
5
|
-
const fs = require("fs");
|
|
6
|
-
const path = require("path");
|
|
7
|
-
const errors_1 = require("../errors");
|
|
8
|
-
const project_compiler_1 = require("../project-compiler");
|
|
9
|
-
const outExt = project_compiler_1.ProjectCompiler.tsOutExt;
|
|
10
|
-
/**
|
|
11
|
-
* 编译特定文件,并生成到制定目录
|
|
12
|
-
* @param sourcePath 源文件路径
|
|
13
|
-
* @param outDir 输出目录
|
|
14
|
-
* @param projectPath 项目路径
|
|
15
|
-
* */
|
|
16
|
-
async function compileFile(sourcePath, outDir, projectPath) {
|
|
17
|
-
if (!sourcePath)
|
|
18
|
-
throw errors_1.errors.argumentNull("sourcePath");
|
|
19
|
-
if (!outDir)
|
|
20
|
-
throw errors_1.errors.argumentNull("outDir");
|
|
21
|
-
if (!projectPath)
|
|
22
|
-
throw errors_1.errors.argumentNull("projectPath");
|
|
23
|
-
// if (!fs.existsSync(sourcePath)) throw errors.pathNotExists(sourcePath);
|
|
24
|
-
if (!fs.existsSync(sourcePath)) {
|
|
25
|
-
console.warn(`Path not exists: ${sourcePath}`);
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
let sourceDir = path.dirname(sourcePath);
|
|
29
|
-
let babelOptions;
|
|
30
|
-
let bablePath;
|
|
31
|
-
//= projectPath ?
|
|
32
|
-
// ProjectCompiler.getBabelConfig(projectPath, sourceDir) : ProjectCompiler.getDefaultBabelConfig();
|
|
33
|
-
if (projectPath) {
|
|
34
|
-
let c = project_compiler_1.ProjectCompiler.getBabelConfig(projectPath, sourceDir);
|
|
35
|
-
bablePath = c.path;
|
|
36
|
-
babelOptions = c.options;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
babelOptions = project_compiler_1.ProjectCompiler.getDefaultBabelConfig();
|
|
40
|
-
bablePath = '';
|
|
41
|
-
}
|
|
42
|
-
babelOptions.filename = sourcePath;
|
|
43
|
-
babelOptions.code = false;
|
|
44
|
-
babelOptions.ast = true;
|
|
45
|
-
// let fileResult = babel.transformFileSync(sourcePath, {
|
|
46
|
-
// filename: sourcePath, code: false, ast: true, plugins,
|
|
47
|
-
// presets
|
|
48
|
-
// });
|
|
49
|
-
let fileResult = babel.transformFileSync(sourcePath, babelOptions);
|
|
50
|
-
if (!fileResult)
|
|
51
|
-
throw errors_1.errors.compileError(sourcePath);
|
|
52
|
-
let ast = fileResult.ast;
|
|
53
|
-
if (!ast)
|
|
54
|
-
throw errors_1.errors.compileError(sourcePath);
|
|
55
|
-
new ImportPathRewrite(sourcePath, ast);
|
|
56
|
-
let r = babel.transformFromAstSync(ast, undefined, {
|
|
57
|
-
filename: sourcePath, plugins: babelOptions.plugins,
|
|
58
|
-
presets: babelOptions.presets, sourceMaps: true
|
|
59
|
-
});
|
|
60
|
-
if (!r || r.code == null)
|
|
61
|
-
throw errors_1.errors.compileError(sourcePath);
|
|
62
|
-
let ext = extname(sourcePath);
|
|
63
|
-
let outExt = fileOutExt(sourcePath);
|
|
64
|
-
let targetPath = path.join(outDir, path.basename(sourcePath).replace(ext, outExt)); //sourcePath.replace(new RegExp(ext + "$"), outExt).replace(path.dirname(sourcePath), outDir);
|
|
65
|
-
let outDirPath = path.resolve(targetPath, "..");
|
|
66
|
-
if (r.map) {
|
|
67
|
-
r.map.file = path.basename(targetPath);
|
|
68
|
-
let sources = r.map.sources || [];
|
|
69
|
-
let sourceDir = path.dirname(sourcePath);
|
|
70
|
-
sources.forEach((s, i) => {
|
|
71
|
-
sources[i] = path.relative(outDirPath, path.join(sourceDir, s));
|
|
72
|
-
});
|
|
73
|
-
r.map.sources = sources;
|
|
74
|
-
let mapPath = targetPath + ".map";
|
|
75
|
-
if (!fs.existsSync(outDirPath))
|
|
76
|
-
fs.mkdirSync(outDirPath, { recursive: true });
|
|
77
|
-
fs.writeFileSync(mapPath, JSON.stringify(r.map));
|
|
78
|
-
r.code += `\n//babel file path = ${bablePath}`;
|
|
79
|
-
r.code += "\n//# sourceMappingURL=" + path.basename(mapPath);
|
|
80
|
-
}
|
|
81
|
-
if (!fs.existsSync(outDirPath))
|
|
82
|
-
fs.mkdirSync(outDirPath, { recursive: true });
|
|
83
|
-
fs.writeFileSync(targetPath, r.code);
|
|
84
|
-
}
|
|
85
|
-
exports.compileFile = compileFile;
|
|
86
|
-
function extname(file) {
|
|
87
|
-
// let ext = /\.[a-zA-Z]+/.exec(file)?.[0] || '';
|
|
88
|
-
let ext = path.extname(file);
|
|
89
|
-
return ext;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* 获取源文件所对应生成文件的扩展名
|
|
93
|
-
* @param file 源文件名
|
|
94
|
-
* */
|
|
95
|
-
function fileOutExt(file) {
|
|
96
|
-
let ext = extname(file);
|
|
97
|
-
if (ext === ".ts")
|
|
98
|
-
return outExt;
|
|
99
|
-
if (ext === ".tsx")
|
|
100
|
-
return outExt;
|
|
101
|
-
return ext;
|
|
102
|
-
}
|
|
103
|
-
class ImportPathRewrite {
|
|
104
|
-
filePath;
|
|
105
|
-
constructor(filePath, node) {
|
|
106
|
-
this.filePath = filePath;
|
|
107
|
-
this.traverse(node);
|
|
108
|
-
}
|
|
109
|
-
traverse(node) {
|
|
110
|
-
switch (node.type) {
|
|
111
|
-
case "Program":
|
|
112
|
-
node.body.forEach(c => this.traverse(c));
|
|
113
|
-
break;
|
|
114
|
-
case "File":
|
|
115
|
-
this.traverse(node.program);
|
|
116
|
-
break;
|
|
117
|
-
case "ImportDeclaration":
|
|
118
|
-
if (node.source.type === "StringLiteral" && node.source.value.startsWith(".")) {
|
|
119
|
-
let ext = extname(node.source.value);
|
|
120
|
-
if (ext != outExt) {
|
|
121
|
-
let dir = path.dirname(this.filePath);
|
|
122
|
-
let fullPath = path.join(dir, node.source.value);
|
|
123
|
-
console.log(`ImportDeclaration: ${fullPath} -> ${ext}`);
|
|
124
|
-
if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
|
|
125
|
-
node.source.value = node.source.value + "/index";
|
|
126
|
-
}
|
|
127
|
-
node.source.value += outExt;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import * as ts from 'typescript';
|
|
2
|
-
/**
|
|
3
|
-
* 编译特定文件,并生成到制定目录
|
|
4
|
-
* @param filePath 源文件路径,绝对路径
|
|
5
|
-
* @param outDir 输出目录,相对于项目路径
|
|
6
|
-
* @param projectPath 项目路径,绝对路径
|
|
7
|
-
* */
|
|
8
|
-
export declare function compileFile(filePath: string, outDir: string, projectPath: string): Promise<void>;
|
|
9
|
-
export declare function getTypescriptConfig(projectPath: string, directoryPath: string): ts.CompilerOptions;
|
|
10
|
-
export declare function findTypeScriptConfigPath(projectPath: string, directoryPath: string): string | null;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.findTypeScriptConfigPath = exports.getTypescriptConfig = exports.compileFile = void 0;
|
|
4
|
-
const ts = require("typescript");
|
|
5
|
-
const errors_1 = require("../errors");
|
|
6
|
-
const fs = require("fs");
|
|
7
|
-
const path = require("path");
|
|
8
|
-
const project_compiler_1 = require("../project-compiler");
|
|
9
|
-
const TS_CONFIG_FILE = 'tsconfig.json';
|
|
10
|
-
/**
|
|
11
|
-
* 编译特定文件,并生成到制定目录
|
|
12
|
-
* @param filePath 源文件路径,绝对路径
|
|
13
|
-
* @param outDir 输出目录,相对于项目路径
|
|
14
|
-
* @param projectPath 项目路径,绝对路径
|
|
15
|
-
* */
|
|
16
|
-
async function compileFile(filePath, outDir, projectPath) {
|
|
17
|
-
if (!filePath)
|
|
18
|
-
throw errors_1.errors.argumentNull('sourcePath');
|
|
19
|
-
if (!outDir)
|
|
20
|
-
throw errors_1.errors.argumentNull('outDir');
|
|
21
|
-
if (!projectPath)
|
|
22
|
-
throw errors_1.errors.argumentNull('projectPath');
|
|
23
|
-
if (!path.isAbsolute(filePath))
|
|
24
|
-
throw errors_1.errors.notAbsolutePath(filePath);
|
|
25
|
-
let content = fs.readFileSync(filePath, 'utf-8');
|
|
26
|
-
let compilerOptions = getTypescriptConfig(projectPath, path.dirname(filePath));
|
|
27
|
-
let result = ts.transpileModule(content, { compilerOptions });
|
|
28
|
-
console.log(result.outputText);
|
|
29
|
-
let ext = path.extname(filePath);
|
|
30
|
-
let outExt = project_compiler_1.ProjectCompiler.tsOutExt;
|
|
31
|
-
let targetPath = path.join(projectPath, outDir, path.basename(filePath).replace(ext, outExt));
|
|
32
|
-
let outDirPath = path.resolve(targetPath, "..");
|
|
33
|
-
if (!fs.existsSync(outDirPath))
|
|
34
|
-
fs.mkdirSync(outDirPath, { recursive: true });
|
|
35
|
-
fs.writeFileSync(targetPath, result.outputText);
|
|
36
|
-
}
|
|
37
|
-
exports.compileFile = compileFile;
|
|
38
|
-
function getTypescriptConfig(projectPath, directoryPath) {
|
|
39
|
-
let configPath = findTypeScriptConfigPath(projectPath, directoryPath);
|
|
40
|
-
let compilerOptions;
|
|
41
|
-
if (!configPath) {
|
|
42
|
-
compilerOptions = defaultCompilerOptions();
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
let configContent = fs.readFileSync(configPath, 'utf-8');
|
|
46
|
-
let config = JSON.parse(configContent);
|
|
47
|
-
compilerOptions = config.compilerOptions;
|
|
48
|
-
}
|
|
49
|
-
return compilerOptions;
|
|
50
|
-
}
|
|
51
|
-
exports.getTypescriptConfig = getTypescriptConfig;
|
|
52
|
-
function findTypeScriptConfigPath(projectPath, directoryPath) {
|
|
53
|
-
if (!path.isAbsolute(directoryPath)) {
|
|
54
|
-
directoryPath = path.join(projectPath, directoryPath);
|
|
55
|
-
}
|
|
56
|
-
console.assert(path.isAbsolute(projectPath), `projectPath ${projectPath} is not absolute`);
|
|
57
|
-
console.assert(path.isAbsolute(directoryPath), `directoryPath ${directoryPath} is not absolute`);
|
|
58
|
-
let tsConfigPath = path.join(directoryPath, TS_CONFIG_FILE);
|
|
59
|
-
if (fs.existsSync(tsConfigPath)) {
|
|
60
|
-
return tsConfigPath;
|
|
61
|
-
}
|
|
62
|
-
if (projectPath == directoryPath)
|
|
63
|
-
return null;
|
|
64
|
-
let parentPath = path.resolve(directoryPath, "..");
|
|
65
|
-
return findTypeScriptConfigPath(projectPath, parentPath);
|
|
66
|
-
}
|
|
67
|
-
exports.findTypeScriptConfigPath = findTypeScriptConfigPath;
|
|
68
|
-
function defaultCompilerOptions() {
|
|
69
|
-
let r = {
|
|
70
|
-
module: ts.ModuleKind.CommonJS,
|
|
71
|
-
target: ts.ScriptTarget.ESNext,
|
|
72
|
-
};
|
|
73
|
-
return r;
|
|
74
|
-
}
|
package/out/start.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/out/start.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const compile_1 = require("./modules/compile");
|
|
4
|
-
const run_1 = require("./modules/run");
|
|
5
|
-
let sourceDir = "src";
|
|
6
|
-
let outDir = "out";
|
|
7
|
-
(0, compile_1.generateCode)(sourceDir, outDir);
|
|
8
|
-
(0, compile_1.watchDirectory)(sourceDir, outDir);
|
|
9
|
-
(0, run_1.run)();
|