@ansstory/hias 1.0.2 → 1.0.4

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.
@@ -23,8 +23,12 @@ const beginAction = async (project, args) => {
23
23
  }
24
24
 
25
25
  async function addComponentAction(cpnName, temPath, fileType) {
26
- const dest = program.opts().dest || 'src/components'
27
- const [folderName = 'index'] = dest.match(/[^\\/]+$/)
26
+ // 边界处理: 若为 .\xx\xx\ 则转换为 ./xx/xx/
27
+ const dest = program.opts().dest.replace(/\\/g, '/') || 'src/components'
28
+ // 边界处理: 若为 ./xx/xx 则转换为 ./xx/xx/
29
+ const path = /[\\/]/.test(dest.at(-1)) ? dest : `${dest}/`
30
+
31
+ const [folderName = 'index'] = dest.match(/[^\\/]+(?=\/?$)/)
28
32
  const name = cpnName === 'index' ? folderName : cpnName
29
33
 
30
34
  const result = await compileEjs(temPath, {
@@ -32,8 +36,10 @@ async function addComponentAction(cpnName, temPath, fileType) {
32
36
  lowername: name.toLowerCase(),
33
37
  })
34
38
 
35
- await writeFile(`${dest}/${cpnName}.${fileType}`, result)
36
- console.log(chalk.green.bold('Component creation was successful:'), chalk.blue.bold(`${cpnName}.${fileType}`), chalk.underline(dest))
39
+ const filePath = `${path}${cpnName}.${fileType}`
40
+
41
+ await writeFile(filePath, result)
42
+ console.log(chalk.green.bold('Component creation was successful:'), chalk.blue.bold(`${cpnName}.${fileType}`), chalk.underline(filePath))
37
43
  }
38
44
 
39
45
  async function addVueComponentAction(cpnName) {
@@ -1,3 +1,4 @@
1
+ const chalk = require('chalk')
1
2
  const {
2
3
  beginAction,
3
4
  addVueComponentAction,
@@ -8,26 +9,31 @@ const {
8
9
  } = require('./action')
9
10
 
10
11
  const beginCommander = function (program) {
12
+ console.log()
11
13
  program.command('create <project> [other...]').alias('crt').description('create project. For example: hias create airbnb').action(beginAction)
12
14
  program
13
15
  .command('adv <vuecpnname> [...others]')
14
- .description('add vue component into a folder, For example: hias addv Demo -d src/components')
16
+ .description(`add vue component into a folder, For example: ${chalk.green.bold(`hias addv Demo -d src/components or hias addv index -d src/views/demo`)}`)
15
17
  .action(addVueComponentAction)
16
18
  program
17
19
  .command('adr <reactcpnname> [...others]')
18
- .description('add react jsx component into a folder, For example: hias addr Demo -d src/components')
20
+ .description(
21
+ `add react jsx component into a folder, For example: ${chalk.green.bold(`hias addr Demo -d src/components or hias addr index -d src/views/demo`)}`
22
+ )
19
23
  .action(addReactComponentAction)
20
24
  program
21
25
  .command('adrt <reactcpnname> [...others]')
22
- .description('add react tsx component into a folder, For example: hias addrt Demo -d src/components')
26
+ .description(
27
+ `add react tsx component into a folder, For example: ${chalk.green.bold(`hias addrt Demo -d src/components or hias addrt index -d src/views/demo`)}`
28
+ )
23
29
  .action(addReactTsComponentAction)
24
30
  program
25
31
  .command('adrd <reactcpnname> [...others]')
26
- .description('add redux jsx store into a folder, For example: hias addrt useDemoStore -d src/store/modules')
32
+ .description(`add redux jsx store into a folder, For example: ${chalk.blue.bold(`hias adrd useDemoStore -d src/store/modules`)}`)
27
33
  .action(addReduxStoreAction)
28
34
  program
29
35
  .command('adrdt <reactcpnname> [...others]')
30
- .description('add redux tsx store into a folder, For example: hias addrt useDemoStore -d src/store/modules')
36
+ .description(`add redux tsx store into a folder, For example: ${chalk.blue.bold(`hias adrdt useDemoStore -d src/store/modules`)}`)
31
37
  .action(addReduxTsStoreAction)
32
38
  }
33
39
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ansstory/hias",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "description": "创建项目模板",
6
6
  "author": "AnsStory story <story0809@163.com>",