@ohos-ports/tarojs-cli 0.0.0-stage → 4.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (223) hide show
  1. package/LICENSE +174 -0
  2. package/README.md +0 -3
  3. package/bin/taro +7 -0
  4. package/dist/cli.d.ts +6 -0
  5. package/dist/cli.js +252 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/commands/customCommand.d.ts +5 -0
  8. package/dist/commands/customCommand.js +23 -0
  9. package/dist/commands/customCommand.js.map +1 -0
  10. package/dist/config/index.d.ts +8 -0
  11. package/dist/config/index.js +10 -0
  12. package/dist/config/index.js.map +1 -0
  13. package/dist/config/packagesManagement.d.ts +19 -0
  14. package/dist/config/packagesManagement.js +22 -0
  15. package/dist/config/packagesManagement.js.map +1 -0
  16. package/dist/create/constants.d.ts +1 -0
  17. package/dist/create/constants.js +5 -0
  18. package/dist/create/constants.js.map +1 -0
  19. package/dist/create/creator.d.ts +9 -0
  20. package/dist/create/creator.js +31 -0
  21. package/dist/create/creator.js.map +1 -0
  22. package/dist/create/fetchTemplate.d.ts +8 -0
  23. package/dist/create/fetchTemplate.js +137 -0
  24. package/dist/create/fetchTemplate.js.map +1 -0
  25. package/dist/create/page.d.ts +65 -0
  26. package/dist/create/page.js +252 -0
  27. package/dist/create/page.js.map +1 -0
  28. package/dist/create/plugin.d.ts +16 -0
  29. package/dist/create/plugin.js +48 -0
  30. package/dist/create/plugin.js.map +1 -0
  31. package/dist/create/project.d.ts +80 -0
  32. package/dist/create/project.js +519 -0
  33. package/dist/create/project.js.map +1 -0
  34. package/dist/doctor/index.d.ts +4 -0
  35. package/dist/doctor/index.js +32 -0
  36. package/dist/doctor/index.js.map +1 -0
  37. package/dist/index.d.ts +16 -0
  38. package/dist/index.js +21 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/presets/commands/build.d.ts +3 -0
  41. package/dist/presets/commands/build.js +239 -0
  42. package/dist/presets/commands/build.js.map +1 -0
  43. package/dist/presets/commands/config.d.ts +3 -0
  44. package/dist/presets/commands/config.js +88 -0
  45. package/dist/presets/commands/config.js.map +1 -0
  46. package/dist/presets/commands/create.d.ts +3 -0
  47. package/dist/presets/commands/create.js +91 -0
  48. package/dist/presets/commands/create.js.map +1 -0
  49. package/dist/presets/commands/global-config.d.ts +3 -0
  50. package/dist/presets/commands/global-config.js +139 -0
  51. package/dist/presets/commands/global-config.js.map +1 -0
  52. package/dist/presets/commands/help.d.ts +3 -0
  53. package/dist/presets/commands/help.js +29 -0
  54. package/dist/presets/commands/help.js.map +1 -0
  55. package/dist/presets/commands/info.d.ts +3 -0
  56. package/dist/presets/commands/info.js +79 -0
  57. package/dist/presets/commands/info.js.map +1 -0
  58. package/dist/presets/commands/init.d.ts +3 -0
  59. package/dist/presets/commands/init.js +59 -0
  60. package/dist/presets/commands/init.js.map +1 -0
  61. package/dist/presets/commands/inspect.d.ts +3 -0
  62. package/dist/presets/commands/inspect.js +118 -0
  63. package/dist/presets/commands/inspect.js.map +1 -0
  64. package/dist/presets/commands/update.d.ts +3 -0
  65. package/dist/presets/commands/update.js +171 -0
  66. package/dist/presets/commands/update.js.map +1 -0
  67. package/dist/presets/constant/hooks.d.ts +13 -0
  68. package/dist/presets/constant/hooks.js +17 -0
  69. package/dist/presets/constant/hooks.js.map +1 -0
  70. package/dist/presets/constant/index.d.ts +1 -0
  71. package/dist/presets/constant/index.js +18 -0
  72. package/dist/presets/constant/index.js.map +1 -0
  73. package/dist/presets/files/generateFrameworkInfo.d.ts +3 -0
  74. package/dist/presets/files/generateFrameworkInfo.js +30 -0
  75. package/dist/presets/files/generateFrameworkInfo.js.map +1 -0
  76. package/dist/presets/files/generateProjectConfig.d.ts +3 -0
  77. package/dist/presets/files/generateProjectConfig.js +40 -0
  78. package/dist/presets/files/generateProjectConfig.js.map +1 -0
  79. package/dist/presets/files/writeFileToDist.d.ts +3 -0
  80. package/dist/presets/files/writeFileToDist.js +17 -0
  81. package/dist/presets/files/writeFileToDist.js.map +1 -0
  82. package/dist/presets/hooks/build.d.ts +3 -0
  83. package/dist/presets/hooks/build.js +22 -0
  84. package/dist/presets/hooks/build.js.map +1 -0
  85. package/dist/presets/hooks/create.d.ts +3 -0
  86. package/dist/presets/hooks/create.js +11 -0
  87. package/dist/presets/hooks/create.js.map +1 -0
  88. package/dist/presets/index.d.ts +4 -0
  89. package/dist/presets/index.js +17 -0
  90. package/dist/presets/index.js.map +1 -0
  91. package/dist/presets/platforms/plugin.d.ts +3 -0
  92. package/dist/presets/platforms/plugin.js +76 -0
  93. package/dist/presets/platforms/plugin.js.map +1 -0
  94. package/dist/presets/platforms/rn.d.ts +3 -0
  95. package/dist/presets/platforms/rn.js +101 -0
  96. package/dist/presets/platforms/rn.js.map +1 -0
  97. package/dist/util/appConfig.d.ts +11 -0
  98. package/dist/util/appConfig.js +25 -0
  99. package/dist/util/appConfig.js.map +1 -0
  100. package/dist/util/createPage.d.ts +9 -0
  101. package/dist/util/createPage.js +117 -0
  102. package/dist/util/createPage.js.map +1 -0
  103. package/dist/util/defineConfig.d.ts +17 -0
  104. package/dist/util/defineConfig.js +12 -0
  105. package/dist/util/defineConfig.js.map +1 -0
  106. package/dist/util/index.d.ts +23 -0
  107. package/dist/util/index.js +125 -0
  108. package/dist/util/index.js.map +1 -0
  109. package/dist/util/types.d.ts +58 -0
  110. package/dist/util/types.js +3 -0
  111. package/dist/util/types.js.map +1 -0
  112. package/global.d.ts +4 -0
  113. package/index.js +3 -0
  114. package/package.json +76 -4
  115. package/postinstall.js +14 -0
  116. package/src/__tests__/__mocks__/presets.ts +15 -0
  117. package/src/__tests__/build-config.spec.ts +99 -0
  118. package/src/__tests__/cli.spec.ts +233 -0
  119. package/src/__tests__/config.spec.ts +232 -0
  120. package/src/__tests__/doctor-config.spec.ts +805 -0
  121. package/src/__tests__/doctor-eslint.spec.ts +31 -0
  122. package/src/__tests__/doctor-recommand.spec.ts +158 -0
  123. package/src/__tests__/doctor.spec.ts +77 -0
  124. package/src/__tests__/dotenv-parse.spec.ts +105 -0
  125. package/src/__tests__/env/.env +2 -0
  126. package/src/__tests__/fixtures/default/.env +3 -0
  127. package/src/__tests__/fixtures/default/.env.development +1 -0
  128. package/src/__tests__/fixtures/default/.env.local +1 -0
  129. package/src/__tests__/fixtures/default/.env.pre +3 -0
  130. package/src/__tests__/fixtures/default/.env.production +1 -0
  131. package/src/__tests__/fixtures/default/.env.uat +5 -0
  132. package/src/__tests__/fixtures/default/.env.uat.local +1 -0
  133. package/src/__tests__/fixtures/default/babel.config.js +10 -0
  134. package/src/__tests__/fixtures/default/config/dev.js +9 -0
  135. package/src/__tests__/fixtures/default/config/index.js +84 -0
  136. package/src/__tests__/fixtures/default/config/prod.js +18 -0
  137. package/src/__tests__/fixtures/default/package.json +38 -0
  138. package/src/__tests__/fixtures/default/src/app.config.js +11 -0
  139. package/src/__tests__/fixtures/default/src/app.js +16 -0
  140. package/src/__tests__/fixtures/default/src/app.scss +0 -0
  141. package/src/__tests__/fixtures/default/src/index.html +19 -0
  142. package/src/__tests__/fixtures/default/src/pages/index/index.config.js +3 -0
  143. package/src/__tests__/fixtures/default/src/pages/index/index.jsx +22 -0
  144. package/src/__tests__/fixtures/default/src/pages/index/index.scss +0 -0
  145. package/src/__tests__/info.spec.ts +74 -0
  146. package/src/__tests__/inspect.spec.ts +163 -0
  147. package/src/__tests__/project.spec.ts +304 -0
  148. package/src/__tests__/update.spec.ts +324 -0
  149. package/src/__tests__/utils/index.ts +54 -0
  150. package/src/cli.ts +250 -0
  151. package/src/commands/customCommand.ts +26 -0
  152. package/src/config/index.ts +7 -0
  153. package/src/config/manifest.default.json +35 -0
  154. package/src/config/packagesManagement.ts +20 -0
  155. package/src/config/rn-stylelint.json +5 -0
  156. package/src/config/tsconfig.json +24 -0
  157. package/src/create/constants.ts +1 -0
  158. package/src/create/creator.ts +37 -0
  159. package/src/create/fetchTemplate.ts +152 -0
  160. package/src/create/page.ts +299 -0
  161. package/src/create/plugin.ts +55 -0
  162. package/src/create/project.ts +591 -0
  163. package/src/doctor/index.ts +27 -0
  164. package/src/index.ts +24 -0
  165. package/src/presets/commands/build.ts +227 -0
  166. package/src/presets/commands/config.ts +86 -0
  167. package/src/presets/commands/create.ts +105 -0
  168. package/src/presets/commands/global-config.ts +140 -0
  169. package/src/presets/commands/help.ts +19 -0
  170. package/src/presets/commands/info.ts +77 -0
  171. package/src/presets/commands/init.ts +66 -0
  172. package/src/presets/commands/inspect.ts +138 -0
  173. package/src/presets/commands/update.ts +179 -0
  174. package/src/presets/constant/hooks.ts +14 -0
  175. package/src/presets/constant/index.ts +1 -0
  176. package/src/presets/files/generateFrameworkInfo.ts +30 -0
  177. package/src/presets/files/generateProjectConfig.ts +41 -0
  178. package/src/presets/files/writeFileToDist.ts +17 -0
  179. package/src/presets/hooks/build.ts +22 -0
  180. package/src/presets/hooks/create.ts +11 -0
  181. package/src/presets/index.ts +15 -0
  182. package/src/presets/platforms/plugin.ts +81 -0
  183. package/src/presets/platforms/rn.ts +113 -0
  184. package/src/util/appConfig.ts +29 -0
  185. package/src/util/createPage.ts +132 -0
  186. package/src/util/defineConfig.ts +22 -0
  187. package/src/util/index.ts +127 -0
  188. package/src/util/types.ts +81 -0
  189. package/templates/default/.husky/commit-msg +4 -0
  190. package/templates/default/_editorconfig +12 -0
  191. package/templates/default/_env.development +2 -0
  192. package/templates/default/_env.production +1 -0
  193. package/templates/default/_env.test +1 -0
  194. package/templates/default/_eslintrc +11 -0
  195. package/templates/default/_gitignore +8 -0
  196. package/templates/default/babel.config.js +14 -0
  197. package/templates/default/commitlint.config.mjs +1 -0
  198. package/templates/default/config/dev.js +10 -0
  199. package/templates/default/config/index.js +106 -0
  200. package/templates/default/config/prod.js +46 -0
  201. package/templates/default/package.json.tmpl +158 -0
  202. package/templates/default/project.config.json +15 -0
  203. package/templates/default/src/app.config.js +11 -0
  204. package/templates/default/src/app.css +0 -0
  205. package/templates/default/src/app.js +44 -0
  206. package/templates/default/src/index.html +17 -0
  207. package/templates/default/src/pages/index/index.config.js +3 -0
  208. package/templates/default/src/pages/index/index.css +0 -0
  209. package/templates/default/src/pages/index/index.jsx +15 -0
  210. package/templates/default/src/pages/index/index.vue +23 -0
  211. package/templates/default/stylelint.config.mjs +4 -0
  212. package/templates/default/template_creator.js +77 -0
  213. package/templates/default/tsconfig.json +32 -0
  214. package/templates/default/types/global.d.ts +35 -0
  215. package/templates/default/types/solid.d.ts +12 -0
  216. package/templates/default/types/vue.d.ts +10 -0
  217. package/templates/global-config/index.json +4 -0
  218. package/templates/global-config/package.json +5 -0
  219. package/templates/plugin-compile/README.md +32 -0
  220. package/templates/plugin-compile/index.js +3 -0
  221. package/templates/plugin-compile/package.json.tmpl +43 -0
  222. package/templates/plugin-compile/src/index.ts +153 -0
  223. package/templates/plugin-compile/tsconfig.json +29 -0
@@ -0,0 +1,113 @@
1
+ import * as fs from 'node:fs'
2
+ import * as os from 'node:os'
3
+ import * as path from 'node:path'
4
+
5
+ import { chalk } from '@tarojs/helper'
6
+ import * as child_process from 'child_process'
7
+
8
+ import { printDevelopmentTip } from '../../util'
9
+
10
+ import type { IPluginContext } from '@tarojs/service'
11
+
12
+ function checkReactNativeDependencies (packageInfo): boolean {
13
+ const packageNames = ['react', 'react-native', '@tarojs/taro-rn', '@tarojs/rn-runner']
14
+ const { dependencies, devDependencies } = packageInfo
15
+ for (let i = 0; i < packageNames.length; i++) {
16
+ if (!dependencies[packageNames[i]] && !devDependencies[packageNames[i]]) {
17
+ return false
18
+ }
19
+ }
20
+ return true
21
+ }
22
+
23
+ function makeSureReactNativeInstalled (workspaceRoot: string): Promise<void> {
24
+ return new Promise<void>((resolve, reject) => {
25
+ const packageInfo = JSON.parse(fs.readFileSync(path.join(workspaceRoot, 'package.json'), {
26
+ encoding: 'utf8'
27
+ }))
28
+
29
+ if (checkReactNativeDependencies(packageInfo)) {
30
+ resolve()
31
+ } else {
32
+ // 便于开发时切换版本
33
+ const devTag = process.env.DEVTAG || ''
34
+ console.log('Installing React-Native related packages:')
35
+ let packages = `react@^18.2.0 react-dom@^18.2.0 react-native@^0.73.1 @react-native/metro-config@^0.73.2 expo@~50.0.2 @tarojs/taro-rn${devTag} @tarojs/components-rn${devTag} @tarojs/rn-runner${devTag} @tarojs/rn-supporter${devTag} @tarojs/runtime-rn${devTag}`
36
+ console.log(packages)
37
+ // windows下不加引号的话,package.json中添加的依赖不会自动带上^
38
+ packages = packages.split(' ').map(str => `"${str}"`).join(' ')
39
+ let installCmd = `npm install ${packages} --save`
40
+ if (fs.existsSync(path.join(workspaceRoot, 'yarn.lock'))) {
41
+ installCmd = `yarn add ${packages} --force`
42
+ }
43
+ if (fs.existsSync(path.join(workspaceRoot, 'pnpm-lock.yaml'))) {
44
+ installCmd = `pnpm add ${packages}`
45
+ }
46
+ child_process.exec(installCmd, error => {
47
+ if (error) {
48
+ reject(error)
49
+ return
50
+ }
51
+ console.log(chalk.green(`React-Native related packages have been installed successfully.${os.EOL}${os.EOL}`))
52
+ console.log(`${chalk.yellow('ATTEHNTION')}: Package.json has been modified automatically, please submit it by yourself.${os.EOL}${os.EOL}`)
53
+ resolve()
54
+ })
55
+ }
56
+ })
57
+ }
58
+
59
+ export default (ctx: IPluginContext) => {
60
+ ctx.registerPlatform({
61
+ name: 'rn',
62
+ useConfigName: 'rn',
63
+ async fn ({ config }) {
64
+ const { appPath, nodeModulesPath } = ctx.paths
65
+ const { npm } = ctx.helper
66
+ const {
67
+ deviceType = 'android',
68
+ port,
69
+ resetCache,
70
+ publicPath,
71
+ bundleOutput,
72
+ sourcemapOutput,
73
+ sourceMapUrl,
74
+ sourcemapSourcesRoot,
75
+ assetsDest,
76
+ qr
77
+ } = ctx.runOpts.options
78
+
79
+ printDevelopmentTip('rn')
80
+
81
+ // 准备 rnRunner 参数
82
+ const rnRunnerOpts = {
83
+ ...config,
84
+ nodeModulesPath,
85
+ deviceType,
86
+ port,
87
+ qr,
88
+ resetCache,
89
+ publicPath,
90
+ bundleOutput,
91
+ sourcemapOutput,
92
+ sourceMapUrl,
93
+ sourcemapSourcesRoot,
94
+ assetsDest,
95
+ buildAdapter: config.platform,
96
+ }
97
+
98
+ if (!rnRunnerOpts.entry) {
99
+ rnRunnerOpts.entry = 'app'
100
+ }
101
+
102
+ makeSureReactNativeInstalled(appPath).then(async () => {
103
+ // build with metro
104
+ const rnRunner = await npm.getNpmPkg('@tarojs/rn-runner', appPath)
105
+ await rnRunner(appPath, rnRunnerOpts)
106
+ }, error => {
107
+ console.log(chalk.red('Error when detecting React-Native packages:'))
108
+ console.log(error)
109
+ console.log(`${chalk.greenBright('TIP')}: 1) Try to remove React-Native dependencies in package.json and shoot again; 2) Install the packages above manually.`)
110
+ })
111
+ }
112
+ })
113
+ }
@@ -0,0 +1,29 @@
1
+ import { IPluginContext } from '@tarojs/service'
2
+ import { isString } from '@tarojs/shared'
3
+ import { AppConfig } from '@tarojs/taro'
4
+
5
+ /**
6
+ * 按需编译功能,只编译指定的页面或组件
7
+ * @param appConfig
8
+ * @param args
9
+ */
10
+ export function extractCompileEntry(
11
+ appConfig: AppConfig,
12
+ args: { _: string[], [key: string]: any },
13
+ ctx: IPluginContext
14
+ ): void {
15
+ const { chalk } = ctx.helper
16
+
17
+ const extractType = isString(args.pages) ? 'pages' : isString(args.components) ? 'components' : ''
18
+ if (!extractType) return
19
+
20
+ const entries = args[extractType].split(',').map(item => item.trim()).filter(Boolean)
21
+ if (!entries.length) {
22
+ console.log(chalk.yellow(`按需编译开启失败,请指定要编译的${extractType}`))
23
+ return
24
+ }
25
+
26
+ appConfig[extractType] = entries
27
+ appConfig.subPackages = []
28
+ console.log(chalk.green(`已开启按需编译,仅编译以下${extractType}: ${appConfig[extractType]}`))
29
+ }
@@ -0,0 +1,132 @@
1
+ import { babelKit } from '@tarojs/helper'
2
+
3
+ import { ConfigModificationState, ModifyCallback } from '../create/page'
4
+
5
+ import type { ArrayExpression, ExportDefaultDeclaration, ObjectExpression, ObjectProperty } from '@babel/types'
6
+ import type { NodePath } from 'babel__traverse'
7
+
8
+ const t = babelKit.types
9
+
10
+ const generateNewSubPackageItem = (subPackage: string) => {
11
+ const pageObject = t.objectProperty(t.identifier('pages'), t.arrayExpression([]))
12
+ const subPkgRootObject = t.objectProperty(t.identifier('root'), t.stringLiteral(subPackage))
13
+ const subPkgItemObject = t.objectExpression([subPkgRootObject, pageObject])
14
+ return subPkgItemObject
15
+ }
16
+
17
+ const isValidSubPkgObject = (subPkgObject: ObjectExpression) => {
18
+ const properties = subPkgObject?.properties || {}
19
+ const rootProperty = properties.find((property: ObjectProperty) => (property.key as any)?.name === 'root') as ObjectProperty
20
+ const pagesProperty = properties.find((property: ObjectProperty) => (property.key as any)?.name === 'pages') as ObjectProperty
21
+ const rootPropertyValueType = rootProperty?.value?.type
22
+ const pagesPropertyValueType = pagesProperty?.value?.type
23
+ return rootPropertyValueType === 'StringLiteral' && pagesPropertyValueType === 'ArrayExpression'
24
+ }
25
+
26
+ const addNewSubPackage = (node: ObjectExpression, page: string, subPackage: string): ConfigModificationState => {
27
+ let subPackages = node?.properties.find(node => (node as any).key.name === 'subPackages') as ObjectProperty
28
+ if (!subPackages) {
29
+ // config 文件不存在 subPackages 字段的情况,给该字段赋予默认值
30
+ const subPkgObject = t.objectProperty(t.identifier('subPackages'), t.arrayExpression([]))
31
+ subPackages = subPkgObject
32
+ node?.properties.push(subPkgObject)
33
+ }
34
+ const value = subPackages?.value
35
+
36
+ // 文件格式不对的情况
37
+ if (!value || value?.type !== 'ArrayExpression') return ConfigModificationState.Fail
38
+ let targetSubPkgObject: ObjectExpression = value.elements.find(node => (node as any)?.properties?.find(property => (property as any)?.value?.value === subPackage)) as ObjectExpression
39
+
40
+ if (!targetSubPkgObject) {
41
+ // 不存在 当前分包配置对象的情况
42
+ const subPkgItemObject = generateNewSubPackageItem(subPackage)
43
+ targetSubPkgObject = subPkgItemObject
44
+ value.elements.push(subPkgItemObject)
45
+ }
46
+
47
+ if (targetSubPkgObject.type !== 'ObjectExpression' || !isValidSubPkgObject(targetSubPkgObject)) return ConfigModificationState.Fail
48
+ const pagesProperty: ObjectProperty = targetSubPkgObject.properties.find((property: ObjectProperty) => (property.key as any)?.name === 'pages') as ObjectProperty
49
+ const currentPages = (pagesProperty.value as ArrayExpression).elements
50
+ const isPageExists = Boolean(currentPages.find(node => (node as any).value === page))
51
+
52
+ if (isPageExists) return ConfigModificationState.NeedLess
53
+
54
+ currentPages.push(t.stringLiteral(page))
55
+ return ConfigModificationState.Success
56
+ }
57
+
58
+ const addNewPage = (node: ObjectExpression, page: string): ConfigModificationState => {
59
+ const pages = node?.properties.find(node => (node as any).key.name === 'pages') as ObjectProperty
60
+ if (!pages) return ConfigModificationState.Fail
61
+
62
+ const value = pages?.value
63
+ // 仅处理 pages 为数组字面量的情形
64
+ if (!value || value?.type !== 'ArrayExpression') return ConfigModificationState.Fail
65
+
66
+ const isPageExists = Boolean(value.elements.find(node => (node as any).value === page))
67
+ if (isPageExists) return ConfigModificationState.NeedLess
68
+
69
+ const newArrayElement = t.stringLiteral(page)
70
+ value.elements.push(newArrayElement)
71
+
72
+ return ConfigModificationState.Success
73
+ }
74
+
75
+ const modifyPages = (path: NodePath<ExportDefaultDeclaration>, newPageConfig, callback: ModifyCallback) => {
76
+ let state = ConfigModificationState.Fail
77
+ const node = path.node.declaration as any
78
+ // Case 1. `export default defineAppConfig({})` 这种情况
79
+ if (node.type === 'CallExpression' && node.callee.name === 'defineAppConfig') {
80
+ const configNode = node.arguments[0]
81
+ state = addNewPage(configNode, newPageConfig.page)
82
+ }
83
+ // Case 2. `export default {}` 这种情况
84
+ if (node.type === 'ObjectExpression') {
85
+ state = addNewPage(node, newPageConfig.page)
86
+ }
87
+ callback(state)
88
+ }
89
+
90
+ const modifySubPackages = (path: NodePath<ExportDefaultDeclaration>, newPageConfig, callback: ModifyCallback) => {
91
+ let state = ConfigModificationState.Fail
92
+ const node = path.node.declaration as any
93
+ // `export default defineAppConfig({})` 这种情况
94
+ if (node.type === 'CallExpression' && node.callee.name === 'defineAppConfig') {
95
+ const configNode = node.arguments[0]
96
+ state = addNewSubPackage(configNode, newPageConfig.page, newPageConfig.pkg)
97
+ }
98
+ // `export default {}` 这种情况
99
+ if (node.type === 'ObjectExpression') {
100
+ state = addNewSubPackage(node, newPageConfig.page, newPageConfig.pkg)
101
+ }
102
+ callback(state)
103
+ }
104
+
105
+ const generateNewPageConfig = (fullPagePath: string, subPkgRootPath = '') => {
106
+ const newPageConfig = {
107
+ pkg: '',
108
+ page: ''
109
+ }
110
+ if (subPkgRootPath) {
111
+ const processedSubPkg = `${subPkgRootPath}/`
112
+ newPageConfig.pkg = processedSubPkg
113
+ newPageConfig.page = fullPagePath.split(processedSubPkg)[1]
114
+ } else {
115
+ newPageConfig.page = fullPagePath
116
+ }
117
+
118
+ return newPageConfig
119
+ }
120
+
121
+ export const modifyPagesOrSubPackages = (params: {
122
+ path: NodePath<ExportDefaultDeclaration>
123
+ fullPagePath: string
124
+ subPkgRootPath?: string
125
+ callback: ModifyCallback
126
+ }) => {
127
+ const { fullPagePath, subPkgRootPath, callback, path } = params
128
+ const newPageConfig = generateNewPageConfig(fullPagePath, subPkgRootPath)
129
+ subPkgRootPath
130
+ ? modifySubPackages(path, newPageConfig, callback)
131
+ : modifyPages(path, newPageConfig, callback)
132
+ }
@@ -0,0 +1,22 @@
1
+ import type { IProjectConfig } from '@tarojs/taro/types/compile'
2
+ import type { CompilerTypes, CompilerWebpackTypes } from '@tarojs/taro/types/compile/compiler'
3
+
4
+ type WebpackMerge = (...configs: Array<object | null | undefined>) => object
5
+
6
+ export interface ConfigEnv {
7
+ /** taro 当前执行的命令 */
8
+ command: string
9
+ /** 当前模式 (mode) */
10
+ mode: string
11
+ }
12
+
13
+ export type UserConfigFn<T extends CompilerTypes = CompilerWebpackTypes> = (merge: WebpackMerge, env: ConfigEnv) => IProjectConfig<T> | Promise<IProjectConfig<T>>
14
+ export type UserConfigExport<T extends CompilerTypes = CompilerWebpackTypes> = IProjectConfig<T> | Promise<IProjectConfig<T>> | UserConfigFn
15
+
16
+ /**
17
+ * @since v3.6.9
18
+ * @warning 暂不支持 react native
19
+ */
20
+ export function defineConfig<T extends CompilerTypes = CompilerWebpackTypes> (config: UserConfigExport<T>) {
21
+ return config
22
+ }
@@ -0,0 +1,127 @@
1
+ import * as path from 'node:path'
2
+
3
+ import { chalk, fs, isWindows } from '@tarojs/helper'
4
+ import { exec } from 'child_process'
5
+
6
+ export function getRootPath (): string {
7
+ return path.resolve(__dirname, '../../')
8
+ }
9
+
10
+ export function getPkgVersion (): string {
11
+ return require(path.join(getRootPath(), 'package.json')).version
12
+ }
13
+
14
+ export function getPkgItemByKey (key: string) {
15
+ const packageMap = require(path.join(getRootPath(), 'package.json'))
16
+ if (Object.keys(packageMap).indexOf(key) === -1) {
17
+ return {}
18
+ } else {
19
+ return packageMap[key]
20
+ }
21
+ }
22
+
23
+ export function printPkgVersion () {
24
+ const taroVersion = getPkgVersion()
25
+ console.log(`👽 Taro v${taroVersion}`)
26
+ console.log()
27
+ }
28
+
29
+ export const getAllFilesInFolder = async (
30
+ folder: string,
31
+ filter: string[] = []
32
+ ): Promise<string[]> => {
33
+ let files: string[] = []
34
+ const list = readDirWithFileTypes(folder)
35
+
36
+ await Promise.all(
37
+ list.map(async item => {
38
+ const itemPath = path.join(folder, item.name)
39
+ if (item.isDirectory) {
40
+ const _files = await getAllFilesInFolder(itemPath, filter)
41
+ files = [...files, ..._files]
42
+ } else if (item.isFile) {
43
+ if (!filter.find(rule => rule === item.name)) files.push(itemPath)
44
+ }
45
+ })
46
+ )
47
+
48
+ return files
49
+ }
50
+
51
+ export type TemplateSourceType = 'git' | 'url'
52
+
53
+ export function getTemplateSourceType (url: string): TemplateSourceType {
54
+ if (/^github:/.test(url) || /^gitlab:/.test(url) || /^direct:/.test(url)) {
55
+ return 'git'
56
+ } else {
57
+ return 'url'
58
+ }
59
+ }
60
+
61
+ interface FileStat {
62
+ name: string
63
+ isDirectory: boolean
64
+ isFile: boolean
65
+ }
66
+
67
+ export function readDirWithFileTypes (folder: string): FileStat[] {
68
+ const list = fs.readdirSync(folder)
69
+ const res = list.map(name => {
70
+ const stat = fs.statSync(path.join(folder, name))
71
+ return {
72
+ name,
73
+ isDirectory: stat.isDirectory(),
74
+ isFile: stat.isFile()
75
+ }
76
+ })
77
+ return res
78
+ }
79
+
80
+ export function printDevelopmentTip (platform: string) {
81
+ if (process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
82
+ let exampleCommand
83
+ if (isWindows) {
84
+ exampleCommand = `$ set NODE_ENV=production && taro build --type ${platform} --watch`
85
+ } else {
86
+ exampleCommand = `$ NODE_ENV=production taro build --type ${platform} --watch`
87
+ }
88
+ console.log(chalk.yellowBright(`Tips: 预览模式生成的文件较大,设置 NODE_ENV 为 production 可以开启压缩。
89
+ Example:
90
+ ${exampleCommand}
91
+ `))
92
+ }
93
+ }
94
+
95
+ export function clearConsole () {
96
+ const readline = require('readline')
97
+ if (process.stdout.isTTY) {
98
+ const blank = '\n'.repeat(process.stdout.rows)
99
+ console.log(blank)
100
+ readline.cursorTo(process.stdout, 0, 0)
101
+ readline.clearScreenDown(process.stdout)
102
+ }
103
+ }
104
+
105
+ export function execCommand (params: {
106
+ command: string
107
+ successCallback?: (data: string) => void
108
+ failCallback?: (data: string) => void
109
+ }) {
110
+ const { command, successCallback, failCallback } = params
111
+ const child = exec(command)
112
+ child.stdout!.on('data', function (data) {
113
+ successCallback?.(data)
114
+ })
115
+ child.stderr!.on('data', function (data) {
116
+ failCallback?.(data)
117
+ })
118
+ }
119
+
120
+ export function getPkgNameByFilterVersion (pkgString: string) {
121
+ const versionFlagIndex = pkgString.lastIndexOf('@')
122
+ return versionFlagIndex === 0 ? pkgString : pkgString.slice(0, versionFlagIndex)
123
+ }
124
+
125
+ export function isNil (value: any): value is null | undefined {
126
+ return value === null || value === undefined
127
+ }
@@ -0,0 +1,81 @@
1
+ export interface IInstallOptions {
2
+ dev: boolean
3
+ peerDependencies?: boolean
4
+ }
5
+
6
+ export interface INpmConfig {
7
+ dir: string
8
+ name: string
9
+ }
10
+
11
+ export interface IResolvedCache {
12
+ [key: string]: {
13
+ main: string
14
+ files: string[]
15
+ }
16
+ }
17
+
18
+ export interface IPrettierConfig {
19
+ printWidth?: number
20
+ tabWidth?: number
21
+ useTabs?: boolean
22
+ semi?: boolean
23
+ singleQuote?: boolean
24
+ jsxSingleQuote?: boolean
25
+ trailingComma?: 'none' | 'es5' | 'all'
26
+ bracketSpacing?: boolean
27
+ jsxBracketSameLine?: boolean
28
+ arrowParens?: 'avoid' | 'always'
29
+ rangeStart?: number
30
+ rangeEnd?: number
31
+ parser?:
32
+ | 'babel'
33
+ | 'babylon'
34
+ | 'flow'
35
+ | 'typescript'
36
+ | 'css'
37
+ | 'scss'
38
+ | 'less'
39
+ | 'json'
40
+ | 'json5'
41
+ | 'json-stringify'
42
+ | 'graphql'
43
+ | 'markdown'
44
+ | 'mdx'
45
+ | 'html'
46
+ | 'vue'
47
+ | 'angular'
48
+ | 'yaml'
49
+ filepath?: string
50
+ requirePragma?: boolean
51
+ insertPragma?: boolean
52
+ proseWrap?: 'always' | 'never' | 'preserve'
53
+ htmlWhitespaceSensitivity?: 'css' | 'strict' | 'ignore'
54
+ endOfLine?: 'auto' | 'lf' | 'crlf' | 'cr'
55
+ }
56
+
57
+ export interface IBuildOptions {
58
+ type?: string
59
+ watch?: boolean
60
+ platform?: string
61
+ port?: number
62
+ release?: boolean
63
+ envHasBeenSet?: boolean
64
+ page?: string
65
+ component?: string
66
+ uiIndex?: string
67
+ }
68
+
69
+ export interface IMiniAppBuildConfig {
70
+ adapter: string
71
+ watch?: boolean
72
+ envHasBeenSet?: boolean
73
+ port?: number
74
+ release?: boolean
75
+ page?: string
76
+ component?: string
77
+ }
78
+
79
+ export interface IOption {
80
+ [key: string]: any
81
+ }
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env sh
2
+
3
+ # 运行 commitlint 检查 commit message
4
+ npx --no -- commitlint --edit ${1}
@@ -0,0 +1,12 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
10
+
11
+ [*.md]
12
+ trim_trailing_whitespace = false
@@ -0,0 +1,2 @@
1
+ # 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config
2
+ # TARO_APP_ID="开发环境下的小程序 AppID"
@@ -0,0 +1 @@
1
+ # TARO_APP_ID="生产环境下的小程序 AppID"
@@ -0,0 +1 @@
1
+ # TARO_APP_ID="测试环境下的小程序 AppID"
@@ -0,0 +1,11 @@
1
+ {{#if (includes "Vue3" s=framework)}}
2
+ // ESLint 检查 .vue 文件需要单独配置编辑器:
3
+ // https://eslint.vuejs.org/user-guide/#editor-integrations
4
+ {{/if}}
5
+ {
6
+ "extends": ["taro/{{ to_lower_case framework }}"]{{#if (eq framework "React") }},
7
+ "rules": {
8
+ "react/jsx-uses-react": "off",
9
+ "react/react-in-jsx-scope": "off"
10
+ }{{/if}}
11
+ }
@@ -0,0 +1,8 @@
1
+ dist/
2
+ deploy_versions/
3
+ .temp/
4
+ .rn_temp/
5
+ node_modules/
6
+ .DS_Store
7
+ .swc
8
+ *.local
@@ -0,0 +1,14 @@
1
+ // babel-preset-taro 更多选项和默认值:
2
+ // https://docs.taro.zone/docs/next/babel-config
3
+ module.exports = {
4
+ presets: [
5
+ ['taro', {
6
+ framework: '{{ to_lower_case framework }}',
7
+ ts: {{ typescript }},
8
+ compiler: '{{ to_lower_case compiler }}',
9
+ {{#if buildEs5 }}
10
+ useBuiltIns: process.env.TARO_ENV === 'h5' ? 'usage' : false
11
+ {{/if}}
12
+ }]
13
+ ]
14
+ }
@@ -0,0 +1 @@
1
+ export default { extends: ["@commitlint/config-conventional"] };
@@ -0,0 +1,10 @@
1
+ {{#if typescript }}import type { UserConfigExport } from "@tarojs/cli"{{/if}}
2
+
3
+ export default {
4
+ {{#if (eq compiler "Webpack5") }} logger: {
5
+ quiet: false,
6
+ stats: true
7
+ },{{/if}}
8
+ mini: {},
9
+ h5: {}
10
+ }{{#if typescript }} satisfies UserConfigExport<'{{ to_lower_case compiler }}'>{{/if}}