@modern-js/generator-utils 1.1.2-rc.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/CHANGELOG.md CHANGED
@@ -1,18 +1,45 @@
1
1
  # @modern-js/generator-utils
2
2
 
3
- ## 1.1.2-rc.0
3
+ ## 1.2.1
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [d927bc83]
8
- - Updated dependencies [d73ff455]
9
- - Updated dependencies [9c1ab865]
10
- - Updated dependencies [d73ff455]
11
- - Updated dependencies [d73ff455]
12
- - Updated dependencies [d73ff455]
13
- - Updated dependencies [d73ff455]
14
- - @modern-js/utils@1.1.4-rc.0
15
- - @modern-js/plugin-i18n@1.1.1
7
+ - 83166714: change .npmignore
8
+ - Updated dependencies [83166714]
9
+ - @modern-js/plugin-i18n@1.2.1
10
+ - @modern-js/utils@1.2.2
11
+
12
+ ## 1.2.0
13
+
14
+ ### Minor Changes
15
+
16
+ - cfe11628: Make Modern.js self bootstraping
17
+
18
+ ### Patch Changes
19
+
20
+ - 2c049918: feat: polyfill function support enable using new command
21
+ - Updated dependencies [2da09c69]
22
+ - Updated dependencies [c3d46ee4]
23
+ - Updated dependencies [cfe11628]
24
+ - @modern-js/utils@1.2.0
25
+ - @modern-js/plugin-i18n@1.2.0
26
+
27
+ ## 1.1.3
28
+
29
+ ### Patch Changes
30
+
31
+ - f73fee4b: feat: upgrade codesmith version to add get npm package timeout's time
32
+
33
+ ## 1.1.2
34
+
35
+ ### Patch Changes
36
+
37
+ - 4819a3c7: feat: update generator version
38
+ - b7fb82ec: fix: get package manager function
39
+ - Updated dependencies [5e3de7d8]
40
+ - Updated dependencies [b7fb82ec]
41
+ - @modern-js/plugin-i18n@1.1.2
42
+ - @modern-js/utils@1.1.6
16
43
 
17
44
  ## 1.1.1
18
45
 
@@ -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, canUseNpm, canUsePnpm, canUseYarn } 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
  }
@@ -1,2 +1 @@
1
- export * from "./env";
2
1
  export * from "./strip-ansi";
@@ -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,8 +15,30 @@ var _exportNames = {
16
15
  getMWAProjectPath: true,
17
16
  fs: true,
18
17
  readTsConfigByFile: true,
18
+ getPackageManager: true,
19
+ canUseNpm: true,
20
+ canUsePnpm: true,
21
+ canUseYarn: true,
19
22
  i18n: true
20
23
  };
24
+ Object.defineProperty(exports, "canUseNpm", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _utils.canUseNpm;
28
+ }
29
+ });
30
+ Object.defineProperty(exports, "canUsePnpm", {
31
+ enumerable: true,
32
+ get: function () {
33
+ return _utils.canUsePnpm;
34
+ }
35
+ });
36
+ Object.defineProperty(exports, "canUseYarn", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _utils.canUseYarn;
40
+ }
41
+ });
21
42
  Object.defineProperty(exports, "fs", {
22
43
  enumerable: true,
23
44
  get: function () {
@@ -27,7 +48,12 @@ Object.defineProperty(exports, "fs", {
27
48
  exports.getAllPackages = getAllPackages;
28
49
  exports.getMWAProjectPath = getMWAProjectPath;
29
50
  exports.getModuleProjectPath = getModuleProjectPath;
30
- exports.getPackageManager = getPackageManager;
51
+ Object.defineProperty(exports, "getPackageManager", {
52
+ enumerable: true,
53
+ get: function () {
54
+ return _utils.getPackageManager;
55
+ }
56
+ });
31
57
  exports.getPackageManagerText = getPackageManagerText;
32
58
  exports.getPackageObj = getPackageObj;
33
59
  exports.getPackageVersion = getPackageVersion;
@@ -47,8 +73,6 @@ Object.defineProperty(exports, "readTsConfigByFile", {
47
73
  exports.validatePackageName = validatePackageName;
48
74
  exports.validatePackagePath = validatePackagePath;
49
75
 
50
- var _os = _interopRequireDefault(require("os"));
51
-
52
76
  var _path = _interopRequireDefault(require("path"));
53
77
 
54
78
  var _utils = require("@modern-js/utils");
@@ -57,8 +81,6 @@ var _execa = _interopRequireDefault(require("execa"));
57
81
 
58
82
  var _ora = _interopRequireDefault(require("ora"));
59
83
 
60
- var _env = require("./utils/env");
61
-
62
84
  var _stripAnsi = require("./utils/strip-ansi");
63
85
 
64
86
  var _locale = require("./locale");
@@ -84,7 +106,7 @@ async function getPackageVersion(packageName, registry) {
84
106
  const spinner = (0, _ora.default)('Loading...').start();
85
107
  spinner.color = 'yellow';
86
108
 
87
- if (await (0, _env.canUsePnpm)()) {
109
+ if (await (0, _utils.canUsePnpm)()) {
88
110
  const args = ['info', packageName, 'version'];
89
111
 
90
112
  if (registry) {
@@ -96,7 +118,7 @@ async function getPackageVersion(packageName, registry) {
96
118
  return (0, _stripAnsi.stripAnsi)(result.stdout);
97
119
  }
98
120
 
99
- if (await (0, _env.canUseYarn)()) {
121
+ if (await (0, _utils.canUseYarn)()) {
100
122
  const args = ['info', packageName, 'version', '--silent'];
101
123
 
102
124
  if (registry) {
@@ -108,7 +130,7 @@ async function getPackageVersion(packageName, registry) {
108
130
  return (0, _stripAnsi.stripAnsi)(result.stdout);
109
131
  }
110
132
 
111
- if (await (0, _env.canUseNpm)()) {
133
+ if (await (0, _utils.canUseNpm)()) {
112
134
  const args = ['view', packageName, 'version'];
113
135
 
114
136
  if (registry) {
@@ -124,28 +146,6 @@ async function getPackageVersion(packageName, registry) {
124
146
  throw new Error('not found npm, please install npm before');
125
147
  }
126
148
 
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
149
  function getPackageManagerText(packageManager) {
150
150
  return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
151
151
  }
@@ -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) {
@@ -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, canUseNpm, canUsePnpm, canUseYarn } 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>;
@@ -1,2 +1 @@
1
- export * from './env';
2
1
  export * from './strip-ansi';
package/jest.config.js ADDED
@@ -0,0 +1,12 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ modulePathIgnorePatterns: [
9
+ // TODO: 很容易超时导致失败,暂时先绕过
10
+ 'tests/index.test.ts',
11
+ ],
12
+ };
package/modern.config.js CHANGED
@@ -1,8 +1,2 @@
1
1
  /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {
3
- testing: {
4
- jest: {
5
- testTimeout: 30000,
6
- },
7
- },
8
- };
2
+ module.exports = {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.2-rc.0",
14
+ "version": "1.2.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -20,6 +20,7 @@
20
20
  "exports": {
21
21
  ".": {
22
22
  "node": {
23
+ "jsnext:source": "./src/index.ts",
23
24
  "import": "./dist/js/modern/index.js",
24
25
  "require": "./dist/js/node/index.js"
25
26
  },
@@ -28,18 +29,19 @@
28
29
  },
29
30
  "dependencies": {
30
31
  "@babel/runtime": "^7",
31
- "@modern-js/plugin-i18n": "^1.1.1",
32
- "@modern-js/utils": "^1.1.4-rc.0",
32
+ "@modern-js/plugin-i18n": "^1.2.1",
33
+ "@modern-js/utils": "^1.2.2",
33
34
  "execa": "^5.1.1",
34
35
  "ora": "^5.4.1"
35
36
  },
36
37
  "devDependencies": {
37
- "@modern-js/codesmith": "^1.0.0",
38
+ "@modern-js/codesmith": "^1.0.8",
38
39
  "@types/jest": "^26",
39
40
  "@types/node": "^14",
40
41
  "typescript": "^4",
41
- "@modern-js/module-tools": "^1.1.1",
42
- "@modern-js/plugin-testing": "^1.1.1"
42
+ "@scripts/build": "0.0.0",
43
+ "jest": "^27",
44
+ "@scripts/jest-config": "0.0.0"
43
45
  },
44
46
  "sideEffects": false,
45
47
  "modernConfig": {
@@ -49,12 +51,13 @@
49
51
  },
50
52
  "publishConfig": {
51
53
  "registry": "https://registry.npmjs.org/",
52
- "access": "public"
54
+ "access": "public",
55
+ "types": "./dist/types/index.d.ts"
53
56
  },
54
57
  "scripts": {
55
58
  "new": "modern new",
56
59
  "build": "modern build",
57
- "test": "modern test --passWithNoTests"
60
+ "test": "jest --passWithNoTests"
58
61
  },
59
62
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
60
63
  }
@@ -1,20 +1,8 @@
1
- import { getPackageVersion, canUseNpm, canUsePnpm, canUseYarn } from '@/index';
1
+ import { getPackageVersion } from '../src';
2
2
 
3
3
  describe('test generator utils', () => {
4
4
  test('test getPackageVersion', async () => {
5
5
  const version = await getPackageVersion('lodash');
6
6
  expect(typeof version === 'string').toBe(true);
7
7
  });
8
- test('test canUseNpm', async () => {
9
- const npmAbility = await canUseNpm();
10
- expect(typeof npmAbility === 'boolean').toBe(true);
11
- });
12
- test('test canUsePnpm', async () => {
13
- const pnpmAbility = await canUsePnpm();
14
- expect(typeof pnpmAbility === 'boolean').toBe(true);
15
- });
16
- test('test canUseYarn', async () => {
17
- const yarnAbility = await canUseYarn();
18
- expect(typeof yarnAbility === 'boolean').toBe(true);
19
- });
20
8
  });
@@ -4,8 +4,6 @@
4
4
  "declaration": false,
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
- "paths": {
8
- "@/*": ["../src/*"]
9
- }
7
+ "paths": {}
10
8
  }
11
9
  }
package/tsconfig.json CHANGED
@@ -4,9 +4,7 @@
4
4
  "declaration": false,
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
- "paths": {
8
- "@/*": ["./src/*"]
9
- }
7
+ "paths": {}
10
8
  },
11
9
  "include": ["src"]
12
10
  }
@@ -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
- }
@@ -1,3 +0,0 @@
1
- export declare function canUseNpm(): Promise<boolean>;
2
- export declare function canUseYarn(): Promise<boolean>;
3
- export declare function canUsePnpm(): Promise<boolean>;
package/src/index.ts DELETED
@@ -1,154 +0,0 @@
1
- import os from 'os';
2
- import path from 'path';
3
- import { fs, getMonorepoPackages } from '@modern-js/utils';
4
- import execa from 'execa';
5
- import ora from 'ora';
6
- import { GeneratorContext } from '@modern-js/codesmith';
7
- import { canUseNpm, canUsePnpm, canUseYarn } from './utils/env';
8
- import { stripAnsi } from './utils/strip-ansi';
9
- import { i18n, localeKeys } from './locale';
10
-
11
- export * from './utils';
12
-
13
- export { fs, readTsConfigByFile } from '@modern-js/utils';
14
-
15
- export { i18n } from './locale';
16
-
17
- // eslint-disable-next-line max-statements
18
- export async function getPackageVersion(
19
- packageName: string,
20
- registry?: string,
21
- ) {
22
- const spinner = ora('Loading...').start();
23
- spinner.color = 'yellow';
24
- if (await canUsePnpm()) {
25
- const args = ['info', packageName, 'version'];
26
- if (registry) {
27
- args.push(`--registry=${registry}`);
28
- }
29
- const result = await execa('pnpm', args);
30
- spinner.stop();
31
- return stripAnsi(result.stdout);
32
- }
33
- if (await canUseYarn()) {
34
- const args = ['info', packageName, 'version', '--silent'];
35
- if (registry) {
36
- args.push(`--registry=${registry}`);
37
- }
38
- const result = await execa('yarn', args);
39
- spinner.stop();
40
- return stripAnsi(result.stdout);
41
- }
42
- if (await canUseNpm()) {
43
- const args = ['view', packageName, 'version'];
44
- if (registry) {
45
- args.push(`--registry=${registry}`);
46
- }
47
- const result = await execa('npm', args);
48
- spinner.stop();
49
- return stripAnsi(result.stdout);
50
- }
51
- spinner.stop();
52
- throw new Error('not found npm, please install npm before');
53
- }
54
-
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
- export function getPackageManagerText(packageManager: 'pnpm' | 'yarn' | 'npm') {
73
- return packageManager === 'yarn' ? 'yarn' : `${packageManager} run`;
74
- }
75
-
76
- export function isTsProject(appDir: string) {
77
- return fs.existsSync(path.join(appDir, 'tsconfig.json'));
78
- }
79
-
80
- export async function getPackageObj(context: GeneratorContext) {
81
- const pkgStr = (await context.materials.default.get(`package.json`).value())
82
- .content;
83
-
84
- return JSON.parse(pkgStr as string);
85
- }
86
-
87
- export function getAllPackages(appDir: string) {
88
- const packages = getMonorepoPackages(appDir);
89
- return packages.map(pkg => pkg.name);
90
- }
91
-
92
- export function validatePackageName(
93
- value: string,
94
- packages: string[],
95
- options: { isMonorepoSubProject: boolean },
96
- ) {
97
- const { isMonorepoSubProject } = options;
98
- if (isMonorepoSubProject && packages.includes(value)) {
99
- return {
100
- success: false,
101
- error: i18n.t(localeKeys.packageName.exit, { value }),
102
- };
103
- }
104
- return { success: true };
105
- }
106
-
107
- export function validatePackagePath(
108
- value: string,
109
- projectDir: string,
110
- options?: { isMwa?: boolean; isPublic?: boolean; isTest?: boolean },
111
- ) {
112
- const { isMwa, isPublic, isTest } = options || {};
113
- let dir = 'apps';
114
- if (isMwa && isTest) {
115
- dir = 'examples';
116
- } else {
117
- dir = isPublic ? 'packages' : 'features';
118
- }
119
- const packageDir = path.resolve(projectDir || '', dir, value);
120
- if (fs.existsSync(packageDir)) {
121
- return {
122
- success: false,
123
- error: i18n.t(localeKeys.pacakgePath.exit, { value }),
124
- };
125
- }
126
- return { success: true };
127
- }
128
-
129
- export function getModuleProjectPath(
130
- packagePath: string,
131
- isMonorepoSubProject: boolean,
132
- isPublic: boolean,
133
- isLocalPackages: boolean,
134
- ) {
135
- if (isLocalPackages && packagePath) {
136
- return `${packagePath}/`;
137
- }
138
- if (isMonorepoSubProject && packagePath) {
139
- return `${isPublic ? 'packages' : 'features'}/${packagePath}/`;
140
- }
141
-
142
- return '';
143
- }
144
-
145
- export function getMWAProjectPath(
146
- packagePath: string,
147
- isMonorepoSubProject: boolean,
148
- isTest = false,
149
- ) {
150
- if (isMonorepoSubProject && packagePath) {
151
- return `${isTest ? 'examples' : 'apps'}/${packagePath}/`;
152
- }
153
- return '';
154
- }
package/src/locale/en.ts DELETED
@@ -1,4 +0,0 @@
1
- export const EN_LOCALE = {
2
- packageName: { exit: 'package name `{value}` is already exists' },
3
- pacakgePath: { exit: 'package path {value} is already exists' },
4
- };
@@ -1,9 +0,0 @@
1
- import { I18n } from '@modern-js/plugin-i18n';
2
- import { ZH_LOCALE } from './zh';
3
- import { EN_LOCALE } from './en';
4
-
5
- const i18n = new I18n();
6
-
7
- const localeKeys = i18n.init('zh', { zh: ZH_LOCALE, en: EN_LOCALE });
8
-
9
- export { i18n, localeKeys };
package/src/locale/zh.ts DELETED
@@ -1,4 +0,0 @@
1
- export const ZH_LOCALE = {
2
- packageName: { exit: '项目名称 {value} 已存在' },
3
- pacakgePath: { exit: '目录 {value} 已存在' },
4
- };
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
- }
@@ -1,2 +0,0 @@
1
- export * from './env';
2
- export * from './strip-ansi';
@@ -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
- }