@umijs/utils 4.0.0-rc.12 → 4.0.0-rc.15
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,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -27,31 +18,32 @@ class BaseGenerator extends Generator_1.default {
|
|
|
27
18
|
prompting() {
|
|
28
19
|
return this.questions;
|
|
29
20
|
}
|
|
30
|
-
writing() {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
21
|
+
async writing() {
|
|
22
|
+
const context = {
|
|
23
|
+
...this.data,
|
|
24
|
+
...this.prompts,
|
|
25
|
+
};
|
|
26
|
+
if ((0, fs_1.statSync)(this.path).isDirectory()) {
|
|
27
|
+
this.copyDirectory({
|
|
28
|
+
context,
|
|
29
|
+
path: this.path,
|
|
30
|
+
target: this.target,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
if (this.path.endsWith('.tpl')) {
|
|
35
|
+
this.copyTpl({
|
|
36
|
+
templatePath: this.path,
|
|
37
37
|
target: this.target,
|
|
38
|
+
context,
|
|
38
39
|
});
|
|
39
40
|
}
|
|
40
41
|
else {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
target: this.target,
|
|
45
|
-
context,
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const absTarget = this.target;
|
|
50
|
-
fs_extra_1.default.mkdirpSync((0, path_1.dirname)(absTarget));
|
|
51
|
-
(0, fs_1.copyFileSync)(this.path, absTarget);
|
|
52
|
-
}
|
|
42
|
+
const absTarget = this.target;
|
|
43
|
+
fs_extra_1.default.mkdirpSync((0, path_1.dirname)(absTarget));
|
|
44
|
+
(0, fs_1.copyFileSync)(this.path, absTarget);
|
|
53
45
|
}
|
|
54
|
-
}
|
|
46
|
+
}
|
|
55
47
|
}
|
|
56
48
|
}
|
|
57
49
|
exports.default = BaseGenerator;
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
14
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
6
|
const BaseGenerator_1 = __importDefault(require("./BaseGenerator"));
|
|
16
|
-
const generateFile = ({ path, target, baseDir, data, questions, }) =>
|
|
7
|
+
const generateFile = async ({ path, target, baseDir, data, questions, }) => {
|
|
17
8
|
const generator = new BaseGenerator_1.default({
|
|
18
9
|
path,
|
|
19
10
|
target,
|
|
@@ -21,6 +12,6 @@ const generateFile = ({ path, target, baseDir, data, questions, }) => __awaiter(
|
|
|
21
12
|
data,
|
|
22
13
|
questions,
|
|
23
14
|
});
|
|
24
|
-
|
|
25
|
-
}
|
|
15
|
+
await generator.run();
|
|
16
|
+
};
|
|
26
17
|
exports.default = generateFile;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -25,19 +16,15 @@ class Generator {
|
|
|
25
16
|
this.args = args;
|
|
26
17
|
this.prompts = {};
|
|
27
18
|
}
|
|
28
|
-
run() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
yield this.writing();
|
|
33
|
-
});
|
|
19
|
+
async run() {
|
|
20
|
+
const questions = this.prompting();
|
|
21
|
+
this.prompts = await (0, prompts_1.default)(questions);
|
|
22
|
+
await this.writing();
|
|
34
23
|
}
|
|
35
24
|
prompting() {
|
|
36
25
|
return [];
|
|
37
26
|
}
|
|
38
|
-
writing() {
|
|
39
|
-
return __awaiter(this, void 0, void 0, function* () { });
|
|
40
|
-
}
|
|
27
|
+
async writing() { }
|
|
41
28
|
copyTpl(opts) {
|
|
42
29
|
const tpl = (0, fs_1.readFileSync)(opts.templatePath, 'utf-8');
|
|
43
30
|
const content = mustache_1.default.render(tpl, opts.context);
|
package/dist/installDeps.js
CHANGED
package/dist/npmClient.d.ts
CHANGED
|
@@ -7,7 +7,9 @@ export declare enum NpmClientEnum {
|
|
|
7
7
|
yarn = "yarn",
|
|
8
8
|
npm = "npm"
|
|
9
9
|
}
|
|
10
|
-
export declare const getNpmClient: (
|
|
10
|
+
export declare const getNpmClient: (opts: {
|
|
11
|
+
cwd: string;
|
|
12
|
+
}) => NpmClient;
|
|
11
13
|
export declare const installWithNpmClient: ({ npmClient, cwd, }: {
|
|
12
14
|
npmClient: NpmClient;
|
|
13
15
|
cwd?: string | undefined;
|
package/dist/npmClient.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.installWithNpmClient = exports.getNpmClient = exports.NpmClientEnum = exports.npmClients = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
4
6
|
exports.npmClients = ['pnpm', 'tnpm', 'cnpm', 'yarn', 'npm'];
|
|
5
7
|
var NpmClientEnum;
|
|
6
8
|
(function (NpmClientEnum) {
|
|
@@ -10,17 +12,21 @@ var NpmClientEnum;
|
|
|
10
12
|
NpmClientEnum["yarn"] = "yarn";
|
|
11
13
|
NpmClientEnum["npm"] = "npm";
|
|
12
14
|
})(NpmClientEnum = exports.NpmClientEnum || (exports.NpmClientEnum = {}));
|
|
13
|
-
const getNpmClient = () => {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const getNpmClient = (opts) => {
|
|
16
|
+
const chokidarPkg = require('chokidar/package.json');
|
|
17
|
+
if (chokidarPkg.__npminstall_done) {
|
|
18
|
+
return chokidarPkg._resolved.includes('registry.npm.alibaba-inc.com')
|
|
19
|
+
? 'tnpm'
|
|
20
|
+
: 'cnpm';
|
|
21
|
+
}
|
|
22
|
+
const chokidarPath = require.resolve('chokidar');
|
|
23
|
+
if (chokidarPath.includes('.pnpm') ||
|
|
24
|
+
(0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'node_modules', '.pnpm'))) {
|
|
25
|
+
return 'pnpm';
|
|
26
|
+
}
|
|
27
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'yarn.lock')) ||
|
|
28
|
+
(0, fs_1.existsSync)((0, path_1.join)(opts.cwd, 'node_modules', '.yarn-integrity'))) {
|
|
29
|
+
return 'yarn';
|
|
24
30
|
}
|
|
25
31
|
return 'npm';
|
|
26
32
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/utils",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.15",
|
|
4
4
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/utils#readme",
|
|
5
5
|
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
6
6
|
"repository": {
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
18
|
"build": "pnpm tsc",
|
|
19
|
-
"build:deps": "
|
|
19
|
+
"build:deps": "umi-scripts bundleDeps",
|
|
20
20
|
"dev": "pnpm build -- --watch",
|
|
21
|
-
"test": "
|
|
21
|
+
"test": "umi-scripts jest-turbo"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"chokidar": "3.5.3"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@types/color": "3.0.3",
|
|
28
28
|
"@types/cross-spawn": "6.0.2",
|
|
29
29
|
"@types/debug": "4.1.7",
|
|
30
|
-
"@types/lodash": "4.14.
|
|
30
|
+
"@types/lodash": "4.14.182",
|
|
31
31
|
"@types/mustache": "4.1.2",
|
|
32
32
|
"@types/prompts": "^2.0.14",
|
|
33
33
|
"@types/rimraf": "3.0.2",
|