@spcsn/taro-cli 0.1.5 → 1.0.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/README.md +37 -0
- package/define-config.d.ts +1 -0
- package/define-config.js +1 -0
- package/dist/cli.js +140 -110
- package/dist/cli.js.map +1 -1
- package/dist/commands/{customCommand.d.ts → custom-command.d.ts} +1 -1
- package/dist/commands/custom-command.js +23 -0
- package/dist/commands/custom-command.js.map +1 -0
- package/dist/create/creator.js +2 -0
- package/dist/create/creator.js.map +1 -1
- package/dist/create/{fetchTemplate.js → fetch-template.js} +26 -33
- package/dist/create/fetch-template.js.map +1 -0
- package/dist/create/project.d.ts +2 -6
- package/dist/create/project.js +240 -285
- package/dist/create/project.js.map +1 -1
- package/dist/create/template-creator.d.ts +75 -0
- package/dist/create/template-creator.js +275 -0
- package/dist/create/template-creator.js.map +1 -0
- package/dist/doctor/validators.d.ts +7 -6
- package/dist/doctor/validators.js +6 -7
- package/dist/doctor/validators.js.map +1 -1
- package/dist/platform-weapp/apis-list.d.ts +1 -0
- package/dist/platform-weapp/apis-list.js +37 -0
- package/dist/platform-weapp/apis-list.js.map +1 -0
- package/dist/platform-weapp/apis.d.ts +16 -0
- package/dist/platform-weapp/apis.js +34 -0
- package/dist/platform-weapp/apis.js.map +1 -0
- package/dist/platform-weapp/components-react.d.ts +80 -0
- package/dist/platform-weapp/components-react.js +86 -0
- package/dist/platform-weapp/components-react.js.map +1 -0
- package/dist/platform-weapp/components.d.ts +4 -0
- package/dist/platform-weapp/components.js +520 -0
- package/dist/platform-weapp/components.js.map +1 -0
- package/dist/platform-weapp/index.d.ts +11 -0
- package/dist/platform-weapp/index.js +17 -0
- package/dist/platform-weapp/index.js.map +1 -0
- package/dist/platform-weapp/program.d.ts +35 -0
- package/dist/platform-weapp/program.js +64 -0
- package/dist/platform-weapp/program.js.map +1 -0
- package/dist/platform-weapp/runtime-utils.d.ts +27 -0
- package/dist/platform-weapp/runtime-utils.js +48 -0
- package/dist/platform-weapp/runtime-utils.js.map +1 -0
- package/dist/platform-weapp/runtime.d.ts +1 -0
- package/dist/platform-weapp/runtime.js +7 -0
- package/dist/platform-weapp/runtime.js.map +1 -0
- package/dist/platform-weapp/template.d.ts +39 -0
- package/dist/platform-weapp/template.js +119 -0
- package/dist/platform-weapp/template.js.map +1 -0
- package/dist/presets/commands/build.js +25 -45
- package/dist/presets/commands/build.js.map +1 -1
- package/dist/presets/commands/init.js +2 -4
- package/dist/presets/commands/init.js.map +1 -1
- package/dist/presets/constant/hooks.d.ts +0 -2
- package/dist/presets/constant/hooks.js +1 -3
- package/dist/presets/constant/hooks.js.map +1 -1
- package/dist/presets/files/generate-framework-info.js +68 -0
- package/dist/presets/files/generate-framework-info.js.map +1 -0
- package/dist/presets/files/{generateProjectConfig.js → generate-project-config.js} +1 -1
- package/dist/presets/files/generate-project-config.js.map +1 -0
- package/dist/presets/files/{writeFileToDist.js → write-file-to-dist.js} +1 -1
- package/dist/presets/files/write-file-to-dist.js.map +1 -0
- package/dist/presets/hooks/build.js +1 -3
- package/dist/presets/hooks/build.js.map +1 -1
- package/dist/presets/index.js +3 -5
- package/dist/presets/index.js.map +1 -1
- package/dist/util/{appConfig.d.ts → app-config.d.ts} +2 -2
- package/dist/util/{appConfig.js → app-config.js} +4 -3
- package/dist/util/app-config.js.map +1 -0
- package/dist/util/defineConfig.d.ts +5 -5
- package/dist/util/defineConfig.js.map +1 -1
- package/dist/util/index.d.ts +9 -1
- package/dist/util/index.js +54 -23
- package/dist/util/index.js.map +1 -1
- package/package.json +36 -39
- package/postinstall.js +1 -17
- package/src/cli.ts +185 -132
- package/src/commands/custom-command.ts +22 -0
- package/src/create/{fetchTemplate.ts → fetch-template.ts} +30 -35
- package/src/create/project.ts +31 -78
- package/src/create/template-creator.ts +325 -0
- package/src/doctor/validators.js +1 -0
- package/src/doctor/validators.ts +8 -6
- package/src/platform-weapp/apis-list.ts +33 -0
- package/src/platform-weapp/apis.ts +48 -0
- package/src/platform-weapp/components-react.ts +81 -0
- package/src/platform-weapp/components.ts +521 -0
- package/src/platform-weapp/index.ts +25 -0
- package/src/platform-weapp/program.ts +70 -0
- package/src/platform-weapp/runtime-utils.ts +57 -0
- package/src/platform-weapp/runtime.ts +6 -0
- package/src/platform-weapp/template.ts +150 -0
- package/src/presets/commands/build.ts +20 -40
- package/src/presets/commands/init.ts +1 -4
- package/src/presets/constant/hooks.js +12 -0
- package/src/presets/constant/hooks.ts +0 -2
- package/src/presets/files/{generateFrameworkInfo.ts → generate-framework-info.ts} +7 -1
- package/src/presets/hooks/build.ts +1 -3
- package/src/presets/index.ts +3 -5
- package/src/util/app-config.js +1 -0
- package/src/util/{appConfig.ts → app-config.ts} +5 -4
- package/src/util/defineConfig.ts +6 -6
- package/src/util/index.ts +67 -25
- package/templates/default/config/dev.js +1 -1
- package/templates/default/config/index.js +28 -40
- package/templates/default/config/prod.js +1 -1
- package/templates/default/package.json.tmpl +2 -17
- package/templates/default/types/global.d.ts +0 -4
- package/templates/plugin-compile/README.md +3 -1
- package/templates/plugin-compile/package.json.tmpl +1 -2
- package/templates/plugin-compile/src/index.ts +18 -28
- package/LICENSE +0 -174
- package/dist/commands/customCommand.js +0 -23
- package/dist/commands/customCommand.js.map +0 -1
- package/dist/config/packagesManagement.d.ts +0 -19
- package/dist/config/packagesManagement.js +0 -22
- package/dist/config/packagesManagement.js.map +0 -1
- package/dist/create/fetchTemplate.js.map +0 -1
- package/dist/create/page.d.ts +0 -65
- package/dist/create/page.js +0 -266
- package/dist/create/page.js.map +0 -1
- package/dist/create/plugin.d.ts +0 -16
- package/dist/create/plugin.js +0 -77
- package/dist/create/plugin.js.map +0 -1
- package/dist/presets/commands/config.js +0 -121
- package/dist/presets/commands/config.js.map +0 -1
- package/dist/presets/commands/create.js +0 -112
- package/dist/presets/commands/create.js.map +0 -1
- package/dist/presets/commands/doctor.js +0 -15
- package/dist/presets/commands/doctor.js.map +0 -1
- package/dist/presets/commands/global-config.d.ts +0 -3
- package/dist/presets/commands/global-config.js +0 -175
- package/dist/presets/commands/global-config.js.map +0 -1
- package/dist/presets/commands/help.d.ts +0 -3
- package/dist/presets/commands/help.js +0 -16
- package/dist/presets/commands/help.js.map +0 -1
- package/dist/presets/commands/info.d.ts +0 -3
- package/dist/presets/commands/info.js +0 -96
- package/dist/presets/commands/info.js.map +0 -1
- package/dist/presets/commands/inspect.d.ts +0 -3
- package/dist/presets/commands/inspect.js +0 -155
- package/dist/presets/commands/inspect.js.map +0 -1
- package/dist/presets/commands/update.d.ts +0 -3
- package/dist/presets/commands/update.js +0 -187
- package/dist/presets/commands/update.js.map +0 -1
- package/dist/presets/files/generateFrameworkInfo.d.ts +0 -3
- package/dist/presets/files/generateFrameworkInfo.js +0 -30
- package/dist/presets/files/generateFrameworkInfo.js.map +0 -1
- package/dist/presets/files/generateProjectConfig.d.ts +0 -3
- package/dist/presets/files/generateProjectConfig.js.map +0 -1
- package/dist/presets/files/writeFileToDist.d.ts +0 -3
- package/dist/presets/files/writeFileToDist.js.map +0 -1
- package/dist/presets/hooks/create.d.ts +0 -3
- package/dist/presets/hooks/create.js +0 -42
- package/dist/presets/hooks/create.js.map +0 -1
- package/dist/presets/platforms/plugin.d.ts +0 -3
- package/dist/presets/platforms/plugin.js +0 -106
- package/dist/presets/platforms/plugin.js.map +0 -1
- package/dist/presets/platforms/rn.d.ts +0 -3
- package/dist/presets/platforms/rn.js +0 -130
- package/dist/presets/platforms/rn.js.map +0 -1
- package/dist/util/appConfig.js.map +0 -1
- package/dist/util/createPage.d.ts +0 -9
- package/dist/util/createPage.js +0 -114
- package/dist/util/createPage.js.map +0 -1
- package/src/__tests__/__mocks__/presets.ts +0 -15
- package/src/__tests__/build-config.spec.ts +0 -66
- package/src/__tests__/cli.spec.ts +0 -226
- package/src/__tests__/config.spec.ts +0 -224
- package/src/__tests__/doctor-config.spec.ts +0 -918
- package/src/__tests__/doctor-recommand.spec.ts +0 -136
- package/src/__tests__/doctor.spec.ts +0 -94
- package/src/__tests__/dotenv-parse.spec.ts +0 -105
- package/src/__tests__/env/.env +0 -2
- package/src/__tests__/fixtures/default/.env +0 -3
- package/src/__tests__/fixtures/default/.env.development +0 -1
- package/src/__tests__/fixtures/default/.env.local +0 -1
- package/src/__tests__/fixtures/default/.env.pre +0 -3
- package/src/__tests__/fixtures/default/.env.production +0 -1
- package/src/__tests__/fixtures/default/.env.uat +0 -5
- package/src/__tests__/fixtures/default/.env.uat.local +0 -1
- package/src/__tests__/fixtures/default/babel.config.js +0 -10
- package/src/__tests__/fixtures/default/config/dev.js +0 -9
- package/src/__tests__/fixtures/default/config/index.js +0 -84
- package/src/__tests__/fixtures/default/config/prod.js +0 -18
- package/src/__tests__/fixtures/default/package.json +0 -27
- package/src/__tests__/fixtures/default/src/app.config.js +0 -11
- package/src/__tests__/fixtures/default/src/app.js +0 -16
- package/src/__tests__/fixtures/default/src/app.scss +0 -0
- package/src/__tests__/fixtures/default/src/index.html +0 -19
- package/src/__tests__/fixtures/default/src/pages/index/index.config.js +0 -3
- package/src/__tests__/fixtures/default/src/pages/index/index.jsx +0 -22
- package/src/__tests__/fixtures/default/src/pages/index/index.scss +0 -0
- package/src/__tests__/info.spec.ts +0 -72
- package/src/__tests__/inspect.spec.ts +0 -160
- package/src/__tests__/update.spec.ts +0 -310
- package/src/__tests__/utils/index.ts +0 -54
- package/src/commands/customCommand.ts +0 -22
- package/src/config/packagesManagement.ts +0 -20
- package/src/config/rn-stylelint.json +0 -4
- package/src/create/page.ts +0 -325
- package/src/create/plugin.ts +0 -55
- package/src/presets/commands/config.ts +0 -86
- package/src/presets/commands/create.ts +0 -104
- package/src/presets/commands/doctor.ts +0 -21
- package/src/presets/commands/global-config.ts +0 -140
- package/src/presets/commands/help.ts +0 -17
- package/src/presets/commands/info.ts +0 -81
- package/src/presets/commands/inspect.ts +0 -137
- package/src/presets/commands/update.ts +0 -175
- package/src/presets/hooks/create.ts +0 -9
- package/src/presets/platforms/plugin.ts +0 -75
- package/src/presets/platforms/rn.ts +0 -125
- package/src/util/createPage.ts +0 -139
- package/templates/default/babel.config.js +0 -14
- /package/dist/create/{fetchTemplate.d.ts → fetch-template.d.ts} +0 -0
- /package/dist/presets/{commands/config.d.ts → files/generate-framework-info.d.ts} +0 -0
- /package/dist/presets/{commands/create.d.ts → files/generate-project-config.d.ts} +0 -0
- /package/dist/presets/{commands/doctor.d.ts → files/write-file-to-dist.d.ts} +0 -0
- /package/src/presets/files/{generateProjectConfig.ts → generate-project-config.ts} +0 -0
- /package/src/presets/files/{writeFileToDist.ts → write-file-to-dist.ts} +0 -0
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { chalk, fs } from '@spcsn/taro-helper';
|
|
4
|
-
|
|
5
|
-
import { run } from './utils';
|
|
6
|
-
|
|
7
|
-
jest.mock('cli-highlight', () => {
|
|
8
|
-
return {
|
|
9
|
-
__esModule: true,
|
|
10
|
-
default(str) {
|
|
11
|
-
return str;
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
jest.mock('@spcsn/taro-helper', () => {
|
|
17
|
-
const helper = jest.requireActual('@spcsn/taro-helper');
|
|
18
|
-
const fs = helper.fs;
|
|
19
|
-
return {
|
|
20
|
-
__esModule: true,
|
|
21
|
-
...helper,
|
|
22
|
-
fs: {
|
|
23
|
-
...fs,
|
|
24
|
-
writeFileSync: jest.fn(),
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const runInspect = run('inspect', [
|
|
30
|
-
'commands/build',
|
|
31
|
-
'commands/inspect',
|
|
32
|
-
require.resolve('@spcsn/taro-plugin-platform-weapp'),
|
|
33
|
-
]);
|
|
34
|
-
|
|
35
|
-
describe('inspect', () => {
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
jest.resetModules();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it("should exit because there isn't a Taro project", async () => {
|
|
41
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
42
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
43
|
-
|
|
44
|
-
exitSpy.mockImplementation(() => {
|
|
45
|
-
throw new Error();
|
|
46
|
-
});
|
|
47
|
-
logSpy.mockImplementation(() => {});
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
await runInspect('');
|
|
51
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
52
|
-
|
|
53
|
-
expect(exitSpy).toBeCalledWith(1);
|
|
54
|
-
expect(logSpy).toBeCalledWith(chalk.red('找不到项目配置文件config/index,请确定当前目录是 Taro 项目根目录!'));
|
|
55
|
-
|
|
56
|
-
exitSpy.mockRestore();
|
|
57
|
-
logSpy.mockRestore();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("should exit when user haven't pass correct type", async () => {
|
|
61
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
62
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
63
|
-
|
|
64
|
-
exitSpy.mockImplementation(() => {
|
|
65
|
-
throw new Error();
|
|
66
|
-
});
|
|
67
|
-
logSpy.mockImplementation(() => {});
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
await runInspect(path.resolve(__dirname, 'fixtures/default'));
|
|
71
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
72
|
-
|
|
73
|
-
expect(exitSpy).toBeCalledWith(0);
|
|
74
|
-
expect(logSpy).toBeCalledWith(chalk.red('请传入正确的编译类型!'));
|
|
75
|
-
|
|
76
|
-
exitSpy.mockRestore();
|
|
77
|
-
logSpy.mockRestore();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('should log config', async () => {
|
|
81
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
82
|
-
const logSpy = jest.spyOn(console, 'info');
|
|
83
|
-
|
|
84
|
-
exitSpy.mockImplementation(() => {
|
|
85
|
-
throw new Error();
|
|
86
|
-
});
|
|
87
|
-
logSpy.mockImplementation(() => {});
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
91
|
-
await runInspect(appPath, {
|
|
92
|
-
options: {
|
|
93
|
-
type: 'weapp',
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
97
|
-
|
|
98
|
-
expect(exitSpy).toBeCalledWith(0);
|
|
99
|
-
expect(logSpy).toBeCalledTimes(1);
|
|
100
|
-
|
|
101
|
-
exitSpy.mockRestore();
|
|
102
|
-
logSpy.mockRestore();
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('should log specific config', async () => {
|
|
106
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
107
|
-
const logSpy = jest.spyOn(console, 'info');
|
|
108
|
-
const errorSpy = jest.spyOn(console, 'error');
|
|
109
|
-
|
|
110
|
-
exitSpy.mockImplementation(() => {
|
|
111
|
-
throw new Error();
|
|
112
|
-
});
|
|
113
|
-
logSpy.mockImplementation(() => {});
|
|
114
|
-
errorSpy.mockImplementation(() => {});
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
118
|
-
await runInspect(appPath, {
|
|
119
|
-
options: {
|
|
120
|
-
type: 'weapp',
|
|
121
|
-
},
|
|
122
|
-
args: ['resolve.mainFields.0'],
|
|
123
|
-
});
|
|
124
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
125
|
-
|
|
126
|
-
expect(exitSpy).toBeCalledWith(0);
|
|
127
|
-
expect(logSpy).toBeCalledTimes(1);
|
|
128
|
-
expect(logSpy).toBeCalledWith("'browser'");
|
|
129
|
-
|
|
130
|
-
exitSpy.mockRestore();
|
|
131
|
-
logSpy.mockRestore();
|
|
132
|
-
errorSpy.mockRestore();
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should output config', async () => {
|
|
136
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
137
|
-
const writeFileSync = fs.writeFileSync as jest.Mock<any>;
|
|
138
|
-
const outputPath = 'project-config.js';
|
|
139
|
-
|
|
140
|
-
exitSpy.mockImplementation(() => {
|
|
141
|
-
throw new Error();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
146
|
-
await runInspect(appPath, {
|
|
147
|
-
options: {
|
|
148
|
-
type: 'weapp',
|
|
149
|
-
output: outputPath,
|
|
150
|
-
},
|
|
151
|
-
args: ['resolve.mainFields.0'],
|
|
152
|
-
});
|
|
153
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
154
|
-
|
|
155
|
-
expect(exitSpy).toBeCalledWith(0);
|
|
156
|
-
expect(writeFileSync).toBeCalledWith(outputPath, "'browser'");
|
|
157
|
-
|
|
158
|
-
exitSpy.mockRestore();
|
|
159
|
-
});
|
|
160
|
-
});
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { chalk, fs, PROJECT_CONFIG, shouldUseCnpm, shouldUseYarn } from '@spcsn/taro-helper';
|
|
4
|
-
import { exec } from 'child_process';
|
|
5
|
-
|
|
6
|
-
import { getPkgVersion } from '../util';
|
|
7
|
-
import { run } from './utils';
|
|
8
|
-
|
|
9
|
-
const runUpdate = run('update', ['commands/update']);
|
|
10
|
-
const lastestVersion = getPkgVersion();
|
|
11
|
-
|
|
12
|
-
jest.mock('child_process', () => {
|
|
13
|
-
const exec = jest.fn();
|
|
14
|
-
exec.mockReturnValue({
|
|
15
|
-
stdout: {
|
|
16
|
-
on() {},
|
|
17
|
-
},
|
|
18
|
-
stderr: {
|
|
19
|
-
on() {},
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
__esModule: true,
|
|
24
|
-
exec,
|
|
25
|
-
};
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
jest.mock('ora', () => {
|
|
29
|
-
const ora = jest.fn();
|
|
30
|
-
ora.mockReturnValue({
|
|
31
|
-
start() {
|
|
32
|
-
return {
|
|
33
|
-
stop() {},
|
|
34
|
-
warn() {},
|
|
35
|
-
succeed() {},
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
return ora;
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
jest.mock('@spcsn/taro-helper', () => {
|
|
43
|
-
const helper = jest.requireActual('@spcsn/taro-helper');
|
|
44
|
-
const fs = helper.fs;
|
|
45
|
-
return {
|
|
46
|
-
__esModule: true,
|
|
47
|
-
...helper,
|
|
48
|
-
shouldUseCnpm: jest.fn(),
|
|
49
|
-
shouldUseYarn: jest.fn(),
|
|
50
|
-
chalk: {
|
|
51
|
-
red: jest.fn(),
|
|
52
|
-
green() {},
|
|
53
|
-
},
|
|
54
|
-
fs: {
|
|
55
|
-
...fs,
|
|
56
|
-
writeJson: jest.fn(),
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
jest.mock('latest-version', () => () => lastestVersion);
|
|
62
|
-
|
|
63
|
-
function updatePkg(pkgPath: string, version: string) {
|
|
64
|
-
let packageMap = require(pkgPath);
|
|
65
|
-
packageMap = {
|
|
66
|
-
...packageMap,
|
|
67
|
-
dependencies: {
|
|
68
|
-
...packageMap.dependencies,
|
|
69
|
-
'@spcsn/taro-shared': version,
|
|
70
|
-
'@spcsn/taro': version,
|
|
71
|
-
'@spcsn/taro-cli': version,
|
|
72
|
-
'@spcsn/taro-components': version,
|
|
73
|
-
'@spcsn/taro-api': version,
|
|
74
|
-
'@spcsn/taro-helper': version,
|
|
75
|
-
'@spcsn/taro-react': version,
|
|
76
|
-
'@spcsn/taro-runner-utils': version,
|
|
77
|
-
'@spcsn/taro-runtime': version,
|
|
78
|
-
'@spcsn/taro-service': version,
|
|
79
|
-
'@spcsn/taro-plugin-platform-weapp': version,
|
|
80
|
-
'@spcsn/taro-plugin-framework-react': version,
|
|
81
|
-
'@spcsn/taro-plugin-generator': version,
|
|
82
|
-
'@spcsn/taro-vite-runner': version,
|
|
83
|
-
'@spcsn/taro-binding': version,
|
|
84
|
-
},
|
|
85
|
-
devDependencies: {
|
|
86
|
-
...packageMap.devDependencies,
|
|
87
|
-
'babel-preset-taro': version,
|
|
88
|
-
'babel-plugin-transform-taroapi': version,
|
|
89
|
-
'postcss-plugin-constparse': version,
|
|
90
|
-
'postcss-pxtransform': version,
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
return packageMap;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
describe('update', () => {
|
|
97
|
-
const execMocked = exec as unknown as jest.Mock<any>;
|
|
98
|
-
const shouldUseCnpmMocked = shouldUseCnpm as jest.Mock<any>;
|
|
99
|
-
const shouldUseYarnMocked = shouldUseYarn as jest.Mock<any>;
|
|
100
|
-
const writeJson = fs.writeJson as jest.Mock<any>;
|
|
101
|
-
|
|
102
|
-
beforeEach(() => {
|
|
103
|
-
shouldUseCnpmMocked.mockReturnValue(false);
|
|
104
|
-
shouldUseYarnMocked.mockReturnValue(false);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
afterEach(() => {
|
|
108
|
-
execMocked.mockClear();
|
|
109
|
-
shouldUseCnpmMocked.mockReset();
|
|
110
|
-
shouldUseYarnMocked.mockReset();
|
|
111
|
-
writeJson.mockClear();
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('should log errors', async () => {
|
|
115
|
-
const spy = jest.spyOn(console, 'log');
|
|
116
|
-
spy.mockImplementation(() => {});
|
|
117
|
-
await runUpdate('', {
|
|
118
|
-
options: {
|
|
119
|
-
npm: 'npm',
|
|
120
|
-
disableGlobalConfig: true,
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
expect(spy).toBeCalledTimes(3);
|
|
124
|
-
spy.mockRestore();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('should update self', async () => {
|
|
128
|
-
await runUpdate('', {
|
|
129
|
-
args: ['self'],
|
|
130
|
-
options: {
|
|
131
|
-
npm: 'npm',
|
|
132
|
-
disableGlobalConfig: true,
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
expect(execMocked).toBeCalledWith(`npm i -g @spcsn/taro-cli@${lastestVersion}`);
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('should update self using yarn', async () => {
|
|
139
|
-
shouldUseCnpmMocked.mockReturnValue(true);
|
|
140
|
-
await runUpdate('', {
|
|
141
|
-
args: ['self'],
|
|
142
|
-
options: {
|
|
143
|
-
npm: 'yarn',
|
|
144
|
-
disableGlobalConfig: true,
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
expect(execMocked).toBeCalledWith(`yarn global add @spcsn/taro-cli@${lastestVersion}`);
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
it('should update self using pnpm', async () => {
|
|
151
|
-
shouldUseCnpmMocked.mockReturnValue(true);
|
|
152
|
-
await runUpdate('', {
|
|
153
|
-
args: ['self'],
|
|
154
|
-
options: {
|
|
155
|
-
npm: 'pnpm',
|
|
156
|
-
disableGlobalConfig: true,
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
expect(execMocked).toBeCalledWith(`pnpm add -g @spcsn/taro-cli@${lastestVersion}`);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('should update self using cnpm', async () => {
|
|
163
|
-
shouldUseCnpmMocked.mockReturnValue(true);
|
|
164
|
-
await runUpdate('', {
|
|
165
|
-
args: ['self'],
|
|
166
|
-
options: {
|
|
167
|
-
npm: 'cnpm',
|
|
168
|
-
disableGlobalConfig: true,
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
expect(execMocked).toBeCalledWith(`cnpm i -g @spcsn/taro-cli@${lastestVersion}`);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it('should update self to specific version', async () => {
|
|
175
|
-
const version = '3.0.0-beta.0';
|
|
176
|
-
await runUpdate('', {
|
|
177
|
-
args: ['self', version],
|
|
178
|
-
options: {
|
|
179
|
-
npm: 'npm',
|
|
180
|
-
disableGlobalConfig: true,
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
expect(execMocked).toBeCalledWith(`npm i -g @spcsn/taro-cli@${version}`);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it("should throw when there isn't a Taro project", async () => {
|
|
187
|
-
const chalkMocked = chalk.red as unknown as jest.Mock<any>;
|
|
188
|
-
const exitSpy = jest.spyOn(process, 'exit');
|
|
189
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
190
|
-
exitSpy.mockImplementation(() => {
|
|
191
|
-
throw new Error();
|
|
192
|
-
});
|
|
193
|
-
logSpy.mockImplementation(() => {});
|
|
194
|
-
try {
|
|
195
|
-
await runUpdate('', {
|
|
196
|
-
args: ['project'],
|
|
197
|
-
options: {
|
|
198
|
-
npm: 'npm',
|
|
199
|
-
disableGlobalConfig: true,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
203
|
-
expect(exitSpy).toBeCalledWith(1);
|
|
204
|
-
expect(chalkMocked).toBeCalledWith(`找不到项目配置文件 ${PROJECT_CONFIG},请确定当前目录是 Taro 项目根目录!`);
|
|
205
|
-
exitSpy.mockRestore();
|
|
206
|
-
logSpy.mockRestore();
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
it('should update project', async () => {
|
|
210
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
211
|
-
const pkgPath = path.join(appPath, 'package.json');
|
|
212
|
-
const packageMap = updatePkg(pkgPath, lastestVersion);
|
|
213
|
-
|
|
214
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
215
|
-
logSpy.mockImplementation(() => {});
|
|
216
|
-
|
|
217
|
-
await runUpdate(appPath, {
|
|
218
|
-
args: ['project'],
|
|
219
|
-
options: {
|
|
220
|
-
npm: 'npm',
|
|
221
|
-
disableGlobalConfig: true,
|
|
222
|
-
},
|
|
223
|
-
});
|
|
224
|
-
expect(writeJson.mock.calls[0][0]).toEqual(pkgPath);
|
|
225
|
-
expect(writeJson.mock.calls[0][1]).toEqual(packageMap);
|
|
226
|
-
expect(execMocked).toBeCalledWith('npm install');
|
|
227
|
-
|
|
228
|
-
logSpy.mockRestore();
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
it('should update project to specific version', async () => {
|
|
232
|
-
const version = '3.0.0-beta.4';
|
|
233
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
234
|
-
const pkgPath = path.join(appPath, 'package.json');
|
|
235
|
-
const packageMap = updatePkg(pkgPath, version);
|
|
236
|
-
|
|
237
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
238
|
-
logSpy.mockImplementation(() => {});
|
|
239
|
-
|
|
240
|
-
await runUpdate(appPath, {
|
|
241
|
-
args: ['project', version],
|
|
242
|
-
options: {
|
|
243
|
-
npm: 'npm',
|
|
244
|
-
disableGlobalConfig: true,
|
|
245
|
-
},
|
|
246
|
-
});
|
|
247
|
-
expect(writeJson.mock.calls[0][0]).toEqual(pkgPath);
|
|
248
|
-
expect(writeJson.mock.calls[0][1]).toEqual(packageMap);
|
|
249
|
-
expect(execMocked).toBeCalledWith('npm install');
|
|
250
|
-
|
|
251
|
-
logSpy.mockRestore();
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
it('should update project with yarn', async () => {
|
|
255
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
256
|
-
|
|
257
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
258
|
-
logSpy.mockImplementation(() => {});
|
|
259
|
-
shouldUseYarnMocked.mockReturnValue(true);
|
|
260
|
-
|
|
261
|
-
await runUpdate(appPath, {
|
|
262
|
-
args: ['project'],
|
|
263
|
-
options: {
|
|
264
|
-
npm: 'yarn',
|
|
265
|
-
disableGlobalConfig: true,
|
|
266
|
-
},
|
|
267
|
-
});
|
|
268
|
-
expect(execMocked).toBeCalledWith('yarn install');
|
|
269
|
-
|
|
270
|
-
logSpy.mockRestore();
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('should update project with pnpm', async () => {
|
|
274
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
275
|
-
|
|
276
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
277
|
-
logSpy.mockImplementation(() => {});
|
|
278
|
-
shouldUseCnpmMocked.mockReturnValue(true);
|
|
279
|
-
|
|
280
|
-
await runUpdate(appPath, {
|
|
281
|
-
args: ['project'],
|
|
282
|
-
options: {
|
|
283
|
-
npm: 'pnpm',
|
|
284
|
-
disableGlobalConfig: true,
|
|
285
|
-
},
|
|
286
|
-
});
|
|
287
|
-
expect(execMocked).toBeCalledWith('pnpm install');
|
|
288
|
-
|
|
289
|
-
logSpy.mockRestore();
|
|
290
|
-
});
|
|
291
|
-
|
|
292
|
-
it('should update project with cnpm', async () => {
|
|
293
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
294
|
-
|
|
295
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
296
|
-
logSpy.mockImplementation(() => {});
|
|
297
|
-
shouldUseCnpmMocked.mockReturnValue(true);
|
|
298
|
-
|
|
299
|
-
await runUpdate(appPath, {
|
|
300
|
-
args: ['project'],
|
|
301
|
-
options: {
|
|
302
|
-
npm: 'cnpm',
|
|
303
|
-
disableGlobalConfig: true,
|
|
304
|
-
},
|
|
305
|
-
});
|
|
306
|
-
expect(execMocked).toBeCalledWith('cnpm install');
|
|
307
|
-
|
|
308
|
-
logSpy.mockRestore();
|
|
309
|
-
});
|
|
310
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { Config, Kernel } from '@spcsn/taro-service';
|
|
4
|
-
|
|
5
|
-
interface IRunOptions {
|
|
6
|
-
options?: Record<string, string | boolean>;
|
|
7
|
-
args?: string[];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface IRun {
|
|
11
|
-
(appPath: string, options?: IRunOptions): Promise<Kernel>;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function run(name: string, presets: string[] = []): IRun {
|
|
15
|
-
return async function (appPath, opts = {}) {
|
|
16
|
-
const { options = {}, args = [] } = opts;
|
|
17
|
-
|
|
18
|
-
const config = new Config({
|
|
19
|
-
appPath: appPath,
|
|
20
|
-
disableGlobalConfig: !!options.disableGlobalConfig,
|
|
21
|
-
});
|
|
22
|
-
await config.init({
|
|
23
|
-
mode: (options.mode || process.env.NODE_ENV) as string,
|
|
24
|
-
command: name,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const kernel = new Kernel({
|
|
28
|
-
appPath: appPath,
|
|
29
|
-
presets: [
|
|
30
|
-
path.resolve(__dirname, '../__mocks__', 'presets.ts'),
|
|
31
|
-
...presets.map((e) => (path.isAbsolute(e) ? e : path.resolve(__dirname, '../../presets', `${e}.ts`))),
|
|
32
|
-
],
|
|
33
|
-
plugins: [],
|
|
34
|
-
config,
|
|
35
|
-
});
|
|
36
|
-
kernel.optsPlugins ||= [];
|
|
37
|
-
|
|
38
|
-
const type = options.type;
|
|
39
|
-
if (typeof type === 'string' && !presets.some((e) => e.includes(type))) {
|
|
40
|
-
kernel.optsPlugins.push(require.resolve(`@spcsn/taro-plugin-platform-${options.type}`));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
await kernel.run({
|
|
44
|
-
name,
|
|
45
|
-
opts: {
|
|
46
|
-
_: [name, ...args],
|
|
47
|
-
options,
|
|
48
|
-
isHelp: false,
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
return kernel;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { Kernel } from '@spcsn/taro-service';
|
|
2
|
-
|
|
3
|
-
export default function customCommand(command: string, kernel: Kernel, args: { _: string[]; [key: string]: any }) {
|
|
4
|
-
if (typeof command === 'string') {
|
|
5
|
-
const options: any = {};
|
|
6
|
-
const excludeKeys = ['_', 'version', 'v', 'help', 'h', 'disable-global-config'];
|
|
7
|
-
Object.keys(args).forEach((key) => {
|
|
8
|
-
if (!excludeKeys.includes(key)) {
|
|
9
|
-
options[key] = args[key];
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
kernel.run({
|
|
14
|
-
name: command,
|
|
15
|
-
opts: {
|
|
16
|
-
_: args._,
|
|
17
|
-
options,
|
|
18
|
-
isHelp: args.h,
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const packagesManagement = {
|
|
2
|
-
yarn: {
|
|
3
|
-
command: 'yarn install',
|
|
4
|
-
globalCommand: 'yarn global add @spcsn/taro-cli',
|
|
5
|
-
},
|
|
6
|
-
pnpm: {
|
|
7
|
-
command: 'pnpm install',
|
|
8
|
-
globalCommand: 'pnpm add -g @spcsn/taro-cli',
|
|
9
|
-
},
|
|
10
|
-
cnpm: {
|
|
11
|
-
command: 'cnpm install',
|
|
12
|
-
globalCommand: 'cnpm i -g @spcsn/taro-cli',
|
|
13
|
-
},
|
|
14
|
-
npm: {
|
|
15
|
-
command: 'npm install',
|
|
16
|
-
globalCommand: 'npm i -g @spcsn/taro-cli',
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default packagesManagement;
|