@modern-js/generator-utils 1.2.0 → 1.2.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/.eslintrc.js +8 -0
- package/CHANGELOG.md +43 -0
- package/dist/js/modern/index.js +2 -5
- package/dist/js/node/index.js +4 -9
- package/jest.config.js +0 -1
- package/package.json +4 -7
- package/src/index.ts +0 -148
- package/src/locale/en.ts +0 -4
- package/src/locale/index.ts +0 -9
- package/src/locale/zh.ts +0 -4
- package/src/utils/index.ts +0 -1
- package/src/utils/strip-ansi.ts +0 -16
- package/tests/.eslintrc.js +0 -6
- package/tests/index.test.ts +0 -8
- package/tests/tsconfig.json +0 -9
package/.eslintrc.js
ADDED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
# @modern-js/generator-utils
|
|
2
2
|
|
|
3
|
+
## 1.2.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 592edabc: feat: prebundle url-join,mime-types,json5,fast-glob,globby,ora,inquirer
|
|
8
|
+
- Updated dependencies [2d155c4c]
|
|
9
|
+
- Updated dependencies [123e432d]
|
|
10
|
+
- Updated dependencies [e5a9b26d]
|
|
11
|
+
- Updated dependencies [0b26b93b]
|
|
12
|
+
- Updated dependencies [123e432d]
|
|
13
|
+
- Updated dependencies [f9f66ef9]
|
|
14
|
+
- Updated dependencies [592edabc]
|
|
15
|
+
- Updated dependencies [895fa0ff]
|
|
16
|
+
- Updated dependencies [3578913e]
|
|
17
|
+
- Updated dependencies [1c3beab3]
|
|
18
|
+
- @modern-js/utils@1.6.0
|
|
19
|
+
|
|
20
|
+
## 1.2.2
|
|
21
|
+
|
|
22
|
+
### Patch Changes
|
|
23
|
+
|
|
24
|
+
- 6cffe99d: chore:
|
|
25
|
+
remove react eslint rules for `modern-js` rule set.
|
|
26
|
+
add .eslintrc for each package to speed up linting
|
|
27
|
+
- 04ae5262: chore: bump @modern-js/utils to v1.4.1 in dependencies
|
|
28
|
+
- 60f7d8bf: feat: add tests dir to npmignore
|
|
29
|
+
- Updated dependencies [b8599d09]
|
|
30
|
+
- Updated dependencies [6cffe99d]
|
|
31
|
+
- Updated dependencies [04ae5262]
|
|
32
|
+
- Updated dependencies [60f7d8bf]
|
|
33
|
+
- Updated dependencies [3bf4f8b0]
|
|
34
|
+
- @modern-js/utils@1.5.0
|
|
35
|
+
- @modern-js/plugin-i18n@1.2.4
|
|
36
|
+
|
|
37
|
+
## 1.2.1
|
|
38
|
+
|
|
39
|
+
### Patch Changes
|
|
40
|
+
|
|
41
|
+
- 83166714: change .npmignore
|
|
42
|
+
- Updated dependencies [83166714]
|
|
43
|
+
- @modern-js/plugin-i18n@1.2.1
|
|
44
|
+
- @modern-js/utils@1.2.2
|
|
45
|
+
|
|
3
46
|
## 1.2.0
|
|
4
47
|
|
|
5
48
|
### Minor Changes
|
package/dist/js/modern/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
-
import { fs, getMonorepoPackages, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
|
|
3
|
-
import execa from 'execa';
|
|
4
|
-
import ora from 'ora';
|
|
2
|
+
import { fs, ora, execa, getMonorepoPackages, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
|
|
5
3
|
import { stripAnsi } from "./utils/strip-ansi";
|
|
6
4
|
import { i18n, localeKeys } from "./locale";
|
|
7
5
|
export * from "./utils";
|
|
8
6
|
export { fs, readTsConfigByFile, getPackageManager, canUseNpm, canUsePnpm, canUseYarn } from '@modern-js/utils';
|
|
9
|
-
export { i18n } from "./locale";
|
|
10
|
-
|
|
7
|
+
export { i18n } from "./locale";
|
|
11
8
|
export async function getPackageVersion(packageName, registry) {
|
|
12
9
|
const spinner = ora('Loading...').start();
|
|
13
10
|
spinner.color = 'yellow';
|
package/dist/js/node/index.js
CHANGED
|
@@ -77,10 +77,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
77
77
|
|
|
78
78
|
var _utils = require("@modern-js/utils");
|
|
79
79
|
|
|
80
|
-
var _execa = _interopRequireDefault(require("execa"));
|
|
81
|
-
|
|
82
|
-
var _ora = _interopRequireDefault(require("ora"));
|
|
83
|
-
|
|
84
80
|
var _stripAnsi = require("./utils/strip-ansi");
|
|
85
81
|
|
|
86
82
|
var _locale = require("./locale");
|
|
@@ -101,9 +97,8 @@ Object.keys(_utils2).forEach(function (key) {
|
|
|
101
97
|
|
|
102
98
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
103
99
|
|
|
104
|
-
// eslint-disable-next-line max-statements
|
|
105
100
|
async function getPackageVersion(packageName, registry) {
|
|
106
|
-
const spinner = (0,
|
|
101
|
+
const spinner = (0, _utils.ora)('Loading...').start();
|
|
107
102
|
spinner.color = 'yellow';
|
|
108
103
|
|
|
109
104
|
if (await (0, _utils.canUsePnpm)()) {
|
|
@@ -113,7 +108,7 @@ async function getPackageVersion(packageName, registry) {
|
|
|
113
108
|
args.push(`--registry=${registry}`);
|
|
114
109
|
}
|
|
115
110
|
|
|
116
|
-
const result = await (0,
|
|
111
|
+
const result = await (0, _utils.execa)('pnpm', args);
|
|
117
112
|
spinner.stop();
|
|
118
113
|
return (0, _stripAnsi.stripAnsi)(result.stdout);
|
|
119
114
|
}
|
|
@@ -125,7 +120,7 @@ async function getPackageVersion(packageName, registry) {
|
|
|
125
120
|
args.push(`--registry=${registry}`);
|
|
126
121
|
}
|
|
127
122
|
|
|
128
|
-
const result = await (0,
|
|
123
|
+
const result = await (0, _utils.execa)('yarn', args);
|
|
129
124
|
spinner.stop();
|
|
130
125
|
return (0, _stripAnsi.stripAnsi)(result.stdout);
|
|
131
126
|
}
|
|
@@ -137,7 +132,7 @@ async function getPackageVersion(packageName, registry) {
|
|
|
137
132
|
args.push(`--registry=${registry}`);
|
|
138
133
|
}
|
|
139
134
|
|
|
140
|
-
const result = await (0,
|
|
135
|
+
const result = await (0, _utils.execa)('npm', args);
|
|
141
136
|
spinner.stop();
|
|
142
137
|
return (0, _stripAnsi.stripAnsi)(result.stdout);
|
|
143
138
|
}
|
package/jest.config.js
CHANGED
|
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
|
|
|
2
2
|
|
|
3
3
|
/** @type {import('@jest/types').Config.InitialOptions} */
|
|
4
4
|
module.exports = {
|
|
5
|
-
// eslint-disable-next-line node/no-unsupported-features/es-syntax
|
|
6
5
|
...sharedConfig,
|
|
7
6
|
rootDir: __dirname,
|
|
8
7
|
modulePathIgnorePatterns: [
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"modern",
|
|
12
12
|
"modern.js"
|
|
13
13
|
],
|
|
14
|
-
"version": "1.2.
|
|
14
|
+
"version": "1.2.3",
|
|
15
15
|
"jsnext:source": "./src/index.ts",
|
|
16
16
|
"types": "./dist/types/index.d.ts",
|
|
17
17
|
"main": "./dist/js/node/index.js",
|
|
@@ -29,10 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7",
|
|
32
|
-
"@modern-js/plugin-i18n": "^1.2.
|
|
33
|
-
"@modern-js/utils": "^1.
|
|
34
|
-
"execa": "^5.1.1",
|
|
35
|
-
"ora": "^5.4.1"
|
|
32
|
+
"@modern-js/plugin-i18n": "^1.2.4",
|
|
33
|
+
"@modern-js/utils": "^1.6.0"
|
|
36
34
|
},
|
|
37
35
|
"devDependencies": {
|
|
38
36
|
"@modern-js/codesmith": "^1.0.8",
|
|
@@ -51,8 +49,7 @@
|
|
|
51
49
|
},
|
|
52
50
|
"publishConfig": {
|
|
53
51
|
"registry": "https://registry.npmjs.org/",
|
|
54
|
-
"access": "public"
|
|
55
|
-
"types": "./dist/types/index.d.ts"
|
|
52
|
+
"access": "public"
|
|
56
53
|
},
|
|
57
54
|
"scripts": {
|
|
58
55
|
"new": "modern new",
|
package/src/index.ts
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import {
|
|
3
|
-
fs,
|
|
4
|
-
getMonorepoPackages,
|
|
5
|
-
canUseNpm,
|
|
6
|
-
canUsePnpm,
|
|
7
|
-
canUseYarn,
|
|
8
|
-
} from '@modern-js/utils';
|
|
9
|
-
import execa from 'execa';
|
|
10
|
-
import ora from 'ora';
|
|
11
|
-
import { GeneratorContext } from '@modern-js/codesmith';
|
|
12
|
-
import { stripAnsi } from './utils/strip-ansi';
|
|
13
|
-
import { i18n, localeKeys } from './locale';
|
|
14
|
-
|
|
15
|
-
export * from './utils';
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
fs,
|
|
19
|
-
readTsConfigByFile,
|
|
20
|
-
getPackageManager,
|
|
21
|
-
canUseNpm,
|
|
22
|
-
canUsePnpm,
|
|
23
|
-
canUseYarn,
|
|
24
|
-
} from '@modern-js/utils';
|
|
25
|
-
|
|
26
|
-
export { i18n } from './locale';
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line max-statements
|
|
29
|
-
export async function getPackageVersion(
|
|
30
|
-
packageName: string,
|
|
31
|
-
registry?: string,
|
|
32
|
-
) {
|
|
33
|
-
const spinner = ora('Loading...').start();
|
|
34
|
-
spinner.color = 'yellow';
|
|
35
|
-
if (await canUsePnpm()) {
|
|
36
|
-
const args = ['info', packageName, 'version'];
|
|
37
|
-
if (registry) {
|
|
38
|
-
args.push(`--registry=${registry}`);
|
|
39
|
-
}
|
|
40
|
-
const result = await execa('pnpm', args);
|
|
41
|
-
spinner.stop();
|
|
42
|
-
return stripAnsi(result.stdout);
|
|
43
|
-
}
|
|
44
|
-
if (await canUseYarn()) {
|
|
45
|
-
const args = ['info', packageName, 'version', '--silent'];
|
|
46
|
-
if (registry) {
|
|
47
|
-
args.push(`--registry=${registry}`);
|
|
48
|
-
}
|
|
49
|
-
const result = await execa('yarn', args);
|
|
50
|
-
spinner.stop();
|
|
51
|
-
return stripAnsi(result.stdout);
|
|
52
|
-
}
|
|
53
|
-
if (await canUseNpm()) {
|
|
54
|
-
const args = ['view', packageName, 'version'];
|
|
55
|
-
if (registry) {
|
|
56
|
-
args.push(`--registry=${registry}`);
|
|
57
|
-
}
|
|
58
|
-
const result = await execa('npm', args);
|
|
59
|
-
spinner.stop();
|
|
60
|
-
return stripAnsi(result.stdout);
|
|
61
|
-
}
|
|
62
|
-
spinner.stop();
|
|
63
|
-
throw new Error('not found npm, please install npm before');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
export function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm') {
|
|
67
|
-
return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function isTsProject(appDir: string) {
|
|
71
|
-
return fs.existsSync(path.join(appDir, 'tsconfig.json'));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export async function getPackageObj(context: GeneratorContext) {
|
|
75
|
-
const pkgStr = (await context.materials.default.get(`package.json`).value())
|
|
76
|
-
.content;
|
|
77
|
-
|
|
78
|
-
return JSON.parse(pkgStr as string);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function getAllPackages(appDir: string) {
|
|
82
|
-
const packages = getMonorepoPackages(appDir);
|
|
83
|
-
return packages.map(pkg => pkg.name);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function validatePackageName(
|
|
87
|
-
value: string,
|
|
88
|
-
packages: string[],
|
|
89
|
-
options: { isMonorepoSubProject: boolean },
|
|
90
|
-
) {
|
|
91
|
-
const { isMonorepoSubProject } = options;
|
|
92
|
-
if (isMonorepoSubProject && packages.includes(value)) {
|
|
93
|
-
return {
|
|
94
|
-
success: false,
|
|
95
|
-
error: i18n.t(localeKeys.packageName.exit, { value }),
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
return { success: true };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export function validatePackagePath(
|
|
102
|
-
value: string,
|
|
103
|
-
projectDir: string,
|
|
104
|
-
options?: { isMwa?: boolean; isPublic?: boolean; isTest?: boolean },
|
|
105
|
-
) {
|
|
106
|
-
const { isMwa, isPublic, isTest } = options || {};
|
|
107
|
-
let dir = 'apps';
|
|
108
|
-
if (isMwa && isTest) {
|
|
109
|
-
dir = 'examples';
|
|
110
|
-
} else {
|
|
111
|
-
dir = isPublic ? 'packages' : 'features';
|
|
112
|
-
}
|
|
113
|
-
const packageDir = path.resolve(projectDir || '', dir, value);
|
|
114
|
-
if (fs.existsSync(packageDir)) {
|
|
115
|
-
return {
|
|
116
|
-
success: false,
|
|
117
|
-
error: i18n.t(localeKeys.pacakgePath.exit, { value }),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
return { success: true };
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export function getModuleProjectPath(
|
|
124
|
-
packagePath: string,
|
|
125
|
-
isMonorepoSubProject: boolean,
|
|
126
|
-
isPublic: boolean,
|
|
127
|
-
isLocalPackages: boolean,
|
|
128
|
-
) {
|
|
129
|
-
if (isLocalPackages && packagePath) {
|
|
130
|
-
return `${packagePath}/`;
|
|
131
|
-
}
|
|
132
|
-
if (isMonorepoSubProject && packagePath) {
|
|
133
|
-
return `${isPublic ? 'packages' : 'features'}/${packagePath}/`;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return '';
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function getMWAProjectPath(
|
|
140
|
-
packagePath: string,
|
|
141
|
-
isMonorepoSubProject: boolean,
|
|
142
|
-
isTest = false,
|
|
143
|
-
) {
|
|
144
|
-
if (isMonorepoSubProject && packagePath) {
|
|
145
|
-
return `${isTest ? 'examples' : 'apps'}/${packagePath}/`;
|
|
146
|
-
}
|
|
147
|
-
return '';
|
|
148
|
-
}
|
package/src/locale/en.ts
DELETED
package/src/locale/index.ts
DELETED
package/src/locale/zh.ts
DELETED
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './strip-ansi';
|
package/src/utils/strip-ansi.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
function ansiRegex({ onlyFirst = false } = {}) {
|
|
2
|
-
const pattern = [
|
|
3
|
-
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
|
4
|
-
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
|
|
5
|
-
].join('|');
|
|
6
|
-
|
|
7
|
-
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function stripAnsi(string: string) {
|
|
11
|
-
if (typeof string !== 'string') {
|
|
12
|
-
throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return string.replace(ansiRegex(), '');
|
|
16
|
-
}
|
package/tests/.eslintrc.js
DELETED
package/tests/index.test.ts
DELETED