@tarojs/cli 4.0.0-canary.9 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/LICENSE +8 -8
  2. package/dist/cli.js +33 -24
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/customCommand.js.map +1 -1
  5. package/dist/create/creator.js +1 -1
  6. package/dist/create/creator.js.map +1 -1
  7. package/dist/create/fetchTemplate.d.ts +1 -0
  8. package/dist/create/fetchTemplate.js +33 -27
  9. package/dist/create/fetchTemplate.js.map +1 -1
  10. package/dist/create/page.d.ts +7 -0
  11. package/dist/create/page.js +15 -10
  12. package/dist/create/page.js.map +1 -1
  13. package/dist/create/plugin.js +1 -1
  14. package/dist/create/plugin.js.map +1 -1
  15. package/dist/create/project.js +33 -31
  16. package/dist/create/project.js.map +1 -1
  17. package/dist/presets/commands/build.js +53 -35
  18. package/dist/presets/commands/build.js.map +1 -1
  19. package/dist/presets/commands/config.js +1 -1
  20. package/dist/presets/commands/config.js.map +1 -1
  21. package/dist/presets/commands/create.js +6 -0
  22. package/dist/presets/commands/create.js.map +1 -1
  23. package/dist/presets/commands/global-config.js +9 -3
  24. package/dist/presets/commands/global-config.js.map +1 -1
  25. package/dist/presets/commands/help.js +2 -2
  26. package/dist/presets/commands/help.js.map +1 -1
  27. package/dist/presets/commands/info.js +3 -3
  28. package/dist/presets/commands/info.js.map +1 -1
  29. package/dist/presets/commands/init.js +2 -1
  30. package/dist/presets/commands/init.js.map +1 -1
  31. package/dist/presets/commands/inspect.js +6 -6
  32. package/dist/presets/commands/inspect.js.map +1 -1
  33. package/dist/presets/commands/update.js +3 -3
  34. package/dist/presets/commands/update.js.map +1 -1
  35. package/dist/presets/constant/hooks.d.ts +1 -0
  36. package/dist/presets/constant/hooks.js +2 -1
  37. package/dist/presets/constant/hooks.js.map +1 -1
  38. package/dist/presets/files/generateFrameworkInfo.js.map +1 -1
  39. package/dist/presets/files/generateProjectConfig.js +1 -1
  40. package/dist/presets/files/generateProjectConfig.js.map +1 -1
  41. package/dist/presets/files/writeFileToDist.js +1 -1
  42. package/dist/presets/files/writeFileToDist.js.map +1 -1
  43. package/dist/presets/hooks/build.js +1 -0
  44. package/dist/presets/hooks/build.js.map +1 -1
  45. package/dist/presets/index.js +1 -1
  46. package/dist/presets/index.js.map +1 -1
  47. package/dist/presets/platforms/plugin.js +14 -4
  48. package/dist/presets/platforms/plugin.js.map +1 -1
  49. package/dist/presets/platforms/rn.js +8 -9
  50. package/dist/presets/platforms/rn.js.map +1 -1
  51. package/dist/util/createPage.js +1 -1
  52. package/dist/util/createPage.js.map +1 -1
  53. package/dist/util/defineConfig.d.ts +1 -1
  54. package/dist/util/index.d.ts +1 -0
  55. package/dist/util/index.js +7 -3
  56. package/dist/util/index.js.map +1 -1
  57. package/package.json +27 -34
  58. package/src/__tests__/__mocks__/presets.ts +1 -1
  59. package/src/__tests__/build-config.spec.ts +2 -1
  60. package/src/__tests__/cli.spec.ts +12 -1
  61. package/src/__tests__/config.spec.ts +2 -1
  62. package/src/__tests__/doctor-config.spec.ts +2 -2
  63. package/src/__tests__/doctor-eslint.spec.ts +2 -28
  64. package/src/__tests__/doctor-recommand.spec.ts +2 -1
  65. package/src/__tests__/dotenv-parse.spec.ts +2 -2
  66. package/src/__tests__/fixtures/default/config/index.js +6 -0
  67. package/src/__tests__/info.spec.ts +2 -2
  68. package/src/__tests__/inspect.spec.ts +8 -3
  69. package/src/__tests__/update.spec.ts +3 -4
  70. package/src/__tests__/utils/index.ts +2 -1
  71. package/src/cli.ts +26 -17
  72. package/src/create/creator.ts +2 -1
  73. package/src/create/fetchTemplate.ts +39 -31
  74. package/src/create/page.ts +31 -16
  75. package/src/create/plugin.ts +2 -1
  76. package/src/create/project.ts +40 -40
  77. package/src/index.ts +2 -1
  78. package/src/presets/commands/build.ts +49 -33
  79. package/src/presets/commands/config.ts +1 -1
  80. package/src/presets/commands/create.ts +6 -0
  81. package/src/presets/commands/global-config.ts +17 -14
  82. package/src/presets/commands/info.ts +2 -1
  83. package/src/presets/commands/init.ts +2 -1
  84. package/src/presets/commands/inspect.ts +3 -2
  85. package/src/presets/commands/update.ts +3 -2
  86. package/src/presets/constant/hooks.ts +1 -0
  87. package/src/presets/files/generateProjectConfig.ts +1 -1
  88. package/src/presets/files/writeFileToDist.ts +1 -1
  89. package/src/presets/hooks/build.ts +1 -0
  90. package/src/presets/index.ts +1 -1
  91. package/src/presets/platforms/plugin.ts +13 -2
  92. package/src/presets/platforms/rn.ts +17 -6
  93. package/src/util/createPage.ts +1 -2
  94. package/src/util/defineConfig.ts +1 -1
  95. package/src/util/index.ts +6 -1
  96. package/templates/default/{_env.dev → _env.development} +1 -1
  97. package/templates/default/_env.production +1 -0
  98. package/templates/default/_env.test +1 -1
  99. package/templates/default/_eslintrc +1 -1
  100. package/templates/default/package.json.tmpl +63 -73
  101. package/templates/default/src/app.js +14 -12
  102. package/templates/default/src/pages/index/index.jsx +1 -2
  103. package/templates/default/src/pages/index/index.vue +0 -7
  104. package/templates/default/template_creator.js +22 -17
  105. package/templates/default/tsconfig.json +3 -2
  106. package/templates/default/types/global.d.ts +2 -2
  107. package/templates/plugin-compile/README.md +1 -1
  108. package/templates/plugin-compile/package.json.tmpl +3 -4
  109. package/templates/plugin-compile/src/index.ts +1 -1
  110. package/dist/config/babylon.d.ts +0 -3
  111. package/dist/config/babylon.js +0 -16
  112. package/dist/config/babylon.js.map +0 -1
  113. package/src/__tests__/fixtures/nerv/babel.config.js +0 -10
  114. package/src/__tests__/fixtures/nerv/config/dev.js +0 -9
  115. package/src/__tests__/fixtures/nerv/config/index.js +0 -70
  116. package/src/__tests__/fixtures/nerv/config/prod.js +0 -18
  117. package/src/__tests__/fixtures/nerv/package.json +0 -59
  118. package/src/__tests__/fixtures/nerv/src/app.config.ts +0 -11
  119. package/src/__tests__/fixtures/nerv/src/app.tsx +0 -10
  120. package/src/__tests__/fixtures/nerv/src/index.html +0 -19
  121. package/src/__tests__/fixtures/nerv/src/pages/index/index.config.ts +0 -3
  122. package/src/__tests__/fixtures/nerv/src/pages/index/index.tsx +0 -25
  123. package/src/__tests__/fixtures/vue/babel.config.js +0 -10
  124. package/src/__tests__/fixtures/vue/config/dev.js +0 -9
  125. package/src/__tests__/fixtures/vue/config/index.js +0 -70
  126. package/src/__tests__/fixtures/vue/config/prod.js +0 -18
  127. package/src/__tests__/fixtures/vue/package.json +0 -54
  128. package/src/__tests__/fixtures/vue/src/app.config.js +0 -11
  129. package/src/__tests__/fixtures/vue/src/app.js +0 -12
  130. package/src/__tests__/fixtures/vue/src/index.html +0 -19
  131. package/src/__tests__/fixtures/vue/src/pages/index/index.config.js +0 -3
  132. package/src/__tests__/fixtures/vue/src/pages/index/index.vue +0 -15
  133. package/src/config/babylon.ts +0 -16
  134. package/templates/default/__tests__/index.test.js.tmpl +0 -12
  135. package/templates/default/_env.prod +0 -1
  136. package/templates/default/jest.config.js +0 -6
  137. package/templates/default/project.tt.json +0 -9
@@ -1,3 +1,5 @@
1
+ import * as path from 'node:path'
2
+
1
3
  import { CompilerType, createProject, CSSType, FrameworkType, NpmType, PeriodType } from '@tarojs/binding'
2
4
  import {
3
5
  chalk,
@@ -10,10 +12,9 @@ import {
10
12
  TARO_CONFIG_FOLDER
11
13
  } from '@tarojs/helper'
12
14
  import { isArray } from '@tarojs/shared'
15
+ import axios from 'axios'
13
16
  import * as inquirer from 'inquirer'
14
17
  import * as ora from 'ora'
15
- import * as path from 'path'
16
- import * as request from 'request'
17
18
  import * as semver from 'semver'
18
19
 
19
20
  import { clearConsole, getPkgVersion, getRootPath } from '../util'
@@ -59,9 +60,9 @@ export default class Project extends Creator {
59
60
 
60
61
  constructor (options: IProjectConfOptions) {
61
62
  super(options.sourceRoot)
62
- const unSupportedVer = semver.lt(process.version, 'v7.6.0')
63
+ const unSupportedVer = semver.lt(process.version, 'v18.0.0')
63
64
  if (unSupportedVer) {
64
- throw new Error('Node.js 版本过低,推荐升级 Node.js 至 v8.0.0+')
65
+ throw new Error('Node.js 版本过低,推荐升级 Node.js 至 v18.0.0+')
65
66
  }
66
67
  this.rootPath = this._rootPath
67
68
 
@@ -105,12 +106,19 @@ export default class Project extends Creator {
105
106
  this.askFramework(conf, prompts)
106
107
  this.askTypescript(conf, prompts)
107
108
  this.askCSS(conf, prompts)
108
- this.askCompiler(conf, prompts)
109
109
  this.askNpm(conf, prompts)
110
- await this.askTemplateSource(conf, prompts)
111
-
112
110
  const answers = await inquirer.prompt<IProjectConf>(prompts)
113
111
 
112
+ // Note: 由于 Solid 框架适配 Vite 还存在某些问题,所以在选择 Solid 框架时,不再询问编译工具
113
+ prompts = []
114
+ if (answers.framework === FrameworkType.Solid || conf.framework === FrameworkType.Solid) {
115
+ answers.compiler = CompilerType.Webpack5
116
+ } else {
117
+ this.askCompiler(conf, prompts)
118
+ }
119
+ await this.askTemplateSource(conf, prompts)
120
+ const compilerAndTemplateSourceAnswer = await inquirer.prompt<IProjectConf>(prompts)
121
+
114
122
  prompts = []
115
123
  const templates = await this.fetchTemplates(answers)
116
124
  await this.askTemplate(conf, prompts, templates)
@@ -118,6 +126,7 @@ export default class Project extends Creator {
118
126
 
119
127
  return {
120
128
  ...answers,
129
+ ...compilerAndTemplateSourceAnswer,
121
130
  ...templateChoiceAnswer
122
131
  }
123
132
  }
@@ -212,10 +221,6 @@ export default class Project extends Creator {
212
221
  name: 'Webpack5',
213
222
  value: CompilerType.Webpack5
214
223
  },
215
- {
216
- name: 'Webpack4',
217
- value: CompilerType.Webpack4
218
- },
219
224
  {
220
225
  name: 'Vite',
221
226
  value: CompilerType.Vite
@@ -242,17 +247,13 @@ export default class Project extends Creator {
242
247
  name: 'PReact',
243
248
  value: FrameworkType.Preact
244
249
  },
245
- // {
246
- // name: 'Nerv',
247
- // value: 'nerv'
248
- // },
249
- {
250
- name: 'Vue',
251
- value: FrameworkType.Vue
252
- },
253
250
  {
254
251
  name: 'Vue3',
255
252
  value: FrameworkType.Vue3
253
+ },
254
+ {
255
+ name: 'Solid',
256
+ value: FrameworkType.Solid
256
257
  }
257
258
  ]
258
259
 
@@ -348,7 +349,7 @@ export default class Project extends Creator {
348
349
  askTemplate: AskMethods = function (conf, prompts, list = []) {
349
350
  const choices = list.map(item => ({
350
351
  name: item.desc ? `${item.name}(${item.desc})` : item.name,
351
- value: item.name
352
+ value: item.value || item.name
352
353
  }))
353
354
 
354
355
  if (!conf.hideDefaultTemplate) {
@@ -400,6 +401,7 @@ export default class Project extends Creator {
400
401
 
401
402
  async fetchTemplates (answers: IProjectConf): Promise<ITemplates[]> {
402
403
  const { templateSource, framework, compiler } = answers
404
+ this.conf.framework = this.conf.framework || framework || ''
403
405
  this.conf.templateSource = this.conf.templateSource || templateSource
404
406
 
405
407
  // 使用默认模版
@@ -414,10 +416,12 @@ export default class Project extends Creator {
414
416
  const templateChoices = await fetchTemplate(this.conf.templateSource, this.templatePath(''), isClone)
415
417
 
416
418
  const filterFramework = (_framework) => {
419
+ const current = this.conf.framework?.toLowerCase()
420
+
417
421
  if (typeof _framework === 'string' && _framework) {
418
- return framework === _framework
422
+ return current === _framework.toLowerCase()
419
423
  } else if (isArray(_framework)) {
420
- return _framework?.includes(framework)
424
+ return _framework?.map(name => name.toLowerCase()).includes(current)
421
425
  } else {
422
426
  return true
423
427
  }
@@ -468,27 +472,23 @@ export default class Project extends Creator {
468
472
  }
469
473
  }
470
474
 
471
- function getOpenSourceTemplates (platform) {
475
+ function getOpenSourceTemplates (platform: string) {
472
476
  return new Promise((resolve, reject) => {
473
477
  const spinner = ora({ text: '正在拉取开源模板列表...', discardStdin: false }).start()
474
- request.get('https://gitee.com/NervJS/awesome-taro/raw/next/index.json', (error, _response, body) => {
475
- if (error) {
478
+ axios.get('https://gitee.com/NervJS/awesome-taro/raw/next/index.json')
479
+ .then(response => {
480
+ spinner.succeed(`${chalk.grey('拉取开源模板列表成功!')}`)
481
+ const collection = response.data
482
+ switch (platform.toLowerCase()) {
483
+ case 'react':
484
+ return resolve(collection.react)
485
+ default:
486
+ return resolve([NONE_AVAILABLE_TEMPLATE])
487
+ }
488
+ })
489
+ .catch(_error => {
476
490
  spinner.fail(chalk.red('拉取开源模板列表失败!'))
477
491
  return reject(new Error())
478
- }
479
-
480
- spinner.succeed(`${chalk.grey('拉取开源模板列表成功!')}`)
481
-
482
- const collection = JSON.parse(body)
483
-
484
- switch (platform) {
485
- case 'react':
486
- return resolve(collection.react)
487
- case 'vue':
488
- return resolve(collection.vue)
489
- default:
490
- return resolve([NONE_AVAILABLE_TEMPLATE])
491
- }
492
- })
492
+ })
493
493
  })
494
494
  }
package/src/index.ts CHANGED
@@ -20,4 +20,5 @@ export {
20
20
  defineConfig,
21
21
  doctor,
22
22
  getRootPath,
23
- Project }
23
+ Project
24
+ }
@@ -16,6 +16,7 @@ export default (ctx: IPluginContext) => {
16
16
  '--env [env]': 'Value for process.env.NODE_ENV',
17
17
  '--mode [mode]': 'Value of dotenv extname',
18
18
  '-p, --port [port]': 'Specified port',
19
+ '--no-build': 'Do not build project',
19
20
  '--platform': '[rn] Specific React-Native build target: android / ios, android is default value',
20
21
  '--reset-cache': '[rn] Clear transform cache',
21
22
  '--public-path': '[rn] Assets public path',
@@ -29,12 +30,15 @@ export default (ctx: IPluginContext) => {
29
30
  '--new-blended': 'Blended Taro project in an original MiniApp project while supporting building components independently',
30
31
  '--plugin [typeName]': 'Build Taro plugin project, weapp',
31
32
  '--env-prefix [envPrefix]': "Provide the dotEnv varables's prefix",
33
+ '--no-inject-global-style': '[H5] Do not inject global style',
34
+ '--no-check': 'Do not check config is valid or not',
32
35
  },
33
36
  synopsisList: [
34
37
  'taro build --type weapp',
35
38
  'taro build --type weapp --watch',
36
39
  'taro build --type weapp --env production',
37
40
  'taro build --type weapp --blended',
41
+ 'taro build --type weapp --no-build',
38
42
  'taro build native-components --type weapp',
39
43
  'taro build --type weapp --new-blended',
40
44
  'taro build --plugin weapp --watch',
@@ -43,7 +47,7 @@ export default (ctx: IPluginContext) => {
43
47
  ],
44
48
  async fn(opts) {
45
49
  const { options, config, _ } = opts
46
- const { platform, isWatch, blended, newBlended } = options
50
+ const { platform, isWatch, blended, newBlended, withoutBuild, noInjectGlobalStyle, noCheck } = options
47
51
  const { fs, chalk, PROJECT_CONFIG } = ctx.helper
48
52
  const { outputPath, configPath } = ctx.paths
49
53
 
@@ -58,38 +62,40 @@ export default (ctx: IPluginContext) => {
58
62
  }
59
63
 
60
64
  // 校验 Taro 项目配置
61
- const checkResult = await checkConfig({
62
- projectConfig: ctx.initialConfig,
63
- helper: ctx.helper
64
- })
65
- if (!checkResult.isValid) {
66
- const ERROR = chalk.red('[✗] ')
67
- const WARNING = chalk.yellow('[!] ')
68
- const SUCCESS = chalk.green('[✓] ')
69
-
70
- const lineChalk = chalk.hex('#fff')
71
- const errorChalk = chalk.hex('#f00')
72
- console.log(errorChalk(`Taro 配置有误,请检查! (${configPath})`))
73
- checkResult.messages.forEach((message) => {
74
- switch (message.kind) {
75
- case MessageKind.Error:
76
- console.log(' ' + ERROR + lineChalk(message.content))
77
- break
78
- case MessageKind.Success:
79
- console.log(' ' + SUCCESS + lineChalk(message.content))
80
- break
81
- case MessageKind.Warning:
82
- console.log(' ' + WARNING + lineChalk(message.content))
83
- break
84
- case MessageKind.Manual:
85
- console.log(' ' + lineChalk(message.content))
86
- break
87
- default:
88
- break
89
- }
65
+ if (!noCheck) {
66
+ const checkResult = await checkConfig({
67
+ projectConfig: ctx.initialConfig,
68
+ helper: ctx.helper
90
69
  })
91
- console.log('')
92
- process.exit(0)
70
+ if (!checkResult.isValid) {
71
+ const ERROR = chalk.red('[✗] ')
72
+ const WARNING = chalk.yellow('[!] ')
73
+ const SUCCESS = chalk.green('[✓] ')
74
+
75
+ const lineChalk = chalk.hex('#fff')
76
+ const errorChalk = chalk.hex('#f00')
77
+ console.log(errorChalk(`Taro 配置有误,请检查! (${configPath})`))
78
+ checkResult.messages.forEach((message) => {
79
+ switch (message.kind) {
80
+ case MessageKind.Error:
81
+ console.log(' ' + ERROR + lineChalk(message.content))
82
+ break
83
+ case MessageKind.Success:
84
+ console.log(' ' + SUCCESS + lineChalk(message.content))
85
+ break
86
+ case MessageKind.Warning:
87
+ console.log(' ' + WARNING + lineChalk(message.content))
88
+ break
89
+ case MessageKind.Manual:
90
+ console.log(' ' + lineChalk(message.content))
91
+ break
92
+ default:
93
+ break
94
+ }
95
+ })
96
+ console.log('')
97
+ process.exit(0)
98
+ }
93
99
  }
94
100
 
95
101
  const isProduction = process.env.NODE_ENV === 'production' || !isWatch
@@ -110,8 +116,18 @@ export default (ctx: IPluginContext) => {
110
116
  mode: isProduction ? 'production' : 'development',
111
117
  blended,
112
118
  isBuildNativeComp,
119
+ withoutBuild,
113
120
  newBlended,
114
- async modifyWebpackChain(chain, webpack, data) {
121
+ noInjectGlobalStyle,
122
+ async modifyAppConfig (appConfig) {
123
+ await ctx.applyPlugins({
124
+ name: hooks.MODIFY_APP_CONFIG,
125
+ opts: {
126
+ appConfig
127
+ }
128
+ })
129
+ },
130
+ async modifyWebpackChain (chain, webpack, data) {
115
131
  await ctx.applyPlugins({
116
132
  name: hooks.MODIFY_WEBPACK_CHAIN,
117
133
  initialVal: chain,
@@ -1,4 +1,4 @@
1
- import * as path from 'path'
1
+ import * as path from 'node:path'
2
2
 
3
3
  import type { IPluginContext } from '@tarojs/service'
4
4
 
@@ -41,6 +41,9 @@ export default (ctx: IPluginContext) => {
41
41
  const type = options.type || createTemplateTypeEnum.PAGE
42
42
  const name = _[1] || options.name
43
43
  const description = options.description || ''
44
+ const afterCreate = options.afterCreate
45
+ const templateSource = options.templateSource
46
+ const clone = options.clone
44
47
  const { chalk } = ctx.helper
45
48
  const { appPath } = ctx.paths
46
49
 
@@ -52,11 +55,14 @@ export default (ctx: IPluginContext) => {
52
55
 
53
56
  const Page = require('../../create/page').default
54
57
  const page = new Page({
58
+ clone,
55
59
  subPkg: options.subpkg,
56
60
  pageDir: options.dir,
57
61
  pageName: name,
58
62
  projectDir: appPath,
59
63
  description,
64
+ templateSource,
65
+ afterCreate,
60
66
  async modifyCustomTemplateConfig (cb: TSetCustomTemplateConfig) {
61
67
  await ctx.applyPlugins({ name: hooks.MODIFY_CREATE_TEMPLATE, opts: cb })
62
68
  }
@@ -1,5 +1,6 @@
1
+ import * as path from 'node:path'
2
+
1
3
  import * as ora from 'ora'
2
- import * as path from 'path'
3
4
  import * as validatePkgName from 'validate-npm-package-name'
4
5
 
5
6
  import { execCommand, getPkgNameByFilterVersion, getRootPath } from '../../util'
@@ -23,8 +24,6 @@ const PLUGIN_TYPE_TO_CONFIG_KEY = {
23
24
  preset: 'presets'
24
25
  }
25
26
 
26
-
27
-
28
27
  export default (ctx: IPluginContext) => {
29
28
  ctx.registerCommand({
30
29
  name: 'global-config',
@@ -36,9 +35,10 @@ export default (ctx: IPluginContext) => {
36
35
  'taro global-config reset',
37
36
  ],
38
37
  optionsMap: {
38
+ '-r --registry [url]': '指定 npm registry',
39
39
  '-h, --help': 'output usage information'
40
40
  },
41
- fn ({ _ }) {
41
+ fn ({ _, options }) {
42
42
  const [, action, pluginName] = _
43
43
  const { getUserHomeDir, TARO_GLOBAL_CONFIG_DIR, fs, TARO_GLOBAL_CONFIG_FILE } = ctx.helper
44
44
  const homedir = getUserHomeDir()
@@ -46,8 +46,9 @@ export default (ctx: IPluginContext) => {
46
46
  if (!homedir) return console.log('找不到用户根目录')
47
47
  const rootPath = getRootPath()
48
48
  const templatePath = path.join(rootPath, 'templates', 'global-config')
49
+ const registry = options.registry || options.r
49
50
  function makeSureConfigExists () {
50
- if (!fs.existsSync(globalPluginConfigDir)){
51
+ if (!fs.existsSync(globalPluginConfigDir)) {
51
52
  const spinner = ora(`目录不存在,全局配置初始化`).start()
52
53
  try {
53
54
  fs.copySync(templatePath, globalPluginConfigDir)
@@ -56,10 +57,9 @@ export default (ctx: IPluginContext) => {
56
57
  spinner.fail(`全局配置初始化失败,${e}`)
57
58
  process.exit(1)
58
59
  }
59
-
60
60
  }
61
61
  }
62
- function addOrRemovePresetOrPlugin (actionType: TPresetOrPluginAction, pluginType: TPluginType ) {
62
+ function addOrRemovePresetOrPlugin (actionType: TPresetOrPluginAction, pluginType: TPluginType) {
63
63
  makeSureConfigExists()
64
64
  const presetOrPluginChineseName = PRESET_OR_PLUGIN_CHINESE_NAME_MAP[pluginType]
65
65
  const chineseCommand = PRESET_OR_PLUGIN_COMMAND_CHINESE_MAP_MAP[actionType]
@@ -74,8 +74,12 @@ export default (ctx: IPluginContext) => {
74
74
  spinner.fail('安装的插件名不合规!')
75
75
  process.exit(1)
76
76
  }
77
+ let command = `cd ${globalPluginConfigDir} && npm ${actionType} ${pluginName}`
78
+ if (registry) {
79
+ command += ` --registry=${registry}`
80
+ }
77
81
  execCommand({
78
- command: `cd ${globalPluginConfigDir} && npm ${actionType} ${pluginName}`,
82
+ command,
79
83
  successCallback (data) {
80
84
  console.log(data.replace(/\n$/, ''))
81
85
  spinner.start(`开始修改${presetOrPluginChineseName}配置`)
@@ -83,21 +87,21 @@ export default (ctx: IPluginContext) => {
83
87
  let globalConfig
84
88
  try {
85
89
  globalConfig = fs.readJSONSync(configFilePath)
86
- } catch (e){
90
+ } catch (e) {
87
91
  spinner.fail('获取配置文件失败')
88
92
  }
89
93
  const configKey = PLUGIN_TYPE_TO_CONFIG_KEY[pluginType]
90
94
  const configItem = globalConfig[configKey] || []
91
- const pluginIndex = configItem.findIndex((item)=>{
95
+ const pluginIndex = configItem.findIndex((item) => {
92
96
  if (typeof item === 'string') return item === pluginWithoutVersionName
93
- if ( item instanceof Array) return item?.[0] === pluginWithoutVersionName
97
+ if (item instanceof Array) return item?.[0] === pluginWithoutVersionName
94
98
  })
95
99
  const shouldChangeFile = !(Number(pluginIndex !== -1) ^ Number(actionType === 'uninstall'))
96
- if (shouldChangeFile){
100
+ if (shouldChangeFile) {
97
101
  actionType === 'install' ? configItem.push(pluginWithoutVersionName) : configItem.splice(pluginIndex, 1)
98
102
  try {
99
103
  fs.writeJSONSync(configFilePath, {
100
- [configKey] : configItem
104
+ [configKey]: configItem
101
105
  })
102
106
  } catch (e) {
103
107
  spinner.fail(`修改配置文件失败:${e}`)
@@ -134,4 +138,3 @@ export default (ctx: IPluginContext) => {
134
138
  }
135
139
  })
136
140
  }
137
-
@@ -1,5 +1,6 @@
1
+ import * as path from 'node:path'
2
+
1
3
  import * as envinfo from 'envinfo'
2
- import * as path from 'path'
3
4
 
4
5
  import { getPkgVersion } from '../../util'
5
6
 
@@ -18,9 +18,10 @@ export default (ctx: IPluginContext) => {
18
18
  // init project
19
19
  const { appPath } = ctx.paths
20
20
  const { options } = opts
21
- const { projectName, templateSource, clone, template, description, typescript, css, npm, framework, compiler, hideDefaultTemplate } = options
21
+ const { projectName, templateSource, clone, template, description, typescript, css, npm, framework, compiler, hideDefaultTemplate, sourceRoot } = options
22
22
  const Project = require('../../create/project').default
23
23
  const project = new Project({
24
+ sourceRoot,
24
25
  projectName,
25
26
  projectDir: appPath,
26
27
  npm,
@@ -1,3 +1,5 @@
1
+ import * as path from 'node:path'
2
+
1
3
  import {
2
4
  ENTRY,
3
5
  OUTPUT_DIR,
@@ -5,7 +7,6 @@ import {
5
7
  SOURCE_DIR
6
8
  } from '@tarojs/helper'
7
9
  import { getPlatformType } from '@tarojs/shared'
8
- import * as path from 'path'
9
10
 
10
11
  import * as hooks from '../constant'
11
12
 
@@ -74,7 +75,7 @@ export default (ctx: IPluginContext) => {
74
75
 
75
76
  if (mode === 'console') {
76
77
  const highlight = require('cli-highlight').default
77
- console.log(highlight(res, { language: 'js' }))
78
+ console.info(highlight(res, { language: 'js' }))
78
79
  } else if (mode === 'output' && outputPath) {
79
80
  fs.writeFileSync(outputPath, res)
80
81
  }
@@ -1,7 +1,8 @@
1
+ import * as path from 'node:path'
2
+
1
3
  import * as inquirer from 'inquirer'
2
4
  import * as getLatestVersion from 'latest-version'
3
5
  import * as ora from 'ora'
4
- import * as path from 'path'
5
6
  import * as semver from 'semver'
6
7
 
7
8
  import packagesManagement from '../../config/packagesManagement'
@@ -63,7 +64,7 @@ export default (ctx: IPluginContext) => {
63
64
  const updateTarget = isSelf ? ' CLI ' : ' Taro 项目依赖'
64
65
  const spinString = `正在更新${updateTarget}到 v${version} ...`
65
66
  const spinner = ora(spinString).start()
66
- execCommand({
67
+ execCommand({
67
68
  command,
68
69
  successCallback (data) {
69
70
  spinner.stop()
@@ -1,3 +1,4 @@
1
+ export const MODIFY_APP_CONFIG = 'modifyAppConfig'
1
2
  export const MODIFY_WEBPACK_CHAIN = 'modifyWebpackChain'
2
3
  export const MODIFY_VITE_CONFIG = 'modifyViteConfig'
3
4
  export const MODIFY_BUILD_ASSETS = 'modifyBuildAssets'
@@ -1,4 +1,4 @@
1
- import * as path from 'path'
1
+ import * as path from 'node:path'
2
2
 
3
3
  import type { IPluginContext } from '@tarojs/service'
4
4
 
@@ -1,4 +1,4 @@
1
- import * as path from 'path'
1
+ import * as path from 'node:path'
2
2
 
3
3
  import type { IPluginContext } from '@tarojs/service'
4
4
 
@@ -4,6 +4,7 @@ import type { IPluginContext } from '@tarojs/service'
4
4
 
5
5
  export default (ctx: IPluginContext) => {
6
6
  [
7
+ hooks.MODIFY_APP_CONFIG,
7
8
  hooks.MODIFY_WEBPACK_CHAIN,
8
9
  hooks.MODIFY_VITE_CONFIG,
9
10
  hooks.MODIFY_BUILD_ASSETS,
@@ -1,4 +1,4 @@
1
- import * as path from 'path'
1
+ import * as path from 'node:path'
2
2
 
3
3
  export default () => {
4
4
  return {
@@ -1,3 +1,6 @@
1
+ import * as path from 'node:path'
2
+
3
+ import { fs } from '@tarojs/helper'
1
4
  import { getPlatformType } from '@tarojs/shared'
2
5
 
3
6
  import type { IPluginContext } from '@tarojs/service'
@@ -35,7 +38,7 @@ export default (ctx: IPluginContext) => {
35
38
  ...config,
36
39
  isBuildPlugin: true,
37
40
  isWatch,
38
- outputRoot: `${config.outputRoot}`,
41
+ outputRoot: `${config.outputRoot}/plugin`,
39
42
  platform
40
43
  },
41
44
  options: Object.assign({}, options, {
@@ -63,7 +66,15 @@ export default (ctx: IPluginContext) => {
63
66
  })
64
67
  }
65
68
 
66
- buildPlugin(plugin)
69
+ await buildPlugin(plugin)
70
+
71
+ try {
72
+ const docSrcPath = path.join(process.cwd(), 'src/plugin/doc')
73
+ const docDestPath = path.join(process.cwd(), 'miniprogram/doc')
74
+ fs.copy(docSrcPath, docDestPath)
75
+ } catch (err) {
76
+ console.error('[@tarojs/cli] build plugin doc failed: ', err)
77
+ }
67
78
  }
68
79
  })
69
80
  }
@@ -1,9 +1,9 @@
1
+ import * as fs from 'node:fs'
2
+ import * as os from 'node:os'
3
+ import * as path from 'node:path'
1
4
 
2
5
  import { chalk } from '@tarojs/helper'
3
6
  import * as child_process from 'child_process'
4
- import * as fs from 'fs'
5
- import * as os from 'os'
6
- import * as path from 'path'
7
7
 
8
8
  import { printDevelopmentTip } from '../../util'
9
9
 
@@ -32,7 +32,7 @@ function makeSureReactNativeInstalled (workspaceRoot: string): Promise<void> {
32
32
  // 便于开发时切换版本
33
33
  const devTag = process.env.DEVTAG || ''
34
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 expo@~50.0.2 @tarojs/taro-rn${devTag} @tarojs/components-rn${devTag} @tarojs/rn-runner${devTag} @tarojs/rn-supporter${devTag} @tarojs/runtime-rn${devTag}`
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
36
  console.log(packages)
37
37
  // windows下不加引号的话,package.json中添加的依赖不会自动带上^
38
38
  packages = packages.split(' ').map(str => `"${str}"`).join(' ')
@@ -62,8 +62,20 @@ export default (ctx: IPluginContext) => {
62
62
  useConfigName: 'rn',
63
63
  async fn ({ config }) {
64
64
  const { appPath, nodeModulesPath } = ctx.paths
65
- const { deviceType = 'android', port, resetCache, publicPath, bundleOutput, sourcemapOutput, sourceMapUrl, sourcemapSourcesRoot, assetsDest, qr } = ctx.runOpts.options
66
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
+
67
79
  printDevelopmentTip('rn')
68
80
 
69
81
  // 准备 rnRunner 参数
@@ -81,7 +93,6 @@ export default (ctx: IPluginContext) => {
81
93
  sourcemapSourcesRoot,
82
94
  assetsDest,
83
95
  buildAdapter: config.platform,
84
- globalObject: 'global' // TODO: 是否可以去掉?
85
96
  }
86
97
 
87
98
  if (!rnRunnerOpts.entry) {
@@ -26,7 +26,7 @@ const isValidSubPkgObject = (subPkgObject: ObjectExpression) => {
26
26
  const addNewSubPackage = (node: ObjectExpression, page: string, subPackage: string): ConfigModificationState => {
27
27
  let subPackages = node?.properties.find(node => (node as any).key.name === 'subPackages') as ObjectProperty
28
28
  if (!subPackages) {
29
- // config 文件不存在 subPackages 字段的情况,给该字段打赋予默认值
29
+ // config 文件不存在 subPackages 字段的情况,给该字段赋予默认值
30
30
  const subPkgObject = t.objectProperty(t.identifier('subPackages'), t.arrayExpression([]))
31
31
  subPackages = subPkgObject
32
32
  node?.properties.push(subPkgObject)
@@ -72,7 +72,6 @@ const addNewPage = (node: ObjectExpression, page: string): ConfigModificationSta
72
72
  return ConfigModificationState.Success
73
73
  }
74
74
 
75
-
76
75
  const modifyPages = (path: NodePath<ExportDefaultDeclaration>, newPageConfig, callback: ModifyCallback) => {
77
76
  let state = ConfigModificationState.Fail
78
77
  const node = path.node.declaration as any
@@ -10,7 +10,7 @@ export interface ConfigEnv {
10
10
  mode: string
11
11
  }
12
12
 
13
- export type UserConfigFn<T extends CompilerTypes = CompilerWebpackTypes> = (mergin: WebpackMerge, env: ConfigEnv) => IProjectConfig<T> | Promise<IProjectConfig<T>>
13
+ export type UserConfigFn<T extends CompilerTypes = CompilerWebpackTypes> = (merge: WebpackMerge, env: ConfigEnv) => IProjectConfig<T> | Promise<IProjectConfig<T>>
14
14
  export type UserConfigExport<T extends CompilerTypes = CompilerWebpackTypes> = IProjectConfig<T> | Promise<IProjectConfig<T>> | UserConfigFn
15
15
 
16
16
  /**
package/src/util/index.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import * as path from 'node:path'
2
+
1
3
  import { chalk, fs, isWindows } from '@tarojs/helper'
2
4
  import { exec } from 'child_process'
3
- import * as path from 'path'
4
5
 
5
6
  export function getRootPath (): string {
6
7
  return path.resolve(__dirname, '../../')
@@ -120,3 +121,7 @@ export function getPkgNameByFilterVersion (pkgString: string) {
120
121
  const versionFlagIndex = pkgString.lastIndexOf('@')
121
122
  return versionFlagIndex === 0 ? pkgString : pkgString.slice(0, versionFlagIndex)
122
123
  }
124
+
125
+ export function isNil (value: any): value is null | undefined {
126
+ return value === null || value === undefined
127
+ }
@@ -1,2 +1,2 @@
1
1
  # 配置文档参考 https://taro-docs.jd.com/docs/next/env-mode-config
2
- # TARO_APP_ID="开发环境下的小程序appid"
2
+ # TARO_APP_ID="开发环境下的小程序 AppID"
@@ -0,0 +1 @@
1
+ # TARO_APP_ID="生产环境下的小程序 AppID"
@@ -1 +1 @@
1
- # TARO_APP_ID="测试环境下的小程序appid"
1
+ # TARO_APP_ID="测试环境下的小程序 AppID"