@modern-js/generator-utils 1.1.1 → 1.1.2-alpha.0
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/js/modern/index.js +2 -25
- package/dist/js/modern/utils/index.js +0 -1
- package/dist/js/node/index.js +10 -31
- package/dist/js/node/utils/index.js +0 -13
- package/dist/types/index.d.ts +1 -2
- package/dist/types/utils/index.d.ts +0 -1
- package/package.json +4 -4
- package/src/index.ts +8 -21
- package/src/utils/index.ts +0 -1
- package/dist/js/modern/utils/env.js +0 -31
- package/dist/js/node/utils/env.js +0 -45
- package/dist/types/utils/env.d.ts +0 -3
- package/src/utils/env.ts +0 -28
package/dist/js/modern/index.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import os from 'os';
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import { fs, getMonorepoPackages } from '@modern-js/utils';
|
|
2
|
+
import { fs, getMonorepoPackages, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
|
|
4
3
|
import execa from 'execa';
|
|
5
4
|
import ora from 'ora';
|
|
6
|
-
import { canUseNpm, canUsePnpm, canUseYarn } from "./utils/env";
|
|
7
5
|
import { stripAnsi } from "./utils/strip-ansi";
|
|
8
6
|
import { i18n, localeKeys } from "./locale";
|
|
9
7
|
export * from "./utils";
|
|
10
|
-
export { fs, readTsConfigByFile } from '@modern-js/utils';
|
|
8
|
+
export { fs, readTsConfigByFile, getPackageManager } from '@modern-js/utils';
|
|
11
9
|
export { i18n } from "./locale"; // eslint-disable-next-line max-statements
|
|
12
10
|
|
|
13
11
|
export async function getPackageVersion(packageName, registry) {
|
|
@@ -53,27 +51,6 @@ export async function getPackageVersion(packageName, registry) {
|
|
|
53
51
|
spinner.stop();
|
|
54
52
|
throw new Error('not found npm, please install npm before');
|
|
55
53
|
}
|
|
56
|
-
export function getPackageManager(cwd = process.cwd()) {
|
|
57
|
-
let appDirectory = cwd;
|
|
58
|
-
|
|
59
|
-
while (os.homedir() !== appDirectory) {
|
|
60
|
-
if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
|
|
61
|
-
return 'pnpm';
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
|
|
65
|
-
return 'yarn';
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
|
|
69
|
-
return 'npm';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
appDirectory = path.join(appDirectory, '..');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return 'npm';
|
|
76
|
-
}
|
|
77
54
|
export function getPackageManagerText(packageManager) {
|
|
78
55
|
return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
|
|
79
56
|
}
|
package/dist/js/node/index.js
CHANGED
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
getPackageVersion: true,
|
|
8
|
-
getPackageManager: true,
|
|
9
8
|
getPackageManagerText: true,
|
|
10
9
|
isTsProject: true,
|
|
11
10
|
getPackageObj: true,
|
|
@@ -16,6 +15,7 @@ var _exportNames = {
|
|
|
16
15
|
getMWAProjectPath: true,
|
|
17
16
|
fs: true,
|
|
18
17
|
readTsConfigByFile: true,
|
|
18
|
+
getPackageManager: true,
|
|
19
19
|
i18n: true
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "fs", {
|
|
@@ -27,7 +27,12 @@ Object.defineProperty(exports, "fs", {
|
|
|
27
27
|
exports.getAllPackages = getAllPackages;
|
|
28
28
|
exports.getMWAProjectPath = getMWAProjectPath;
|
|
29
29
|
exports.getModuleProjectPath = getModuleProjectPath;
|
|
30
|
-
exports
|
|
30
|
+
Object.defineProperty(exports, "getPackageManager", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _utils.getPackageManager;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
31
36
|
exports.getPackageManagerText = getPackageManagerText;
|
|
32
37
|
exports.getPackageObj = getPackageObj;
|
|
33
38
|
exports.getPackageVersion = getPackageVersion;
|
|
@@ -47,8 +52,6 @@ Object.defineProperty(exports, "readTsConfigByFile", {
|
|
|
47
52
|
exports.validatePackageName = validatePackageName;
|
|
48
53
|
exports.validatePackagePath = validatePackagePath;
|
|
49
54
|
|
|
50
|
-
var _os = _interopRequireDefault(require("os"));
|
|
51
|
-
|
|
52
55
|
var _path = _interopRequireDefault(require("path"));
|
|
53
56
|
|
|
54
57
|
var _utils = require("@modern-js/utils");
|
|
@@ -57,8 +60,6 @@ var _execa = _interopRequireDefault(require("execa"));
|
|
|
57
60
|
|
|
58
61
|
var _ora = _interopRequireDefault(require("ora"));
|
|
59
62
|
|
|
60
|
-
var _env = require("./utils/env");
|
|
61
|
-
|
|
62
63
|
var _stripAnsi = require("./utils/strip-ansi");
|
|
63
64
|
|
|
64
65
|
var _locale = require("./locale");
|
|
@@ -84,7 +85,7 @@ async function getPackageVersion(packageName, registry) {
|
|
|
84
85
|
const spinner = (0, _ora.default)('Loading...').start();
|
|
85
86
|
spinner.color = 'yellow';
|
|
86
87
|
|
|
87
|
-
if (await (0,
|
|
88
|
+
if (await (0, _utils.canUsePnpm)()) {
|
|
88
89
|
const args = ['info', packageName, 'version'];
|
|
89
90
|
|
|
90
91
|
if (registry) {
|
|
@@ -96,7 +97,7 @@ async function getPackageVersion(packageName, registry) {
|
|
|
96
97
|
return (0, _stripAnsi.stripAnsi)(result.stdout);
|
|
97
98
|
}
|
|
98
99
|
|
|
99
|
-
if (await (0,
|
|
100
|
+
if (await (0, _utils.canUseYarn)()) {
|
|
100
101
|
const args = ['info', packageName, 'version', '--silent'];
|
|
101
102
|
|
|
102
103
|
if (registry) {
|
|
@@ -108,7 +109,7 @@ async function getPackageVersion(packageName, registry) {
|
|
|
108
109
|
return (0, _stripAnsi.stripAnsi)(result.stdout);
|
|
109
110
|
}
|
|
110
111
|
|
|
111
|
-
if (await (0,
|
|
112
|
+
if (await (0, _utils.canUseNpm)()) {
|
|
112
113
|
const args = ['view', packageName, 'version'];
|
|
113
114
|
|
|
114
115
|
if (registry) {
|
|
@@ -124,28 +125,6 @@ async function getPackageVersion(packageName, registry) {
|
|
|
124
125
|
throw new Error('not found npm, please install npm before');
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
function getPackageManager(cwd = process.cwd()) {
|
|
128
|
-
let appDirectory = cwd;
|
|
129
|
-
|
|
130
|
-
while (_os.default.homedir() !== appDirectory) {
|
|
131
|
-
if (_utils.fs.existsSync(_path.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
|
|
132
|
-
return 'pnpm';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (_utils.fs.existsSync(_path.default.resolve(appDirectory, 'yarn.lock'))) {
|
|
136
|
-
return 'yarn';
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (_utils.fs.existsSync(_path.default.resolve(appDirectory, 'package-lock.json'))) {
|
|
140
|
-
return 'npm';
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
appDirectory = _path.default.join(appDirectory, '..');
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return 'npm';
|
|
147
|
-
}
|
|
148
|
-
|
|
149
128
|
function getPackageManagerText(packageManager) {
|
|
150
129
|
return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
|
|
151
130
|
}
|
|
@@ -4,19 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
|
|
7
|
-
var _env = require("./env");
|
|
8
|
-
|
|
9
|
-
Object.keys(_env).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] === _env[key]) return;
|
|
12
|
-
Object.defineProperty(exports, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _env[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
7
|
var _stripAnsi = require("./strip-ansi");
|
|
21
8
|
|
|
22
9
|
Object.keys(_stripAnsi).forEach(function (key) {
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { GeneratorContext } from '@modern-js/codesmith';
|
|
2
2
|
export * from './utils';
|
|
3
|
-
export { fs, readTsConfigByFile } from '@modern-js/utils';
|
|
3
|
+
export { fs, readTsConfigByFile, getPackageManager } from '@modern-js/utils';
|
|
4
4
|
export { i18n } from './locale';
|
|
5
5
|
export declare function getPackageVersion(packageName: string, registry?: string): Promise<string>;
|
|
6
|
-
export declare function getPackageManager(cwd?: string): "npm" | "yarn" | "pnpm";
|
|
7
6
|
export declare function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm'): string;
|
|
8
7
|
export declare function isTsProject(appDir: string): boolean;
|
|
9
8
|
export declare function getPackageObj(context: GeneratorContext): Promise<any>;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.1.
|
|
14
|
+
"version": "1.1.2-alpha.0",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"ora": "^5.4.1"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@modern-js/codesmith": "^1.0.
|
|
37
|
+
"@modern-js/codesmith": "^1.0.7",
|
|
38
38
|
"@types/jest": "^26",
|
|
39
39
|
"@types/node": "^14",
|
|
40
40
|
"typescript": "^4",
|
|
41
|
-
"@modern-js/module-tools": "^1.1.
|
|
42
|
-
"@modern-js/plugin-testing": "^1.1.
|
|
41
|
+
"@modern-js/module-tools": "^1.1.1",
|
|
42
|
+
"@modern-js/plugin-testing": "^1.1.1"
|
|
43
43
|
},
|
|
44
44
|
"sideEffects": false,
|
|
45
45
|
"modernConfig": {
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import os from 'os';
|
|
2
1
|
import path from 'path';
|
|
3
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
fs,
|
|
4
|
+
getMonorepoPackages,
|
|
5
|
+
canUseNpm,
|
|
6
|
+
canUsePnpm,
|
|
7
|
+
canUseYarn,
|
|
8
|
+
} from '@modern-js/utils';
|
|
4
9
|
import execa from 'execa';
|
|
5
10
|
import ora from 'ora';
|
|
6
11
|
import { GeneratorContext } from '@modern-js/codesmith';
|
|
7
|
-
import { canUseNpm, canUsePnpm, canUseYarn } from './utils/env';
|
|
8
12
|
import { stripAnsi } from './utils/strip-ansi';
|
|
9
13
|
import { i18n, localeKeys } from './locale';
|
|
10
14
|
|
|
11
15
|
export * from './utils';
|
|
12
16
|
|
|
13
|
-
export { fs, readTsConfigByFile } from '@modern-js/utils';
|
|
17
|
+
export { fs, readTsConfigByFile, getPackageManager } from '@modern-js/utils';
|
|
14
18
|
|
|
15
19
|
export { i18n } from './locale';
|
|
16
20
|
|
|
@@ -52,23 +56,6 @@ export async function getPackageVersion(
|
|
|
52
56
|
throw new Error('not found npm, please install npm before');
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
export function getPackageManager(cwd: string = process.cwd()) {
|
|
56
|
-
let appDirectory = cwd;
|
|
57
|
-
while (os.homedir() !== appDirectory) {
|
|
58
|
-
if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
|
|
59
|
-
return 'pnpm';
|
|
60
|
-
}
|
|
61
|
-
if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
|
|
62
|
-
return 'yarn';
|
|
63
|
-
}
|
|
64
|
-
if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
|
|
65
|
-
return 'npm';
|
|
66
|
-
}
|
|
67
|
-
appDirectory = path.join(appDirectory, '..');
|
|
68
|
-
}
|
|
69
|
-
return 'npm';
|
|
70
|
-
}
|
|
71
|
-
|
|
72
59
|
export function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm') {
|
|
73
60
|
return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
|
|
74
61
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import execa from 'execa';
|
|
2
|
-
export async function canUseNpm() {
|
|
3
|
-
try {
|
|
4
|
-
await execa('npm', ['--version'], {
|
|
5
|
-
env: process.env
|
|
6
|
-
});
|
|
7
|
-
return true;
|
|
8
|
-
} catch (e) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export async function canUseYarn() {
|
|
13
|
-
try {
|
|
14
|
-
await execa('yarn', ['--version'], {
|
|
15
|
-
env: process.env
|
|
16
|
-
});
|
|
17
|
-
return true;
|
|
18
|
-
} catch (e) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export async function canUsePnpm() {
|
|
23
|
-
try {
|
|
24
|
-
await execa('pnpm', ['--version'], {
|
|
25
|
-
env: process.env
|
|
26
|
-
});
|
|
27
|
-
return true;
|
|
28
|
-
} catch (e) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.canUseNpm = canUseNpm;
|
|
7
|
-
exports.canUsePnpm = canUsePnpm;
|
|
8
|
-
exports.canUseYarn = canUseYarn;
|
|
9
|
-
|
|
10
|
-
var _execa = _interopRequireDefault(require("execa"));
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
async function canUseNpm() {
|
|
15
|
-
try {
|
|
16
|
-
await (0, _execa.default)('npm', ['--version'], {
|
|
17
|
-
env: process.env
|
|
18
|
-
});
|
|
19
|
-
return true;
|
|
20
|
-
} catch (e) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function canUseYarn() {
|
|
26
|
-
try {
|
|
27
|
-
await (0, _execa.default)('yarn', ['--version'], {
|
|
28
|
-
env: process.env
|
|
29
|
-
});
|
|
30
|
-
return true;
|
|
31
|
-
} catch (e) {
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async function canUsePnpm() {
|
|
37
|
-
try {
|
|
38
|
-
await (0, _execa.default)('pnpm', ['--version'], {
|
|
39
|
-
env: process.env
|
|
40
|
-
});
|
|
41
|
-
return true;
|
|
42
|
-
} catch (e) {
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
45
|
-
}
|
package/src/utils/env.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import execa from 'execa';
|
|
2
|
-
|
|
3
|
-
export async function canUseNpm() {
|
|
4
|
-
try {
|
|
5
|
-
await execa('npm', ['--version'], { env: process.env });
|
|
6
|
-
return true;
|
|
7
|
-
} catch (e) {
|
|
8
|
-
return false;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function canUseYarn() {
|
|
13
|
-
try {
|
|
14
|
-
await execa('yarn', ['--version'], { env: process.env });
|
|
15
|
-
return true;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export async function canUsePnpm() {
|
|
22
|
-
try {
|
|
23
|
-
await execa('pnpm', ['--version'], { env: process.env });
|
|
24
|
-
return true;
|
|
25
|
-
} catch (e) {
|
|
26
|
-
return false;
|
|
27
|
-
}
|
|
28
|
-
}
|