@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,136 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { chalk, fs } from '@spcsn/taro-helper';
|
|
4
|
-
|
|
5
|
-
import doctor from '../doctor';
|
|
6
|
-
|
|
7
|
-
const validator = doctor.validators[3];
|
|
8
|
-
|
|
9
|
-
jest.mock('@spcsn/taro-helper', () => {
|
|
10
|
-
const helper = jest.requireActual('@spcsn/taro-helper');
|
|
11
|
-
const fs = helper.fs;
|
|
12
|
-
return {
|
|
13
|
-
__esModule: true,
|
|
14
|
-
...helper,
|
|
15
|
-
fs: {
|
|
16
|
-
...fs,
|
|
17
|
-
readdirSync: jest.fn(),
|
|
18
|
-
existsSync: jest.fn(),
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('recommand validator of doctor', () => {
|
|
24
|
-
const existsSyncMocked = fs.existsSync as jest.Mock<any>;
|
|
25
|
-
const readdirSyncMocked = fs.readdirSync as jest.Mock<any>;
|
|
26
|
-
|
|
27
|
-
beforeEach(() => {
|
|
28
|
-
jest.resetModules();
|
|
29
|
-
existsSyncMocked.mockReset();
|
|
30
|
-
readdirSyncMocked.mockReset();
|
|
31
|
-
existsSyncMocked.mockReturnValue(true);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it.skip("should exit because there isn't a Taro project", async () => {
|
|
35
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
36
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
37
|
-
|
|
38
|
-
exitSpy.mockImplementation(() => {
|
|
39
|
-
throw new Error();
|
|
40
|
-
});
|
|
41
|
-
logSpy.mockImplementation(() => {});
|
|
42
|
-
existsSyncMocked.mockReturnValue(false);
|
|
43
|
-
|
|
44
|
-
const MOCK_APP_PATH = 'src/';
|
|
45
|
-
try {
|
|
46
|
-
await validator({ appPath: MOCK_APP_PATH });
|
|
47
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
48
|
-
|
|
49
|
-
expect(exitSpy).toBeCalledWith(1);
|
|
50
|
-
const PROJECT_PACKAGE_PATH = path.join(MOCK_APP_PATH, 'package.json');
|
|
51
|
-
expect(logSpy).toBeCalledWith(chalk.red(`找不到${PROJECT_PACKAGE_PATH},请确定当前目录是Taro项目根目录!`));
|
|
52
|
-
|
|
53
|
-
exitSpy.mockRestore();
|
|
54
|
-
logSpy.mockRestore();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it.skip('should warn when test framework not found', async () => {
|
|
58
|
-
jest.doMock('./fixtures/default/package.json', () => ({
|
|
59
|
-
devDependencies: {
|
|
60
|
-
eslint: 1,
|
|
61
|
-
},
|
|
62
|
-
}));
|
|
63
|
-
readdirSyncMocked.mockReturnValue(['readme', '.gitignore', '.editorconfig']);
|
|
64
|
-
|
|
65
|
-
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') });
|
|
66
|
-
|
|
67
|
-
expect(lines.length).toBe(1);
|
|
68
|
-
expect(lines[0].desc).toBe(
|
|
69
|
-
'没有检查到常见的测试依赖(jest/mocha/ava/tape/jesmine/karma), 配置测试可以帮助提升项目质量',
|
|
70
|
-
);
|
|
71
|
-
expect(lines[0].valid).toBe(true);
|
|
72
|
-
expect(lines[0].solution).toBe(
|
|
73
|
-
'可以参考 https://github.com/NervJS/taro-ui-sample 项目, 其中已经包含了完整的测试配置与范例',
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
jest.dontMock('./fixtures/default/package.json');
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it.skip('should warn when Readme not found', async () => {
|
|
80
|
-
jest.doMock('./fixtures/default/package.json', () => ({
|
|
81
|
-
devDependencies: {
|
|
82
|
-
mocha: 1,
|
|
83
|
-
jslint: 1,
|
|
84
|
-
},
|
|
85
|
-
}));
|
|
86
|
-
readdirSyncMocked.mockReturnValue(['.gitignore', '.editorconfig']);
|
|
87
|
-
|
|
88
|
-
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') });
|
|
89
|
-
|
|
90
|
-
expect(lines.length).toBe(1);
|
|
91
|
-
expect(lines[0].desc).toBe(
|
|
92
|
-
'没有检查到 Readme (readme/readme.md/readme.markdown), 编写 Readme 可以方便其他人了解项目',
|
|
93
|
-
);
|
|
94
|
-
expect(lines[0].valid).toBe(true);
|
|
95
|
-
|
|
96
|
-
jest.dontMock('./fixtures/default/package.json');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it.skip('should warn when .gitignore not found', async () => {
|
|
100
|
-
jest.doMock('./fixtures/default/package.json', () => ({
|
|
101
|
-
devDependencies: {
|
|
102
|
-
jesmine: 1,
|
|
103
|
-
tslint: 1,
|
|
104
|
-
},
|
|
105
|
-
}));
|
|
106
|
-
readdirSyncMocked.mockReturnValue(['readme.markdown', '.editorconfig']);
|
|
107
|
-
|
|
108
|
-
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') });
|
|
109
|
-
|
|
110
|
-
expect(lines.length).toBe(1);
|
|
111
|
-
expect(lines[0].desc).toBe(
|
|
112
|
-
'没有检查到 .gitignore 配置, 配置 .gitignore 以避免将敏感信息或不必要的内容提交到代码仓库',
|
|
113
|
-
);
|
|
114
|
-
expect(lines[0].valid).toBe(true);
|
|
115
|
-
|
|
116
|
-
jest.dontMock('./fixtures/default/package.json');
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it.skip('should warn when .editorconfig not found', async () => {
|
|
120
|
-
jest.doMock('./fixtures/default/package.json', () => ({
|
|
121
|
-
devDependencies: {
|
|
122
|
-
karma: 1,
|
|
123
|
-
jshint: 1,
|
|
124
|
-
},
|
|
125
|
-
}));
|
|
126
|
-
readdirSyncMocked.mockReturnValue(['readme', '.gitignore']);
|
|
127
|
-
|
|
128
|
-
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') });
|
|
129
|
-
|
|
130
|
-
expect(lines.length).toBe(1);
|
|
131
|
-
expect(lines[0].desc).toBe('没有检查到 .editconfig 配置, 配置 editconfig 以统一项目成员编辑器的代码风格');
|
|
132
|
-
expect(lines[0].valid).toBe(true);
|
|
133
|
-
|
|
134
|
-
jest.dontMock('./fixtures/default/package.json');
|
|
135
|
-
});
|
|
136
|
-
});
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { chalk } from '@spcsn/taro-helper';
|
|
2
|
-
|
|
3
|
-
import { run } from './utils';
|
|
4
|
-
|
|
5
|
-
jest.mock('../doctor', () => {
|
|
6
|
-
return {
|
|
7
|
-
__esModule: true,
|
|
8
|
-
default: {
|
|
9
|
-
validators: [
|
|
10
|
-
() => ({
|
|
11
|
-
isValid: true,
|
|
12
|
-
messgaes: [
|
|
13
|
-
{
|
|
14
|
-
kind: 2,
|
|
15
|
-
content: 'Env Success',
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
}),
|
|
19
|
-
() =>
|
|
20
|
-
Promise.resolve({
|
|
21
|
-
isValid: false,
|
|
22
|
-
messgaes: [
|
|
23
|
-
{
|
|
24
|
-
kind: 1,
|
|
25
|
-
content: 'Config Error',
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
}),
|
|
29
|
-
() => ({
|
|
30
|
-
isValid: true,
|
|
31
|
-
messgaes: [
|
|
32
|
-
{
|
|
33
|
-
kind: 2,
|
|
34
|
-
content: 'Package Success',
|
|
35
|
-
},
|
|
36
|
-
],
|
|
37
|
-
}),
|
|
38
|
-
() => ({
|
|
39
|
-
isValid: true,
|
|
40
|
-
messgaes: [
|
|
41
|
-
{
|
|
42
|
-
kind: 2,
|
|
43
|
-
content: 'recommend Success',
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
}),
|
|
47
|
-
async () => ({
|
|
48
|
-
isValid: true,
|
|
49
|
-
messgaes: [
|
|
50
|
-
{
|
|
51
|
-
kind: 2,
|
|
52
|
-
content: 'doctor Success',
|
|
53
|
-
},
|
|
54
|
-
],
|
|
55
|
-
}),
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
jest.mock('ora', () => {
|
|
62
|
-
const ora = jest.fn();
|
|
63
|
-
ora.mockReturnValue({
|
|
64
|
-
start() {
|
|
65
|
-
return {
|
|
66
|
-
succeed() {},
|
|
67
|
-
};
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
return ora;
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const runDoctor = run('doctor', ['commands/doctor']);
|
|
74
|
-
|
|
75
|
-
describe('doctor', () => {
|
|
76
|
-
it("should exit because there isn't a Taro project", async () => {
|
|
77
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
78
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
79
|
-
|
|
80
|
-
exitSpy.mockImplementation(() => {
|
|
81
|
-
throw new Error();
|
|
82
|
-
});
|
|
83
|
-
logSpy.mockImplementation(() => {});
|
|
84
|
-
try {
|
|
85
|
-
await runDoctor('', { options: { disableGlobalConfig: true } });
|
|
86
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
87
|
-
|
|
88
|
-
expect(exitSpy).toBeCalledWith(1);
|
|
89
|
-
expect(logSpy).toBeCalledWith(chalk.red('找不到项目配置文件config/index,请确定当前目录是 Taro 项目根目录!'));
|
|
90
|
-
|
|
91
|
-
exitSpy.mockRestore();
|
|
92
|
-
logSpy.mockRestore();
|
|
93
|
-
});
|
|
94
|
-
});
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { dotenvParse } from '@spcsn/taro-helper';
|
|
4
|
-
import { Kernel } from '@spcsn/taro-service';
|
|
5
|
-
|
|
6
|
-
import CLI from '../cli';
|
|
7
|
-
|
|
8
|
-
jest.mock('@spcsn/taro-service');
|
|
9
|
-
const MockedKernel = Kernel as unknown as jest.Mock<Kernel>;
|
|
10
|
-
const APP_PATH = path.join(__dirname, 'fixtures/default');
|
|
11
|
-
|
|
12
|
-
function setProcessArgv(cmd: string) {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
process.argv = [null, ...cmd.split(' ')];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('inspect', () => {
|
|
18
|
-
let cli: CLI;
|
|
19
|
-
|
|
20
|
-
beforeAll(() => {
|
|
21
|
-
cli = new CLI(APP_PATH);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
beforeEach(() => {
|
|
25
|
-
MockedKernel.mockClear();
|
|
26
|
-
process.argv = [];
|
|
27
|
-
delete process.env.NODE_ENV;
|
|
28
|
-
delete process.env.TARO_ENV;
|
|
29
|
-
delete process.env.TARO_APP_TEST;
|
|
30
|
-
delete process.env.TARO_APP_ID;
|
|
31
|
-
delete process.env.JD_APP_TEST;
|
|
32
|
-
delete process.env.TARO_APP_DEFAULT;
|
|
33
|
-
delete process.env.TARO_APP_FOO;
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
afterEach(() => {
|
|
37
|
-
MockedKernel.mockClear();
|
|
38
|
-
process.argv = [];
|
|
39
|
-
delete process.env.NODE_ENV;
|
|
40
|
-
delete process.env.TARO_ENV;
|
|
41
|
-
delete process.env.TARO_APP_TEST;
|
|
42
|
-
delete process.env.TARO_APP_ID;
|
|
43
|
-
delete process.env.JD_APP_TEST;
|
|
44
|
-
delete process.env.TARO_APP_DEFAULT;
|
|
45
|
-
delete process.env.TARO_APP_FOO;
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
describe('cli mode env', () => {
|
|
49
|
-
it('dotenvParse .env .env.dev should success', async () => {
|
|
50
|
-
expect(process.env.TARO_test).toBeUndefined();
|
|
51
|
-
dotenvParse(path.resolve(__dirname, 'env'), 'TARO_', 'dev');
|
|
52
|
-
expect(process.env.TARO_test).toBe('123');
|
|
53
|
-
expect(process.env._TARO_test).toBeUndefined();
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('--watch true => 默认加载 .env.development', async () => {
|
|
57
|
-
setProcessArgv('taro build --watch --type weapp');
|
|
58
|
-
await cli.run();
|
|
59
|
-
expect(process.env.TARO_APP_TEST).toEqual('env-development');
|
|
60
|
-
expect(process.env.TARO_APP_DEFAULT).toEqual('default');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('--watch false => 默认加载 .env.production', async () => {
|
|
64
|
-
setProcessArgv('taro build --type weapp');
|
|
65
|
-
await cli.run();
|
|
66
|
-
expect(process.env.TARO_APP_TEST).toEqual('env-production');
|
|
67
|
-
expect(process.env.TARO_APP_DEFAULT).toEqual('default');
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('指定加载 .env.pre', async () => {
|
|
71
|
-
setProcessArgv('taro build --type weapp --mode pre');
|
|
72
|
-
await cli.run();
|
|
73
|
-
expect(process.env.TARO_APP_TEST).toEqual('env-pre');
|
|
74
|
-
expect(process.env.TARO_APP_DEFAULT).toEqual('default');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('env.local 比 .env 优先级更高', async () => {
|
|
78
|
-
setProcessArgv('taro build --type weapp --mode find404');
|
|
79
|
-
await cli.run();
|
|
80
|
-
expect(process.env.TARO_APP_TEST).toEqual('env-local');
|
|
81
|
-
expect(process.env.TARO_APP_DEFAULT).toEqual('default');
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('env.uat.local 比 .env.uat 优先级更高', async () => {
|
|
85
|
-
setProcessArgv('taro build --type weapp --mode uat');
|
|
86
|
-
await cli.run();
|
|
87
|
-
expect(process.env.TARO_APP_TEST).toEqual('env-uat-local');
|
|
88
|
-
expect(process.env.TARO_APP_DEFAULT).toEqual('default');
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it('自定义前缀: JD_APP_', async () => {
|
|
92
|
-
setProcessArgv('taro build --type weapp --mode uat --env-prefix JD_APP_');
|
|
93
|
-
await cli.run();
|
|
94
|
-
expect(process.env.JD_APP_TEST).toEqual('env-uat');
|
|
95
|
-
expect(process.env.TARO_APP_TEST).toEqual(undefined);
|
|
96
|
-
expect(process.env.TARO_APP_ID).toEqual('特殊变量appid');
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('环境变量可以相互引用', async () => {
|
|
100
|
-
setProcessArgv('taro build --type weapp --mode pre');
|
|
101
|
-
await cli.run();
|
|
102
|
-
expect(process.env.TARO_APP_FOO).toEqual('env-pre-foo');
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
package/src/__tests__/env/.env
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
TARO_APP_TEST=env-development
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
TARO_APP_TEST=env-local
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
TARO_APP_TEST=env-production
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
TARO_APP_TEST=env-uat-local
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
const config = {
|
|
2
|
-
projectName: 't2',
|
|
3
|
-
date: '2020-5-21',
|
|
4
|
-
designWidth: 750,
|
|
5
|
-
deviceRatio: {
|
|
6
|
-
640: 2.34 / 2,
|
|
7
|
-
750: 1,
|
|
8
|
-
828: 1.81 / 2
|
|
9
|
-
},
|
|
10
|
-
sourceRoot: 'src',
|
|
11
|
-
outputRoot: 'dist',
|
|
12
|
-
plugins: [],
|
|
13
|
-
defineConstants: {
|
|
14
|
-
},
|
|
15
|
-
copy: {
|
|
16
|
-
patterns: [
|
|
17
|
-
],
|
|
18
|
-
options: {
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
framework: 'react',
|
|
22
|
-
compiler: {
|
|
23
|
-
type: 'webpack5',
|
|
24
|
-
prebundle: {
|
|
25
|
-
enable: false
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
mini: {
|
|
29
|
-
output: {
|
|
30
|
-
clean: {
|
|
31
|
-
keep: ['project.config.json']
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
postcss: {
|
|
35
|
-
pxtransform: {
|
|
36
|
-
enable: true,
|
|
37
|
-
config: {
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
url: {
|
|
42
|
-
enable: true,
|
|
43
|
-
config: {
|
|
44
|
-
limit: 1024 // 设定转换尺寸上限
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
cssModules: {
|
|
48
|
-
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
49
|
-
config: {
|
|
50
|
-
namingPattern: 'module', // 转换模式,取值为 global/module
|
|
51
|
-
generateScopedName: '[name]__[local]___[hash:base64:5]'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
|
-
h5: {
|
|
57
|
-
output: {
|
|
58
|
-
clean: false
|
|
59
|
-
},
|
|
60
|
-
publicPath: '/',
|
|
61
|
-
staticDirectory: 'static',
|
|
62
|
-
postcss: {
|
|
63
|
-
autoprefixer: {
|
|
64
|
-
enable: true,
|
|
65
|
-
config: {
|
|
66
|
-
}
|
|
67
|
-
},
|
|
68
|
-
cssModules: {
|
|
69
|
-
enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
|
|
70
|
-
config: {
|
|
71
|
-
namingPattern: 'module', // 转换模式,取值为 global/module
|
|
72
|
-
generateScopedName: '[name]__[local]___[hash:base64:5]'
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
module.exports = function (merge) {
|
|
80
|
-
if (process.env.NODE_ENV === 'development') {
|
|
81
|
-
return merge({}, config, require('./dev'))
|
|
82
|
-
}
|
|
83
|
-
return merge({}, config, require('./prod'))
|
|
84
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
env: {
|
|
3
|
-
NODE_ENV: '"production"'
|
|
4
|
-
},
|
|
5
|
-
defineConstants: {
|
|
6
|
-
},
|
|
7
|
-
mini: {},
|
|
8
|
-
h5: {
|
|
9
|
-
/**
|
|
10
|
-
* 如果h5端编译后体积过大,可以使用webpack-bundle-analyzer插件对打包体积进行分析。
|
|
11
|
-
* 参考代码如下:
|
|
12
|
-
* webpackChain (chain) {
|
|
13
|
-
* chain.plugin('analyzer')
|
|
14
|
-
* .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "test",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"@babel/runtime": "^7.7.7",
|
|
5
|
-
"@spcsn/taro-shared": "3.0.0-beta.6",
|
|
6
|
-
"@spcsn/taro": "3.0.0-beta.6",
|
|
7
|
-
"@spcsn/taro-api": "3.0.0-beta.6",
|
|
8
|
-
"@spcsn/taro-cli": "3.0.0-beta.6",
|
|
9
|
-
"@spcsn/taro-components": "3.0.0-beta.6",
|
|
10
|
-
"@spcsn/taro-helper": "3.0.0-beta.6",
|
|
11
|
-
"@spcsn/taro-react": "3.0.0-beta.6",
|
|
12
|
-
"@spcsn/taro-runner-utils": "3.0.0-beta.6",
|
|
13
|
-
"@spcsn/taro-runtime": "3.0.0-beta.6",
|
|
14
|
-
"@spcsn/taro-service": "3.0.0-beta.6",
|
|
15
|
-
"@spcsn/taro-plugin-platform-weapp": "3.0.0-beta.6",
|
|
16
|
-
"@spcsn/taro-plugin-framework-react": "3.0.0-beta.6",
|
|
17
|
-
"@spcsn/taro-plugin-generator": "3.0.0-beta.6",
|
|
18
|
-
"@spcsn/taro-vite-runner": "3.0.0-beta.6",
|
|
19
|
-
"@spcsn/taro-binding": "0.1.0"
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"babel-preset-taro": "2.0.0",
|
|
23
|
-
"babel-plugin-transform-taroapi": "3.0.0-beta.6",
|
|
24
|
-
"postcss-plugin-constparse": "3.0.0-beta.6",
|
|
25
|
-
"postcss-pxtransform": "3.0.0-beta.6"
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Component } from 'react'
|
|
2
|
-
|
|
3
|
-
class App extends Component {
|
|
4
|
-
componentDidMount () {}
|
|
5
|
-
|
|
6
|
-
componentDidShow () {}
|
|
7
|
-
|
|
8
|
-
componentDidHide () {}
|
|
9
|
-
|
|
10
|
-
// this.props.children 是将要会渲染的页面
|
|
11
|
-
render () {
|
|
12
|
-
return this.props.children
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export default App
|
|
File without changes
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
<head>
|
|
4
|
-
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
5
|
-
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
|
|
6
|
-
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
7
|
-
<meta name="apple-touch-fullscreen" content="yes">
|
|
8
|
-
<meta name="format-detection" content="telephone=no,address=no">
|
|
9
|
-
<meta name="apple-mobile-web-app-status-bar-style" content="white">
|
|
10
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
|
|
11
|
-
<title></title>
|
|
12
|
-
<script>
|
|
13
|
-
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
|
|
14
|
-
</script>
|
|
15
|
-
</head>
|
|
16
|
-
<body>
|
|
17
|
-
<div id="app"></div>
|
|
18
|
-
</body>
|
|
19
|
-
</html>
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import React, { Component } from 'react'
|
|
2
|
-
import { View, Text } from '@spcsn/taro-components'
|
|
3
|
-
|
|
4
|
-
export default class Index extends Component {
|
|
5
|
-
componentWillMount () { }
|
|
6
|
-
|
|
7
|
-
componentDidMount () { }
|
|
8
|
-
|
|
9
|
-
componentWillUnmount () { }
|
|
10
|
-
|
|
11
|
-
componentDidShow () { }
|
|
12
|
-
|
|
13
|
-
componentDidHide () { }
|
|
14
|
-
|
|
15
|
-
render () {
|
|
16
|
-
return (
|
|
17
|
-
<View className='index'>
|
|
18
|
-
<Text>Hello world!</Text>
|
|
19
|
-
</View>
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
File without changes
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import * as path from 'node:path';
|
|
2
|
-
|
|
3
|
-
import { chalk } from '@spcsn/taro-helper';
|
|
4
|
-
|
|
5
|
-
import { getPkgVersion } from '../util';
|
|
6
|
-
import { run } from './utils';
|
|
7
|
-
|
|
8
|
-
jest.mock('envinfo', () => {
|
|
9
|
-
const envinfo = jest.requireActual('envinfo');
|
|
10
|
-
return {
|
|
11
|
-
__esModule: true,
|
|
12
|
-
async run(data, options) {
|
|
13
|
-
const res = await envinfo.run(data, { ...options, json: true });
|
|
14
|
-
return JSON.parse(res);
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const runInfo = run('info', ['commands/info']);
|
|
20
|
-
|
|
21
|
-
describe('info', () => {
|
|
22
|
-
it("should exit because there isn't a Taro project", async () => {
|
|
23
|
-
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>;
|
|
24
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
25
|
-
|
|
26
|
-
exitSpy.mockImplementation(() => {
|
|
27
|
-
throw new Error();
|
|
28
|
-
});
|
|
29
|
-
logSpy.mockImplementation(() => {});
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
await runInfo('');
|
|
33
|
-
} catch (error) {} // eslint-disable-line no-empty
|
|
34
|
-
|
|
35
|
-
expect(exitSpy).toBeCalledWith(1);
|
|
36
|
-
expect(logSpy).toBeCalledWith(chalk.red('找不到项目配置文件config/index,请确定当前目录是 Taro 项目根目录!'));
|
|
37
|
-
|
|
38
|
-
exitSpy.mockRestore();
|
|
39
|
-
logSpy.mockRestore();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should log information', async () => {
|
|
43
|
-
const logSpy = jest.spyOn(console, 'log');
|
|
44
|
-
logSpy.mockImplementation(() => {});
|
|
45
|
-
|
|
46
|
-
const appPath = path.resolve(__dirname, 'fixtures/default');
|
|
47
|
-
await runInfo(appPath);
|
|
48
|
-
|
|
49
|
-
expect(logSpy).toBeCalledTimes(1);
|
|
50
|
-
const res = logSpy.mock.calls[0][0];
|
|
51
|
-
const title = `Taro CLI ${getPkgVersion()} environment info`;
|
|
52
|
-
expect(res.hasOwnProperty(title)).toBeTruthy();
|
|
53
|
-
const info = res[title];
|
|
54
|
-
expect('System' in info).toBeTruthy();
|
|
55
|
-
expect('Binaries' in info).toBeTruthy();
|
|
56
|
-
// envinfo 还不支持 yarn workspace
|
|
57
|
-
// expect('npmPackages' in info).toBeTruthy()
|
|
58
|
-
// Note: windows 操作系统可能不存在 System.Shell
|
|
59
|
-
expect(Object.keys(info.System)).toEqual(expect.arrayContaining(['OS']));
|
|
60
|
-
// Note: 环境内可能不包括 Yarn
|
|
61
|
-
expect(Object.keys(info.Binaries)).toEqual(expect.arrayContaining(['Node', 'npm']));
|
|
62
|
-
// expect(info.npmPackages.hasOwnProperty('@spcsn/taro-helper')).toBeTruthy()
|
|
63
|
-
// expect(info.npmPackages.hasOwnProperty('@spcsn/taro-service')).toBeTruthy()
|
|
64
|
-
// expect(info.npmPackages.hasOwnProperty('@spcsn/taro')).toBeTruthy()
|
|
65
|
-
// expect(info.npmPackages.hasOwnProperty('@spcsn/taroize')).toBeTruthy()
|
|
66
|
-
// expect(info.npmPackages.hasOwnProperty('@spcsn/taro-webpack-runner')).toBeTruthy()
|
|
67
|
-
// expect(info.npmPackages.hasOwnProperty('babel-plugin-transform-taroapi')).toBeTruthy()
|
|
68
|
-
// expect(info.npmPackages.hasOwnProperty('postcss-pxtransform')).toBeTruthy()
|
|
69
|
-
|
|
70
|
-
logSpy.mockRestore();
|
|
71
|
-
});
|
|
72
|
-
});
|