@cabloy/cli 3.0.67 → 3.0.68
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/dist/index.js +1615 -6
- package/dist/lib/local.common.d.ts +2 -0
- package/dist/types/template.d.ts +1 -0
- package/package.json +6 -7
- package/dist/config.js +0 -38
- package/dist/lib/bean.cli.base.js +0 -144
- package/dist/lib/bean.cli.js +0 -33
- package/dist/lib/cli.js +0 -217
- package/dist/lib/commands.js +0 -52
- package/dist/lib/index.js +0 -7
- package/dist/lib/local.common.js +0 -149
- package/dist/lib/local.console.js +0 -44
- package/dist/lib/local.helper.js +0 -329
- package/dist/lib/local.template.js +0 -291
- package/dist/registry.js +0 -14
- package/dist/start.js +0 -93
- package/dist/types/argv.js +0 -1
- package/dist/types/console.js +0 -1
- package/dist/types/helper.js +0 -1
- package/dist/types/index.js +0 -4
- package/dist/types/template.js +0 -3
- package/dist/utils.js +0 -46
package/dist/lib/local.common.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import fse from 'fs-extra';
|
|
3
|
-
export class LocalCommon {
|
|
4
|
-
cli;
|
|
5
|
-
constructor(cli) {
|
|
6
|
-
this.cli = cli;
|
|
7
|
-
}
|
|
8
|
-
async _generateTypeModulesFile(projectPath) {
|
|
9
|
-
const pathName = this.cli.context.brandName === 'zova' ? 'front' : 'backend';
|
|
10
|
-
const typeFile = path.join(projectPath, `src/${pathName}/typing/modules.d.ts`);
|
|
11
|
-
let content = '';
|
|
12
|
-
// // all suites
|
|
13
|
-
// for (const key in this.modulesMeta.suites) {
|
|
14
|
-
// const suite = this.modulesMeta.suites[key];
|
|
15
|
-
// content += `import '${suite.package.name}';\n`;
|
|
16
|
-
// }
|
|
17
|
-
// all modules
|
|
18
|
-
this.cli.modulesMeta.modulesArray.forEach(module => {
|
|
19
|
-
content += `import '${module.package.name}';\n`;
|
|
20
|
-
});
|
|
21
|
-
await fse.writeFile(typeFile, content);
|
|
22
|
-
// all modules: type file
|
|
23
|
-
for (const module of this.cli.modulesMeta.modulesArray) {
|
|
24
|
-
if (module.info.node_modules)
|
|
25
|
-
continue;
|
|
26
|
-
const moduleTypeFile = path.join(module.root, 'src/.metadata/modules.d.ts');
|
|
27
|
-
let needCreate = true;
|
|
28
|
-
if (fse.existsSync(moduleTypeFile)) {
|
|
29
|
-
try {
|
|
30
|
-
const realFile = await fse.readlink(moduleTypeFile);
|
|
31
|
-
if (realFile === typeFile) {
|
|
32
|
-
needCreate = false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
catch (_err) { }
|
|
36
|
-
}
|
|
37
|
-
if (needCreate) {
|
|
38
|
-
await fse.remove(moduleTypeFile);
|
|
39
|
-
await fse.ensureSymlink(typeFile, moduleTypeFile);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
async _generatePackageJson(projectPath) {
|
|
44
|
-
const pkgFile = path.join(projectPath, 'package.json');
|
|
45
|
-
const pkgOriginalFile = path.join(projectPath, 'package.original.json');
|
|
46
|
-
// check original
|
|
47
|
-
if (!fse.existsSync(pkgOriginalFile)) {
|
|
48
|
-
await fse.copyFile(pkgFile, pkgOriginalFile);
|
|
49
|
-
}
|
|
50
|
-
// prepare deps
|
|
51
|
-
const { deps, depsDev } = await this._generatePackageJson_prepareDeps(projectPath);
|
|
52
|
-
// pkg/pkgOriginal
|
|
53
|
-
const pkgOriginal = await this.cli.helper.loadJSONFile(pkgOriginalFile);
|
|
54
|
-
if (fse.existsSync(pkgFile)) {
|
|
55
|
-
const pkg = await this.cli.helper.loadJSONFile(pkgFile);
|
|
56
|
-
// save back
|
|
57
|
-
await this._generatePackageJson_saveBack(pkg, pkgOriginal, pkgOriginalFile, deps, depsDev);
|
|
58
|
-
}
|
|
59
|
-
// generate pkg from pkgOriginal
|
|
60
|
-
await this._generatePackageJson_pkgFromPkgOriginal(pkgOriginal, pkgFile, deps, depsDev);
|
|
61
|
-
}
|
|
62
|
-
async _generatePackageJson_prepareDeps(_projectPath) {
|
|
63
|
-
const deps = {};
|
|
64
|
-
const depsDev = {};
|
|
65
|
-
// all modules
|
|
66
|
-
this.cli.modulesMeta.modulesArray.forEach(module => {
|
|
67
|
-
const onlyDev = _checkIfModuleOnlyDev(module);
|
|
68
|
-
const version = module.info.node_modules ? `^${module.package.version}` : 'workspace:^';
|
|
69
|
-
if (onlyDev) {
|
|
70
|
-
depsDev[module.package.name] = version;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
deps[module.package.name] = version;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
// all globalDependencies of modules
|
|
77
|
-
this.cli.modulesMeta.modulesArray.forEach(module => {
|
|
78
|
-
_collectModuleDevs(module, deps, 'dependencies', 'globalDependencies');
|
|
79
|
-
_collectModuleDevs(module, depsDev, 'devDependencies', 'globalDependenciesDev');
|
|
80
|
-
});
|
|
81
|
-
return { deps, depsDev };
|
|
82
|
-
}
|
|
83
|
-
async _generatePackageJson_pkgFromPkgOriginal(pkgOriginal, pkgFile, deps, depsDev) {
|
|
84
|
-
function _handleDeps(nameDependencies, deps) {
|
|
85
|
-
for (const key in deps) {
|
|
86
|
-
const version = deps[key];
|
|
87
|
-
if (!pkgOriginal[nameDependencies][key]) {
|
|
88
|
-
pkgOriginal[nameDependencies][key] = version;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
_handleDeps('dependencies', deps);
|
|
93
|
-
_handleDeps('devDependencies', depsDev);
|
|
94
|
-
await this.cli.helper.saveJSONFile(pkgFile, pkgOriginal);
|
|
95
|
-
}
|
|
96
|
-
async _generatePackageJson_saveBack(pkg, pkgOriginal, pkgOriginalFile, deps, depsDev) {
|
|
97
|
-
let changed = false;
|
|
98
|
-
for (const key of ['version', 'gitHead']) {
|
|
99
|
-
if (pkgOriginal[key] !== pkg[key]) {
|
|
100
|
-
pkgOriginal[key] = pkg[key];
|
|
101
|
-
changed = true;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
function _handleDeps(nameDependencies, deps) {
|
|
105
|
-
const moduleDeps = pkg[nameDependencies];
|
|
106
|
-
const moduleDepsOriginal = pkgOriginal[nameDependencies];
|
|
107
|
-
for (const key in moduleDeps) {
|
|
108
|
-
const version = moduleDeps[key];
|
|
109
|
-
if (moduleDepsOriginal[key] && moduleDepsOriginal[key] === version)
|
|
110
|
-
continue;
|
|
111
|
-
const isModule = key.includes('vona-module-') || key.includes('zova-module-');
|
|
112
|
-
const isModuleWorkspace = isModule && version.startsWith('workspace:');
|
|
113
|
-
if (isModuleWorkspace)
|
|
114
|
-
continue;
|
|
115
|
-
if (deps[key] && !isModule)
|
|
116
|
-
continue;
|
|
117
|
-
moduleDepsOriginal[key] = version;
|
|
118
|
-
changed = true;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
_handleDeps('dependencies', deps);
|
|
122
|
-
_handleDeps('devDependencies', depsDev);
|
|
123
|
-
if (changed) {
|
|
124
|
-
await this.cli.helper.saveJSONFile(pkgOriginalFile, pkgOriginal);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function _checkIfModuleOnlyDev(module) {
|
|
129
|
-
const meta = module.package.vonaModule?.capabilities?.meta || module.package.zovaModule?.capabilities?.meta;
|
|
130
|
-
if (!meta || !meta.mode)
|
|
131
|
-
return false;
|
|
132
|
-
const modes = Array.isArray(meta.mode) ? meta.mode : [meta.mode];
|
|
133
|
-
return !modes.some(mode => ['prod', 'production'].includes(mode));
|
|
134
|
-
}
|
|
135
|
-
function _collectModuleDevs(module, deps, nameDependencies, nameGlobalDependencies) {
|
|
136
|
-
const moduleDeps = module.package[nameDependencies];
|
|
137
|
-
const globalDependencies = module.package.vonaModule?.[nameGlobalDependencies] || module.package.zovaModule?.[nameGlobalDependencies];
|
|
138
|
-
if (globalDependencies) {
|
|
139
|
-
for (const key in globalDependencies) {
|
|
140
|
-
let version = globalDependencies[key];
|
|
141
|
-
if (version !== false) {
|
|
142
|
-
if (version === true)
|
|
143
|
-
version = moduleDeps[key];
|
|
144
|
-
deps[key] = version;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return deps;
|
|
149
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
export class LocalConsole {
|
|
2
|
-
cli;
|
|
3
|
-
constructor(cli) {
|
|
4
|
-
this.cli = cli;
|
|
5
|
-
}
|
|
6
|
-
get options() {
|
|
7
|
-
return this.cli.options;
|
|
8
|
-
}
|
|
9
|
-
get context() {
|
|
10
|
-
return this.cli.options.context;
|
|
11
|
-
}
|
|
12
|
-
async log(data, options = {}) {
|
|
13
|
-
if (!data)
|
|
14
|
-
return;
|
|
15
|
-
// data
|
|
16
|
-
if (typeof data !== 'object') {
|
|
17
|
-
data = { text: String(data) };
|
|
18
|
-
}
|
|
19
|
-
let { /* progressNo, */ total, progress, text } = data;
|
|
20
|
-
// logPrefix
|
|
21
|
-
const logPrefix = options.logPrefix;
|
|
22
|
-
if (logPrefix) {
|
|
23
|
-
text = this._adjustText(logPrefix, text);
|
|
24
|
-
}
|
|
25
|
-
// fallback
|
|
26
|
-
if (!this.cli.terminal) {
|
|
27
|
-
if (total !== undefined && progress !== undefined) {
|
|
28
|
-
const progressValid = progress >= 0;
|
|
29
|
-
const progressText = `(${progressValid ? progress + 1 : '-'}/${total})`;
|
|
30
|
-
if (progressValid) {
|
|
31
|
-
text = this._adjustText(`${progressText}=> `, text);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// eslint-disable-next-line
|
|
35
|
-
console.log(text);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
_adjustText(prefix, text) {
|
|
39
|
-
return String(text)
|
|
40
|
-
.split('\n')
|
|
41
|
-
.map(item => (item ? prefix + item : item))
|
|
42
|
-
.join('\n');
|
|
43
|
-
}
|
|
44
|
-
}
|
package/dist/lib/local.helper.js
DELETED
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
-
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
-
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
-
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
return path;
|
|
8
|
-
};
|
|
9
|
-
import { createRequire } from 'node:module';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
import { pathToFileURL } from 'node:url';
|
|
12
|
-
import * as ModuleInfo from '@cabloy/module-info';
|
|
13
|
-
import { ProcessHelper } from '@cabloy/process-helper';
|
|
14
|
-
import { combineResourceName } from '@cabloy/utils';
|
|
15
|
-
import Boxen from 'boxen';
|
|
16
|
-
import Chalk from 'chalk';
|
|
17
|
-
import TableClass from 'cli-table3';
|
|
18
|
-
import fse from 'fs-extra';
|
|
19
|
-
import gogocode from 'gogocode';
|
|
20
|
-
import tmp from 'tmp';
|
|
21
|
-
import { commandsConfig } from "../config.js";
|
|
22
|
-
import { getRegistry } from "../registry.js";
|
|
23
|
-
export class LocalHelper {
|
|
24
|
-
cli;
|
|
25
|
-
processHelper;
|
|
26
|
-
constructor(cli) {
|
|
27
|
-
this.cli = cli;
|
|
28
|
-
this.processHelper = new ProcessHelper(this.cwd, this.console);
|
|
29
|
-
}
|
|
30
|
-
get options() {
|
|
31
|
-
return this.cli.options;
|
|
32
|
-
}
|
|
33
|
-
get context() {
|
|
34
|
-
return this.cli.options.context;
|
|
35
|
-
}
|
|
36
|
-
get console() {
|
|
37
|
-
return this.cli.console;
|
|
38
|
-
}
|
|
39
|
-
get template() {
|
|
40
|
-
return this.cli.template;
|
|
41
|
-
}
|
|
42
|
-
get moduleConfig() {
|
|
43
|
-
return commandsConfig;
|
|
44
|
-
}
|
|
45
|
-
get chalk() {
|
|
46
|
-
return this.newChalk();
|
|
47
|
-
}
|
|
48
|
-
get Table() {
|
|
49
|
-
return TableClass;
|
|
50
|
-
}
|
|
51
|
-
get cwd() {
|
|
52
|
-
return this.context.argv.projectPath;
|
|
53
|
-
}
|
|
54
|
-
newChalk(options) {
|
|
55
|
-
if (!options) {
|
|
56
|
-
options = this.moduleConfig.helper.chalk.options;
|
|
57
|
-
}
|
|
58
|
-
return new Chalk.Instance(options);
|
|
59
|
-
}
|
|
60
|
-
newTable(options) {
|
|
61
|
-
return new TableClass(options);
|
|
62
|
-
}
|
|
63
|
-
boxen({ text, options }) {
|
|
64
|
-
if (!options) {
|
|
65
|
-
options = this.moduleConfig.helper.boxen.options;
|
|
66
|
-
}
|
|
67
|
-
return Boxen(text, options);
|
|
68
|
-
}
|
|
69
|
-
gogocode(sourceCode, options) {
|
|
70
|
-
return gogocode(sourceCode, options);
|
|
71
|
-
}
|
|
72
|
-
firstCharToLowerCase(name) {
|
|
73
|
-
return name.charAt(0).toLowerCase() + name.substring(1);
|
|
74
|
-
}
|
|
75
|
-
firstCharToUpperCase(name) {
|
|
76
|
-
return name.charAt(0).toUpperCase() + name.substring(1);
|
|
77
|
-
}
|
|
78
|
-
stringToCapitalize(str, separator) {
|
|
79
|
-
if (typeof str === 'string')
|
|
80
|
-
str = str.split(separator);
|
|
81
|
-
return str
|
|
82
|
-
.map(name => {
|
|
83
|
-
return this.firstCharToUpperCase(name);
|
|
84
|
-
})
|
|
85
|
-
.join('');
|
|
86
|
-
}
|
|
87
|
-
slashPrefixForPath(count) {
|
|
88
|
-
if (count === 0)
|
|
89
|
-
return './';
|
|
90
|
-
return '../'.repeat(count);
|
|
91
|
-
}
|
|
92
|
-
parseNameMeta(name, ignores) {
|
|
93
|
-
const original = name;
|
|
94
|
-
const parts = original.split('/');
|
|
95
|
-
const directory = parts.slice(0, parts.length - 1).join('/');
|
|
96
|
-
const short = parts[parts.length - 1];
|
|
97
|
-
const shortCapitalize = this.firstCharToUpperCase(short);
|
|
98
|
-
let partsFull;
|
|
99
|
-
if (ignores && parts.length > 1 && ignores.includes(parts[0])) {
|
|
100
|
-
partsFull = parts.slice(1);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
partsFull = parts;
|
|
104
|
-
}
|
|
105
|
-
if (partsFull.length > 1 && partsFull[0] === partsFull[1]) {
|
|
106
|
-
partsFull = partsFull.slice(1);
|
|
107
|
-
}
|
|
108
|
-
const fullCapitalize = this.stringToCapitalize(partsFull, '/');
|
|
109
|
-
const full = this.firstCharToLowerCase(fullCapitalize);
|
|
110
|
-
return {
|
|
111
|
-
original,
|
|
112
|
-
parts,
|
|
113
|
-
directory,
|
|
114
|
-
short,
|
|
115
|
-
shortCapitalize,
|
|
116
|
-
full,
|
|
117
|
-
fullCapitalize,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
parseModuleInfo(moduleName) {
|
|
121
|
-
const moduleInfo = ModuleInfo.parseInfoPro(moduleName, process.env.CabloyCliBrandName, 'module');
|
|
122
|
-
if (!moduleInfo)
|
|
123
|
-
throw new Error(`module name is not valid: ${moduleName}`);
|
|
124
|
-
return moduleInfo;
|
|
125
|
-
}
|
|
126
|
-
findModule(moduleName) {
|
|
127
|
-
const moduleInfo = this.parseModuleInfo(moduleName);
|
|
128
|
-
return this.cli.modulesMeta.modules[moduleInfo.relativeName];
|
|
129
|
-
}
|
|
130
|
-
parseSuiteInfo(suiteName) {
|
|
131
|
-
const suiteInfo = ModuleInfo.parseInfoPro(suiteName, process.env.CabloyCliBrandName, 'suite');
|
|
132
|
-
if (!suiteInfo)
|
|
133
|
-
throw new Error(`suite name is not valid: ${suiteName}`);
|
|
134
|
-
return suiteInfo;
|
|
135
|
-
}
|
|
136
|
-
findSuite(suiteName) {
|
|
137
|
-
const suiteInfo = this.parseSuiteInfo(suiteName);
|
|
138
|
-
return this.cli.modulesMeta.suites[suiteInfo.relativeName];
|
|
139
|
-
}
|
|
140
|
-
async ensureDir(dir) {
|
|
141
|
-
await fse.ensureDir(dir);
|
|
142
|
-
return dir;
|
|
143
|
-
}
|
|
144
|
-
async pnpmInstall() {
|
|
145
|
-
// args
|
|
146
|
-
const args = ['install'];
|
|
147
|
-
// log
|
|
148
|
-
await this.console.log('===> pnpm install');
|
|
149
|
-
// spawn
|
|
150
|
-
await this.spawnCmd({
|
|
151
|
-
cmd: 'pnpm',
|
|
152
|
-
args,
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
async formatFile({ fileName, logPrefix }) {
|
|
156
|
-
if (_formatFileDisable(fileName))
|
|
157
|
-
return;
|
|
158
|
-
return await this.processHelper.formatFile({ fileName, logPrefix });
|
|
159
|
-
}
|
|
160
|
-
async spawnBin({ cmd, args, options }) {
|
|
161
|
-
return await this.processHelper.spawnBin({ cmd, args, options });
|
|
162
|
-
}
|
|
163
|
-
async spawnCmd({ cmd, args, options }) {
|
|
164
|
-
return await this.processHelper.spawnCmd({ cmd, args, options });
|
|
165
|
-
}
|
|
166
|
-
async spawnExe({ cmd, args, options }) {
|
|
167
|
-
return await this.processHelper.spawnExe({ cmd, args, options });
|
|
168
|
-
}
|
|
169
|
-
async spawn({ cmd, args = [], options = {} }) {
|
|
170
|
-
return await this.processHelper.spawn({ cmd, args, options });
|
|
171
|
-
}
|
|
172
|
-
async gitCommit({ cwd, message }) {
|
|
173
|
-
return await this.processHelper.gitCommit(message, { cwd });
|
|
174
|
-
}
|
|
175
|
-
async getRegistry() {
|
|
176
|
-
return await getRegistry();
|
|
177
|
-
}
|
|
178
|
-
parseBrandPath() {
|
|
179
|
-
const require = createRequire(import.meta.url);
|
|
180
|
-
const modulePath = require.resolve(`${process.env.CabloyCliBrandName}-cli/package.json`);
|
|
181
|
-
// ts or js
|
|
182
|
-
let file = path.join(path.dirname(modulePath), `src/bin/${process.env.CabloyCliBrandName}.ts`);
|
|
183
|
-
if (!fse.existsSync(file)) {
|
|
184
|
-
file = path.join(path.dirname(modulePath), `dist/bin/${process.env.CabloyCliBrandName}.js`);
|
|
185
|
-
}
|
|
186
|
-
return file;
|
|
187
|
-
}
|
|
188
|
-
async invokeCli(args, options) {
|
|
189
|
-
// tsx: spawnCmd, node: spawnExe
|
|
190
|
-
await this.processHelper.spawnCmd({
|
|
191
|
-
cmd: 'tsx',
|
|
192
|
-
args: [this.parseBrandPath()].concat(args),
|
|
193
|
-
// cmd: 'node',
|
|
194
|
-
// args: ['--experimental-transform-types', getImportEsm(), this.parseBrandPath()].concat(args),
|
|
195
|
-
options,
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
async loadJSONFile(fileName) {
|
|
199
|
-
const pkgContent = (await fse.readFile(fileName)).toString();
|
|
200
|
-
return JSON.parse(pkgContent);
|
|
201
|
-
}
|
|
202
|
-
async saveJSONFile(fileName, json, format) {
|
|
203
|
-
await fse.writeFile(fileName, `${JSON.stringify(json, null, 2)}\n`);
|
|
204
|
-
if (format !== false) {
|
|
205
|
-
await this.formatFile({ fileName });
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
safeSplit(str, sep = ',') {
|
|
209
|
-
let left = 0;
|
|
210
|
-
let start = 0;
|
|
211
|
-
const result = [];
|
|
212
|
-
while (start < str.length) {
|
|
213
|
-
let end = start;
|
|
214
|
-
while (end < str.length) {
|
|
215
|
-
if (str[end] === sep && left === 0) {
|
|
216
|
-
result.push(str.substring(start, end));
|
|
217
|
-
start = end + 1;
|
|
218
|
-
break;
|
|
219
|
-
}
|
|
220
|
-
if (str[end] === '<')
|
|
221
|
-
left++;
|
|
222
|
-
if (str[end] === '>')
|
|
223
|
-
left--;
|
|
224
|
-
end++;
|
|
225
|
-
}
|
|
226
|
-
if (start < end) {
|
|
227
|
-
result.push(str.substring(start, end));
|
|
228
|
-
start = end + 1;
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
if (start <= str.length) {
|
|
232
|
-
result.push(str.substring(start, str.length));
|
|
233
|
-
}
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
|
-
async removeGitkeep(parentPath) {
|
|
237
|
-
const gitkeep = path.join(parentPath, '.gitkeep');
|
|
238
|
-
if (fse.existsSync(gitkeep)) {
|
|
239
|
-
await fse.remove(gitkeep);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
combineModuleNameAndResource(moduleName, resourceName) {
|
|
243
|
-
return combineResourceName(resourceName, moduleName, true, true);
|
|
244
|
-
}
|
|
245
|
-
async importDynamic(fileName, fn) {
|
|
246
|
-
// load
|
|
247
|
-
const instance = await import(__rewriteRelativeImportExtension(this.pathToHref(fileName)));
|
|
248
|
-
if (!fn)
|
|
249
|
-
return instance;
|
|
250
|
-
return await fn(instance);
|
|
251
|
-
}
|
|
252
|
-
requireDynamic(file) {
|
|
253
|
-
if (!file)
|
|
254
|
-
throw new Error('file should not empty');
|
|
255
|
-
const require = createRequire(import.meta.url);
|
|
256
|
-
let instance = require(file);
|
|
257
|
-
const mtime = this._requireDynamic_getFileTime(file);
|
|
258
|
-
if (instance.__requireDynamic_mtime === undefined) {
|
|
259
|
-
instance.__requireDynamic_mtime = mtime;
|
|
260
|
-
}
|
|
261
|
-
else if (instance.__requireDynamic_mtime !== mtime) {
|
|
262
|
-
delete require.cache[require.resolve(file)];
|
|
263
|
-
instance = require(file);
|
|
264
|
-
instance.__requireDynamic_mtime = mtime;
|
|
265
|
-
}
|
|
266
|
-
return instance;
|
|
267
|
-
}
|
|
268
|
-
_requireDynamic_getFileTime(file) {
|
|
269
|
-
if (!path.isAbsolute(file))
|
|
270
|
-
return null;
|
|
271
|
-
const exists = fse.pathExistsSync(file);
|
|
272
|
-
if (!exists)
|
|
273
|
-
return null;
|
|
274
|
-
// stat
|
|
275
|
-
const stat = fse.statSync(file);
|
|
276
|
-
return stat.mtime.valueOf();
|
|
277
|
-
}
|
|
278
|
-
async tempFile(fn, options) {
|
|
279
|
-
// temp
|
|
280
|
-
const fileTempObj = tmp.fileSync(options);
|
|
281
|
-
const fileTemp = fileTempObj.name;
|
|
282
|
-
try {
|
|
283
|
-
return await fn(fileTemp);
|
|
284
|
-
}
|
|
285
|
-
finally {
|
|
286
|
-
// delete temp
|
|
287
|
-
fileTempObj.removeCallback();
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
pathToHref(fileName) {
|
|
291
|
-
return pathToFileURL(fileName).href;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
function _formatFileDisable(fileName) {
|
|
295
|
-
const baseName = path.basename(fileName);
|
|
296
|
-
if (/.env\..*$/.test(baseName))
|
|
297
|
-
return true;
|
|
298
|
-
if (['.env', 'docker-compose-dockerfile-app', 'docker-compose.yml'].includes(baseName))
|
|
299
|
-
return true;
|
|
300
|
-
return false;
|
|
301
|
-
}
|
|
302
|
-
// async importDynamic<RESULT>(fileName: string, fn: (instance: any) => Promise<RESULT>): Promise<RESULT> {
|
|
303
|
-
// return await this.tempFile(
|
|
304
|
-
// async fileTemp => {
|
|
305
|
-
// // build
|
|
306
|
-
// const esBuildConfig = this._createEsbuildConfig(fileName, fileTemp);
|
|
307
|
-
// await esBuild(esBuildConfig as any);
|
|
308
|
-
// // load
|
|
309
|
-
// const instance = await import(this._pathToHref(fileTemp));
|
|
310
|
-
// return await fn(instance);
|
|
311
|
-
// },
|
|
312
|
-
// {
|
|
313
|
-
// tmpdir: path.dirname(fileName),
|
|
314
|
-
// prefix: '.temp-dynamic-',
|
|
315
|
-
// postfix: '.mjs',
|
|
316
|
-
// },
|
|
317
|
-
// );
|
|
318
|
-
// }
|
|
319
|
-
// private _createEsbuildConfig(fileSrc: string, fileDest: string) {
|
|
320
|
-
// return {
|
|
321
|
-
// platform: 'node',
|
|
322
|
-
// format: 'esm',
|
|
323
|
-
// bundle: true,
|
|
324
|
-
// packages: 'external',
|
|
325
|
-
// resolveExtensions: ['.mjs', '.js', '.mts', '.ts', '.json'],
|
|
326
|
-
// entryPoints: [fileSrc],
|
|
327
|
-
// outfile: fileDest,
|
|
328
|
-
// };
|
|
329
|
-
// }
|