@spcsn/taro-cli 0.1.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/LICENSE +174 -0
- package/README.md +0 -0
- package/bin/taro +7 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +266 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/customCommand.d.ts +5 -0
- package/dist/commands/customCommand.js +23 -0
- package/dist/commands/customCommand.js.map +1 -0
- package/dist/config/index.d.ts +8 -0
- package/dist/config/index.js +10 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/packagesManagement.d.ts +19 -0
- package/dist/config/packagesManagement.js +22 -0
- package/dist/config/packagesManagement.js.map +1 -0
- package/dist/create/constants.d.ts +1 -0
- package/dist/create/constants.js +5 -0
- package/dist/create/constants.js.map +1 -0
- package/dist/create/creator.d.ts +9 -0
- package/dist/create/creator.js +64 -0
- package/dist/create/creator.js.map +1 -0
- package/dist/create/fetchTemplate.d.ts +8 -0
- package/dist/create/fetchTemplate.js +169 -0
- package/dist/create/fetchTemplate.js.map +1 -0
- package/dist/create/page.d.ts +65 -0
- package/dist/create/page.js +266 -0
- package/dist/create/page.js.map +1 -0
- package/dist/create/plugin.d.ts +16 -0
- package/dist/create/plugin.js +77 -0
- package/dist/create/plugin.js.map +1 -0
- package/dist/create/project.d.ts +70 -0
- package/dist/create/project.js +481 -0
- package/dist/create/project.js.map +1 -0
- package/dist/doctor/index.d.ts +4 -0
- package/dist/doctor/index.js +23 -0
- package/dist/doctor/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/presets/commands/build.d.ts +3 -0
- package/dist/presets/commands/build.js +236 -0
- package/dist/presets/commands/build.js.map +1 -0
- package/dist/presets/commands/config.d.ts +3 -0
- package/dist/presets/commands/config.js +121 -0
- package/dist/presets/commands/config.js.map +1 -0
- package/dist/presets/commands/create.d.ts +3 -0
- package/dist/presets/commands/create.js +112 -0
- package/dist/presets/commands/create.js.map +1 -0
- package/dist/presets/commands/global-config.d.ts +3 -0
- package/dist/presets/commands/global-config.js +175 -0
- package/dist/presets/commands/global-config.js.map +1 -0
- package/dist/presets/commands/help.d.ts +3 -0
- package/dist/presets/commands/help.js +16 -0
- package/dist/presets/commands/help.js.map +1 -0
- package/dist/presets/commands/info.d.ts +3 -0
- package/dist/presets/commands/info.js +96 -0
- package/dist/presets/commands/info.js.map +1 -0
- package/dist/presets/commands/init.d.ts +3 -0
- package/dist/presets/commands/init.js +46 -0
- package/dist/presets/commands/init.js.map +1 -0
- package/dist/presets/commands/inspect.d.ts +3 -0
- package/dist/presets/commands/inspect.js +155 -0
- package/dist/presets/commands/inspect.js.map +1 -0
- package/dist/presets/commands/update.d.ts +3 -0
- package/dist/presets/commands/update.js +187 -0
- package/dist/presets/commands/update.js.map +1 -0
- package/dist/presets/constant/hooks.d.ts +13 -0
- package/dist/presets/constant/hooks.js +17 -0
- package/dist/presets/constant/hooks.js.map +1 -0
- package/dist/presets/constant/index.d.ts +1 -0
- package/dist/presets/constant/index.js +18 -0
- package/dist/presets/constant/index.js.map +1 -0
- package/dist/presets/files/generateFrameworkInfo.d.ts +3 -0
- package/dist/presets/files/generateFrameworkInfo.js +30 -0
- package/dist/presets/files/generateFrameworkInfo.js.map +1 -0
- package/dist/presets/files/generateProjectConfig.d.ts +3 -0
- package/dist/presets/files/generateProjectConfig.js +72 -0
- package/dist/presets/files/generateProjectConfig.js.map +1 -0
- package/dist/presets/files/writeFileToDist.d.ts +3 -0
- package/dist/presets/files/writeFileToDist.js +50 -0
- package/dist/presets/files/writeFileToDist.js.map +1 -0
- package/dist/presets/hooks/build.d.ts +3 -0
- package/dist/presets/hooks/build.js +55 -0
- package/dist/presets/hooks/build.js.map +1 -0
- package/dist/presets/hooks/create.d.ts +3 -0
- package/dist/presets/hooks/create.js +42 -0
- package/dist/presets/hooks/create.js.map +1 -0
- package/dist/presets/index.d.ts +4 -0
- package/dist/presets/index.js +50 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/platforms/plugin.d.ts +3 -0
- package/dist/presets/platforms/plugin.js +106 -0
- package/dist/presets/platforms/plugin.js.map +1 -0
- package/dist/presets/platforms/rn.d.ts +3 -0
- package/dist/presets/platforms/rn.js +130 -0
- package/dist/presets/platforms/rn.js.map +1 -0
- package/dist/util/appConfig.d.ts +11 -0
- package/dist/util/appConfig.js +27 -0
- package/dist/util/appConfig.js.map +1 -0
- package/dist/util/createPage.d.ts +9 -0
- package/dist/util/createPage.js +114 -0
- package/dist/util/createPage.js.map +1 -0
- package/dist/util/defineConfig.d.ts +17 -0
- package/dist/util/defineConfig.js +11 -0
- package/dist/util/defineConfig.js.map +1 -0
- package/dist/util/index.d.ts +23 -0
- package/dist/util/index.js +149 -0
- package/dist/util/index.js.map +1 -0
- package/dist/util/types.d.ts +58 -0
- package/dist/util/types.js +3 -0
- package/dist/util/types.js.map +1 -0
- package/global.d.ts +4 -0
- package/index.js +3 -0
- package/package.json +74 -0
- package/postinstall.js +17 -0
- package/src/__tests__/__mocks__/presets.ts +15 -0
- package/src/__tests__/build-config.spec.ts +66 -0
- package/src/__tests__/cli.spec.ts +226 -0
- package/src/__tests__/config.spec.ts +224 -0
- package/src/__tests__/doctor-config.spec.ts +943 -0
- package/src/__tests__/doctor-recommand.spec.ts +136 -0
- package/src/__tests__/doctor.spec.ts +94 -0
- package/src/__tests__/dotenv-parse.spec.ts +105 -0
- package/src/__tests__/env/.env +2 -0
- package/src/__tests__/fixtures/default/.env +3 -0
- package/src/__tests__/fixtures/default/.env.development +1 -0
- package/src/__tests__/fixtures/default/.env.local +1 -0
- package/src/__tests__/fixtures/default/.env.pre +3 -0
- package/src/__tests__/fixtures/default/.env.production +1 -0
- package/src/__tests__/fixtures/default/.env.uat +5 -0
- package/src/__tests__/fixtures/default/.env.uat.local +1 -0
- package/src/__tests__/fixtures/default/babel.config.js +10 -0
- package/src/__tests__/fixtures/default/config/dev.js +9 -0
- package/src/__tests__/fixtures/default/config/index.js +84 -0
- package/src/__tests__/fixtures/default/config/prod.js +18 -0
- package/src/__tests__/fixtures/default/package.json +27 -0
- package/src/__tests__/fixtures/default/src/app.config.js +11 -0
- package/src/__tests__/fixtures/default/src/app.js +16 -0
- package/src/__tests__/fixtures/default/src/app.scss +0 -0
- package/src/__tests__/fixtures/default/src/index.html +19 -0
- package/src/__tests__/fixtures/default/src/pages/index/index.config.js +3 -0
- package/src/__tests__/fixtures/default/src/pages/index/index.jsx +22 -0
- package/src/__tests__/fixtures/default/src/pages/index/index.scss +0 -0
- package/src/__tests__/info.spec.ts +72 -0
- package/src/__tests__/inspect.spec.ts +160 -0
- package/src/__tests__/update.spec.ts +310 -0
- package/src/__tests__/utils/index.ts +54 -0
- package/src/cli.ts +240 -0
- package/src/commands/customCommand.ts +22 -0
- package/src/config/index.ts +7 -0
- package/src/config/manifest.default.json +33 -0
- package/src/config/packagesManagement.ts +20 -0
- package/src/config/rn-stylelint.json +4 -0
- package/src/config/tsconfig.json +22 -0
- package/src/create/constants.ts +1 -0
- package/src/create/creator.ts +37 -0
- package/src/create/fetchTemplate.ts +161 -0
- package/src/create/page.ts +325 -0
- package/src/create/plugin.ts +55 -0
- package/src/create/project.ts +539 -0
- package/src/doctor/index.ts +21 -0
- package/src/index.ts +24 -0
- package/src/presets/commands/build.ts +215 -0
- package/src/presets/commands/config.ts +86 -0
- package/src/presets/commands/create.ts +104 -0
- package/src/presets/commands/global-config.ts +140 -0
- package/src/presets/commands/help.ts +17 -0
- package/src/presets/commands/info.ts +81 -0
- package/src/presets/commands/init.ts +63 -0
- package/src/presets/commands/inspect.ts +137 -0
- package/src/presets/commands/update.ts +175 -0
- package/src/presets/constant/hooks.ts +14 -0
- package/src/presets/constant/index.ts +1 -0
- package/src/presets/files/generateFrameworkInfo.ts +30 -0
- package/src/presets/files/generateProjectConfig.ts +41 -0
- package/src/presets/files/writeFileToDist.ts +17 -0
- package/src/presets/hooks/build.ts +22 -0
- package/src/presets/hooks/create.ts +9 -0
- package/src/presets/index.ts +15 -0
- package/src/presets/platforms/plugin.ts +75 -0
- package/src/presets/platforms/rn.ts +125 -0
- package/src/util/appConfig.ts +32 -0
- package/src/util/createPage.ts +139 -0
- package/src/util/defineConfig.ts +28 -0
- package/src/util/index.ts +126 -0
- package/src/util/types.ts +81 -0
- package/templates/default/_editorconfig +12 -0
- package/templates/default/_env.development +2 -0
- package/templates/default/_env.production +1 -0
- package/templates/default/_env.test +1 -0
- package/templates/default/_gitignore +8 -0
- package/templates/default/babel.config.js +14 -0
- package/templates/default/config/dev.js +5 -0
- package/templates/default/config/index.js +61 -0
- package/templates/default/config/prod.js +5 -0
- package/templates/default/package.json.tmpl +52 -0
- package/templates/default/project.config.json +15 -0
- package/templates/default/src/app.config.js +11 -0
- package/templates/default/src/app.css +0 -0
- package/templates/default/src/app.js +15 -0
- package/templates/default/src/pages/index/index.config.js +3 -0
- package/templates/default/src/pages/index/index.css +0 -0
- package/templates/default/src/pages/index/index.jsx +15 -0
- package/templates/default/template_creator.js +61 -0
- package/templates/default/tsconfig.json +30 -0
- package/templates/default/types/global.d.ts +27 -0
- package/templates/global-config/index.json +4 -0
- package/templates/global-config/package.json +5 -0
- package/templates/plugin-compile/README.md +32 -0
- package/templates/plugin-compile/index.js +3 -0
- package/templates/plugin-compile/package.json.tmpl +43 -0
- package/templates/plugin-compile/src/index.ts +153 -0
- package/templates/plugin-compile/tsconfig.json +28 -0
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
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', [require.resolve('@tarojs/plugin-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
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TARO_APP_TEST=env-development
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TARO_APP_TEST=env-local
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TARO_APP_TEST=env-production
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
TARO_APP_TEST=env-uat-local
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
|
@@ -0,0 +1,19 @@
|
|
|
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>
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
});
|