@ohos-ports/tarojs-cli 0.0.0-stage → 4.3.0-beta.2
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 -3
- package/bin/taro +7 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.js +252 -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 +31 -0
- package/dist/create/creator.js.map +1 -0
- package/dist/create/fetchTemplate.d.ts +8 -0
- package/dist/create/fetchTemplate.js +137 -0
- package/dist/create/fetchTemplate.js.map +1 -0
- package/dist/create/page.d.ts +65 -0
- package/dist/create/page.js +252 -0
- package/dist/create/page.js.map +1 -0
- package/dist/create/plugin.d.ts +16 -0
- package/dist/create/plugin.js +48 -0
- package/dist/create/plugin.js.map +1 -0
- package/dist/create/project.d.ts +80 -0
- package/dist/create/project.js +519 -0
- package/dist/create/project.js.map +1 -0
- package/dist/doctor/index.d.ts +4 -0
- package/dist/doctor/index.js +32 -0
- package/dist/doctor/index.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/presets/commands/build.d.ts +3 -0
- package/dist/presets/commands/build.js +239 -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 +88 -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 +91 -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 +139 -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 +29 -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 +79 -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 +59 -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 +118 -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 +171 -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 +40 -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 +17 -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 +22 -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 +11 -0
- package/dist/presets/hooks/create.js.map +1 -0
- package/dist/presets/index.d.ts +4 -0
- package/dist/presets/index.js +17 -0
- package/dist/presets/index.js.map +1 -0
- package/dist/presets/platforms/plugin.d.ts +3 -0
- package/dist/presets/platforms/plugin.js +76 -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 +101 -0
- package/dist/presets/platforms/rn.js.map +1 -0
- package/dist/util/appConfig.d.ts +11 -0
- package/dist/util/appConfig.js +25 -0
- package/dist/util/appConfig.js.map +1 -0
- package/dist/util/createPage.d.ts +9 -0
- package/dist/util/createPage.js +117 -0
- package/dist/util/createPage.js.map +1 -0
- package/dist/util/defineConfig.d.ts +17 -0
- package/dist/util/defineConfig.js +12 -0
- package/dist/util/defineConfig.js.map +1 -0
- package/dist/util/index.d.ts +23 -0
- package/dist/util/index.js +125 -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 +76 -4
- package/postinstall.js +14 -0
- package/src/__tests__/__mocks__/presets.ts +15 -0
- package/src/__tests__/build-config.spec.ts +99 -0
- package/src/__tests__/cli.spec.ts +233 -0
- package/src/__tests__/config.spec.ts +232 -0
- package/src/__tests__/doctor-config.spec.ts +805 -0
- package/src/__tests__/doctor-eslint.spec.ts +31 -0
- package/src/__tests__/doctor-recommand.spec.ts +158 -0
- package/src/__tests__/doctor.spec.ts +77 -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 +38 -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 +74 -0
- package/src/__tests__/inspect.spec.ts +163 -0
- package/src/__tests__/project.spec.ts +304 -0
- package/src/__tests__/update.spec.ts +324 -0
- package/src/__tests__/utils/index.ts +54 -0
- package/src/cli.ts +250 -0
- package/src/commands/customCommand.ts +26 -0
- package/src/config/index.ts +7 -0
- package/src/config/manifest.default.json +35 -0
- package/src/config/packagesManagement.ts +20 -0
- package/src/config/rn-stylelint.json +5 -0
- package/src/config/tsconfig.json +24 -0
- package/src/create/constants.ts +1 -0
- package/src/create/creator.ts +37 -0
- package/src/create/fetchTemplate.ts +152 -0
- package/src/create/page.ts +299 -0
- package/src/create/plugin.ts +55 -0
- package/src/create/project.ts +591 -0
- package/src/doctor/index.ts +27 -0
- package/src/index.ts +24 -0
- package/src/presets/commands/build.ts +227 -0
- package/src/presets/commands/config.ts +86 -0
- package/src/presets/commands/create.ts +105 -0
- package/src/presets/commands/global-config.ts +140 -0
- package/src/presets/commands/help.ts +19 -0
- package/src/presets/commands/info.ts +77 -0
- package/src/presets/commands/init.ts +66 -0
- package/src/presets/commands/inspect.ts +138 -0
- package/src/presets/commands/update.ts +179 -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 +11 -0
- package/src/presets/index.ts +15 -0
- package/src/presets/platforms/plugin.ts +81 -0
- package/src/presets/platforms/rn.ts +113 -0
- package/src/util/appConfig.ts +29 -0
- package/src/util/createPage.ts +132 -0
- package/src/util/defineConfig.ts +22 -0
- package/src/util/index.ts +127 -0
- package/src/util/types.ts +81 -0
- package/templates/default/.husky/commit-msg +4 -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/_eslintrc +11 -0
- package/templates/default/_gitignore +8 -0
- package/templates/default/babel.config.js +14 -0
- package/templates/default/commitlint.config.mjs +1 -0
- package/templates/default/config/dev.js +10 -0
- package/templates/default/config/index.js +106 -0
- package/templates/default/config/prod.js +46 -0
- package/templates/default/package.json.tmpl +158 -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 +44 -0
- package/templates/default/src/index.html +17 -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/src/pages/index/index.vue +23 -0
- package/templates/default/stylelint.config.mjs +4 -0
- package/templates/default/template_creator.js +77 -0
- package/templates/default/tsconfig.json +32 -0
- package/templates/default/types/global.d.ts +35 -0
- package/templates/default/types/solid.d.ts +12 -0
- package/templates/default/types/vue.d.ts +10 -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 +29 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { chalk } from '@tarojs/helper'
|
|
4
|
+
|
|
5
|
+
import doctor from '../doctor'
|
|
6
|
+
|
|
7
|
+
const validator = doctor.validators[4]
|
|
8
|
+
|
|
9
|
+
describe('eslint validator of doctor', () => {
|
|
10
|
+
let cwd = ''
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
cwd = process.cwd()
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
process.chdir(cwd)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('should lint for react', async () => {
|
|
20
|
+
process.chdir(path.join(__dirname, 'fixtures/default'))
|
|
21
|
+
const { isValid, messages } = await validator({
|
|
22
|
+
projectConfig: {
|
|
23
|
+
framework: 'react',
|
|
24
|
+
sourceRoot: 'src'
|
|
25
|
+
},
|
|
26
|
+
chalk
|
|
27
|
+
})
|
|
28
|
+
expect(isValid).toBe(true)
|
|
29
|
+
expect(messages.length).toBe(2)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import * as path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { chalk, fs } from '@tarojs/helper'
|
|
4
|
+
|
|
5
|
+
import doctor from '../doctor'
|
|
6
|
+
|
|
7
|
+
const validator = doctor.validators[3]
|
|
8
|
+
|
|
9
|
+
jest.mock('@tarojs/helper', () => {
|
|
10
|
+
const helper = jest.requireActual('@tarojs/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 linters not found', async () => {
|
|
80
|
+
jest.doMock('./fixtures/default/package.json', () => ({
|
|
81
|
+
devDependencies: {
|
|
82
|
+
jest: 1,
|
|
83
|
+
},
|
|
84
|
+
}))
|
|
85
|
+
readdirSyncMocked.mockReturnValue(['readme.md', '.gitignore', '.editorconfig'])
|
|
86
|
+
|
|
87
|
+
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') })
|
|
88
|
+
|
|
89
|
+
expect(lines.length).toBe(1)
|
|
90
|
+
expect(lines[0].desc).toBe(
|
|
91
|
+
'没有检查到常见的 linter (eslint/jslint/jshint/tslint), 配置 linter 可以帮助提升项目质量'
|
|
92
|
+
)
|
|
93
|
+
expect(lines[0].valid).toBe(true)
|
|
94
|
+
expect(lines[0].solution).toBe(
|
|
95
|
+
'Taro 还提供了定制的 ESLint 规则, 可以帮助开发者避免一些常见的问题. 使用 taro cli 创建新项目即可体验'
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
jest.dontMock('./fixtures/default/package.json')
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it.skip('should warn when Readme not found', async () => {
|
|
102
|
+
jest.doMock('./fixtures/default/package.json', () => ({
|
|
103
|
+
devDependencies: {
|
|
104
|
+
mocha: 1,
|
|
105
|
+
jslint: 1,
|
|
106
|
+
},
|
|
107
|
+
}))
|
|
108
|
+
readdirSyncMocked.mockReturnValue(['.gitignore', '.editorconfig'])
|
|
109
|
+
|
|
110
|
+
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') })
|
|
111
|
+
|
|
112
|
+
expect(lines.length).toBe(1)
|
|
113
|
+
expect(lines[0].desc).toBe(
|
|
114
|
+
'没有检查到 Readme (readme/readme.md/readme.markdown), 编写 Readme 可以方便其他人了解项目'
|
|
115
|
+
)
|
|
116
|
+
expect(lines[0].valid).toBe(true)
|
|
117
|
+
|
|
118
|
+
jest.dontMock('./fixtures/default/package.json')
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it.skip('should warn when .gitignore not found', async () => {
|
|
122
|
+
jest.doMock('./fixtures/default/package.json', () => ({
|
|
123
|
+
devDependencies: {
|
|
124
|
+
jesmine: 1,
|
|
125
|
+
tslint: 1,
|
|
126
|
+
},
|
|
127
|
+
}))
|
|
128
|
+
readdirSyncMocked.mockReturnValue(['readme.markdown', '.editorconfig'])
|
|
129
|
+
|
|
130
|
+
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') })
|
|
131
|
+
|
|
132
|
+
expect(lines.length).toBe(1)
|
|
133
|
+
expect(lines[0].desc).toBe(
|
|
134
|
+
'没有检查到 .gitignore 配置, 配置 .gitignore 以避免将敏感信息或不必要的内容提交到代码仓库'
|
|
135
|
+
)
|
|
136
|
+
expect(lines[0].valid).toBe(true)
|
|
137
|
+
|
|
138
|
+
jest.dontMock('./fixtures/default/package.json')
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it.skip('should warn when .editorconfig not found', async () => {
|
|
142
|
+
jest.doMock('./fixtures/default/package.json', () => ({
|
|
143
|
+
devDependencies: {
|
|
144
|
+
karma: 1,
|
|
145
|
+
jshint: 1,
|
|
146
|
+
},
|
|
147
|
+
}))
|
|
148
|
+
readdirSyncMocked.mockReturnValue(['readme', '.gitignore'])
|
|
149
|
+
|
|
150
|
+
const { lines } = await validator({ appPath: path.join(__dirname, './fixtures/default') })
|
|
151
|
+
|
|
152
|
+
expect(lines.length).toBe(1)
|
|
153
|
+
expect(lines[0].desc).toBe('没有检查到 .editconfig 配置, 配置 editconfig 以统一项目成员编辑器的代码风格')
|
|
154
|
+
expect(lines[0].valid).toBe(true)
|
|
155
|
+
|
|
156
|
+
jest.dontMock('./fixtures/default/package.json')
|
|
157
|
+
})
|
|
158
|
+
})
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { chalk } from '@tarojs/helper'
|
|
2
|
+
|
|
3
|
+
import { run } from './utils'
|
|
4
|
+
|
|
5
|
+
jest.mock('../doctor', () => {
|
|
6
|
+
return {
|
|
7
|
+
__esModule: true,
|
|
8
|
+
default: {
|
|
9
|
+
validators: [() => ({
|
|
10
|
+
isValid: true,
|
|
11
|
+
messgaes: [{
|
|
12
|
+
kind: 2,
|
|
13
|
+
content: 'Env Success'
|
|
14
|
+
}]
|
|
15
|
+
}), () => Promise.resolve({
|
|
16
|
+
isValid: false,
|
|
17
|
+
messgaes: [{
|
|
18
|
+
kind: 1,
|
|
19
|
+
content: 'Config Error'
|
|
20
|
+
}]
|
|
21
|
+
}), () => ({
|
|
22
|
+
isValid: true,
|
|
23
|
+
messgaes: [{
|
|
24
|
+
kind: 2,
|
|
25
|
+
content: 'Package Success'
|
|
26
|
+
}]
|
|
27
|
+
}), () => ({
|
|
28
|
+
isValid: true,
|
|
29
|
+
messgaes: [{
|
|
30
|
+
kind: 2,
|
|
31
|
+
content: 'recommend Success'
|
|
32
|
+
}]
|
|
33
|
+
}), async () => ({
|
|
34
|
+
isValid: true,
|
|
35
|
+
messgaes: [{
|
|
36
|
+
kind: 2,
|
|
37
|
+
content: 'eslint Success'
|
|
38
|
+
}]
|
|
39
|
+
})]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
jest.mock('ora', () => {
|
|
45
|
+
const ora = jest.fn()
|
|
46
|
+
ora.mockReturnValue({
|
|
47
|
+
start () {
|
|
48
|
+
return {
|
|
49
|
+
succeed () {}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
return ora
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const runDoctor = run('doctor', [require.resolve('@tarojs/plugin-doctor')])
|
|
57
|
+
|
|
58
|
+
describe('doctor', () => {
|
|
59
|
+
it('should exit because there isn\'t a Taro project', async () => {
|
|
60
|
+
const exitSpy = jest.spyOn(process, 'exit') as jest.SpyInstance<void, any>
|
|
61
|
+
const logSpy = jest.spyOn(console, 'log')
|
|
62
|
+
|
|
63
|
+
exitSpy.mockImplementation(() => {
|
|
64
|
+
throw new Error()
|
|
65
|
+
})
|
|
66
|
+
logSpy.mockImplementation(() => {})
|
|
67
|
+
try {
|
|
68
|
+
await runDoctor('', { options: { disableGlobalConfig: true } })
|
|
69
|
+
} catch (error) {} // eslint-disable-line no-empty
|
|
70
|
+
|
|
71
|
+
expect(exitSpy).toBeCalledWith(1)
|
|
72
|
+
expect(logSpy).toBeCalledWith(chalk.red('找不到项目配置文件config/index,请确定当前目录是 Taro 项目根目录!'))
|
|
73
|
+
|
|
74
|
+
exitSpy.mockRestore()
|
|
75
|
+
logSpy.mockRestore()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import * as path from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { dotenvParse } from '@tarojs/helper'
|
|
4
|
+
import { Kernel } from '@tarojs/service'
|
|
5
|
+
|
|
6
|
+
import CLI from '../cli'
|
|
7
|
+
|
|
8
|
+
jest.mock('@tarojs/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,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "test",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@babel/runtime": "^7.7.7",
|
|
5
|
+
"@tarojs/shared": "3.0.0-beta.6",
|
|
6
|
+
"@tarojs/taro": "3.0.0-beta.6",
|
|
7
|
+
"@tarojs/api": "3.0.0-beta.6",
|
|
8
|
+
"@tarojs/cli": "3.0.0-beta.6",
|
|
9
|
+
"@tarojs/components": "3.0.0-beta.6",
|
|
10
|
+
"@tarojs/taro-h5": "3.0.0-beta.6",
|
|
11
|
+
"@tarojs/helper": "3.0.0-beta.6",
|
|
12
|
+
"@tarojs/taro-loader": "3.0.0-beta.6",
|
|
13
|
+
"@tarojs/mini-runner": "3.0.0-beta.6",
|
|
14
|
+
"@tarojs/react": "3.0.0-beta.6",
|
|
15
|
+
"@tarojs/router": "3.0.0-beta.6",
|
|
16
|
+
"@tarojs/runner-utils": "3.0.0-beta.6",
|
|
17
|
+
"@tarojs/runtime": "3.0.0-beta.6",
|
|
18
|
+
"@tarojs/service": "3.0.0-beta.6",
|
|
19
|
+
"@tarojs/webpack-runner": "3.0.0-beta.6",
|
|
20
|
+
"@tarojs/with-weapp": "3.0.0-beta.6",
|
|
21
|
+
"@tarojs/plugin-platform-alipay": "3.0.0-beta.6",
|
|
22
|
+
"@tarojs/plugin-platform-h5": "3.0.0-beta.6",
|
|
23
|
+
"@tarojs/plugin-platform-jd": "3.0.0-beta.6",
|
|
24
|
+
"@tarojs/plugin-platform-qq": "3.0.0-beta.6",
|
|
25
|
+
"@tarojs/plugin-platform-swan": "3.0.0-beta.6",
|
|
26
|
+
"@tarojs/plugin-platform-tt": "3.0.0-beta.6",
|
|
27
|
+
"@tarojs/plugin-platform-weapp": "3.0.0-beta.6",
|
|
28
|
+
"@tarojs/taroize": "1.3.22"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"babel-preset-taro": "2.0.0",
|
|
32
|
+
"eslint": "^8.12.0",
|
|
33
|
+
"eslint-config-taro": "3.0.0-beta.6",
|
|
34
|
+
"babel-plugin-transform-taroapi": "3.0.0-beta.6",
|
|
35
|
+
"postcss-plugin-constparse": "3.0.0-beta.6",
|
|
36
|
+
"postcss-pxtransform": "3.0.0-beta.6"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -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 '@tarojs/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
|