create-banana 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/.prettierrc +10 -3
  2. package/.vscode/settings.json +10 -0
  3. package/bin/index.js +110 -35
  4. package/eslint.config.js +59 -0
  5. package/package.json +6 -2
  6. package/readme.md +6 -1
  7. package/template/Eslint/eslint.config.js.ejs +70 -31
  8. package/template/Eslint/package.json +1 -2
  9. package/template/Prettier/.prettierrc +1 -1
  10. package/template/Prettier/package.json +2 -2
  11. package/template/base/src/App.vue.ejs +119 -48
  12. package/template/base/src/components/HelloWorld.vue +1 -1
  13. package/template/base/src/components/TheWelcome.vue +61 -26
  14. package/template/base/src/components/icons/IconCommunity.vue +6 -1
  15. package/template/base/src/components/icons/IconDocumentation.vue +6 -1
  16. package/template/base/src/components/icons/IconEcosystem.vue +6 -1
  17. package/template/base/src/components/icons/IconSupport.vue +6 -1
  18. package/template/base/src/main.js.ejs +12 -1
  19. package/template/base/vite.config.js +5 -5
  20. package/template/pinia/counter.js +7 -7
  21. package/template/pinia/pinia-plugin-persistedstate/key.js +6 -6
  22. package/template/vue-router/components/TitleText.vue +13 -0
  23. package/template/vue-router/package.json +5 -0
  24. package/template/vue-router/router/index.js +32 -0
  25. package/template/vue-router/views/AboutView.vue.ejs +21 -0
  26. package/template/vue-router/views/HomeView.vue +7 -0
  27. package/template/vue-router/views/NotFound.vue +7 -0
  28. package/utils/URL.js +9 -7
  29. package/utils/figletPrint.js +6 -6
  30. package/utils/pathExists.js +13 -11
  31. package/utils/rainbow.js +17 -12
  32. package/utils/template/base/appVue.js +25 -13
  33. package/utils/template/base/base.js +12 -12
  34. package/utils/template/base/main.js +25 -13
  35. package/utils/template/eslint/eslint.js +16 -19
  36. package/utils/template/eslint/eslintConfig.js +14 -11
  37. package/utils/template/pinia/pinia.js +20 -12
  38. package/utils/template/pinia/piniaPluginPersistedstate.js +24 -13
  39. package/utils/template/prettier.js +19 -20
  40. package/utils/template/vueRouter/aboutView.js +29 -0
  41. package/utils/template/vueRouter/vueRouter.js +46 -0
  42. package/eslint.config.mjs +0 -27
  43. package/template/Eslint/.eslintignore +0 -36
  44. package/template/Prettier/.prettierignore +0 -7
  45. package/template/base/.vscode/extensions.json +0 -3
@@ -1,39 +1,36 @@
1
1
  // 添加Eslint功能
2
- import path from 'path'
3
- import fs from 'fs-extra'
4
- import { templatePath } from '../../URL.js'
2
+ import path from 'path';
3
+ import fs from 'fs-extra';
4
+ import { templatePath } from '../../URL.js';
5
5
 
6
6
  // TODO: 优化变量名长度,提高可读性
7
7
  const addEslint = async (projectName, flag) => {
8
8
  // 没有选择Eslint则直接返回
9
- if (!flag) return
9
+ if (!flag) return;
10
10
  // 路径
11
- const templateEslintPath = path.join(templatePath, 'eslint')
12
- const targetPath = path.join(process.cwd(), projectName)
13
- const targetPackageJsonPath = path.join(targetPath, 'package.json')
11
+ const templateEslintPath = path.join(templatePath, 'eslint');
12
+ const targetPath = path.join(process.cwd(), projectName);
13
+ const targetPackageJsonPath = path.join(targetPath, 'package.json');
14
14
 
15
15
  // 文件
16
16
  // 读取package.json文件
17
- const targetPkg = await fs.readJson(targetPackageJsonPath)
17
+ const targetPkg = await fs.readJson(targetPackageJsonPath);
18
18
  // 读取添加Eslint附加的package.json文件
19
- const eslintPkg = await fs.readJson(path.join(templateEslintPath, 'package.json'))
19
+ const eslintPkg = await fs.readJson(
20
+ path.join(templateEslintPath, 'package.json')
21
+ );
20
22
 
21
23
  targetPkg.devDependencies = {
22
24
  ...targetPkg.devDependencies,
23
25
  ...eslintPkg.devDependencies,
24
- }
26
+ };
25
27
 
26
28
  targetPkg.scripts = {
27
29
  ...targetPkg.scripts,
28
30
  ...eslintPkg.scripts,
29
- }
31
+ };
30
32
 
31
- await fs.writeJson(targetPackageJsonPath, targetPkg, { spaces: 2 })
33
+ await fs.writeJson(targetPackageJsonPath, targetPkg, { spaces: 2 });
34
+ };
32
35
 
33
- // 复制.eslintignore文件
34
- const eslintIgnorePath = path.join(templateEslintPath, '.eslintignore')
35
- const eslintIgnoreTargetPath = path.join(targetPath, '.eslintignore')
36
- fs.copy(eslintIgnorePath, eslintIgnoreTargetPath)
37
- }
38
-
39
- export default addEslint
36
+ export default addEslint;
@@ -1,19 +1,22 @@
1
1
  // 渲染eslint.config.js文件
2
2
  // 通过模板匹配prettier的选择情况
3
- import ejs from 'ejs'
4
- import { templatePath } from '#utils/URL.js'
5
- import fs from 'fs-extra'
6
- import path from 'path'
3
+ import ejs from 'ejs';
4
+ import { templatePath } from '#utils/URL.js';
5
+ import fs from 'fs-extra';
6
+ import path from 'path';
7
7
 
8
8
  const addEslintConfig = async (projectName, usePrettier, flag) => {
9
- if (!flag) return
9
+ if (!flag) return;
10
10
  await fs.writeFile(
11
11
  path.join(process.cwd(), projectName, 'eslint.config.js'),
12
12
  ejs.render(
13
- await fs.readFile(path.join(templatePath, 'eslint', 'eslint.config.js.ejs'), 'utf-8'),
14
- { usePrettier },
15
- ),
16
- )
17
- }
13
+ await fs.readFile(
14
+ path.join(templatePath, 'eslint', 'eslint.config.js.ejs'),
15
+ 'utf-8'
16
+ ),
17
+ { usePrettier }
18
+ )
19
+ );
20
+ };
18
21
 
19
- export default addEslintConfig
22
+ export default addEslintConfig;
@@ -1,25 +1,33 @@
1
1
  // 添加pinia功能
2
- import path from 'path'
3
- import fs from 'fs-extra'
4
- import { templatePath } from '#utils/URL.js'
2
+ import path from 'path';
3
+ import fs from 'fs-extra';
4
+ import { templatePath } from '#utils/URL.js';
5
5
 
6
6
  const addPinia = async (projectName, flag) => {
7
- if (!flag) return
8
- const targetPkg = fs.readJsonSync(path.join(process.cwd(), projectName, 'package.json'))
9
- const piniaPkg = fs.readJsonSync(path.join(templatePath, 'pinia', 'package.json'))
7
+ if (!flag) return;
8
+ const targetPkg = fs.readJsonSync(
9
+ path.join(process.cwd(), projectName, 'package.json')
10
+ );
11
+ const piniaPkg = fs.readJsonSync(
12
+ path.join(templatePath, 'pinia', 'package.json')
13
+ );
10
14
 
11
15
  // package.json的配置
12
16
  targetPkg.dependencies = {
13
17
  ...targetPkg.dependencies,
14
18
  ...piniaPkg.dependencies,
15
- }
19
+ };
16
20
 
17
- fs.writeJSONSync(path.join(process.cwd(), projectName, 'package.json'), targetPkg, { spaces: 2 })
21
+ fs.writeJSONSync(
22
+ path.join(process.cwd(), projectName, 'package.json'),
23
+ targetPkg,
24
+ { spaces: 2 }
25
+ );
18
26
 
19
27
  fs.copySync(
20
28
  path.join(templatePath, 'pinia', 'counter.js'),
21
- path.join(process.cwd(), projectName, 'src', 'stores', 'counter.js'),
22
- )
23
- }
29
+ path.join(process.cwd(), projectName, 'src', 'stores', 'counter.js')
30
+ );
31
+ };
24
32
 
25
- export default addPinia
33
+ export default addPinia;
@@ -1,27 +1,38 @@
1
1
  // 添加pinia自动持久化功能
2
- import fs from 'fs-extra'
3
- import path from 'path'
4
- import { templatePath } from '#utils/URL.js'
2
+ import fs from 'fs-extra';
3
+ import path from 'path';
4
+ import { templatePath } from '#utils/URL.js';
5
5
 
6
6
  const addPiniaPluginPersistedstate = async (projectName, flag) => {
7
- if (!flag) return
8
- const targetPkg = fs.readJsonSync(path.join(process.cwd(), projectName, 'package.json'))
7
+ if (!flag) return;
8
+ const targetPkg = fs.readJsonSync(
9
+ path.join(process.cwd(), projectName, 'package.json')
10
+ );
9
11
  const persistPkg = fs.readJsonSync(
10
- path.join(templatePath, 'pinia', 'pinia-plugin-persistedstate', 'package.json'),
11
- )
12
+ path.join(
13
+ templatePath,
14
+ 'pinia',
15
+ 'pinia-plugin-persistedstate',
16
+ 'package.json'
17
+ )
18
+ );
12
19
 
13
20
  // package.json的配置
14
21
  targetPkg.dependencies = {
15
22
  ...targetPkg.dependencies,
16
23
  ...persistPkg.dependencies,
17
- }
24
+ };
18
25
 
19
- fs.writeJSONSync(path.join(process.cwd(), projectName, 'package.json'), targetPkg, { spaces: 2 })
26
+ fs.writeJSONSync(
27
+ path.join(process.cwd(), projectName, 'package.json'),
28
+ targetPkg,
29
+ { spaces: 2 }
30
+ );
20
31
 
21
32
  fs.copySync(
22
33
  path.join(templatePath, 'pinia', 'pinia-plugin-persistedstate', 'key.js'),
23
- path.join(process.cwd(), projectName, 'src', 'stores', 'key.js'),
24
- )
25
- }
34
+ path.join(process.cwd(), projectName, 'src', 'stores', 'key.js')
35
+ );
36
+ };
26
37
 
27
- export default addPiniaPluginPersistedstate
38
+ export default addPiniaPluginPersistedstate;
@@ -1,38 +1,37 @@
1
- import { templatePath } from '../URL.js'
2
- import path from 'path'
3
- import fs from 'fs-extra'
1
+ import { templatePath } from '../URL.js';
2
+ import path from 'path';
3
+ import fs from 'fs-extra';
4
4
 
5
5
  const addPrettier = async (projectName, flag) => {
6
6
  // 没有选择Prettier则直接返回
7
- if (!flag) return
7
+ if (!flag) return;
8
8
  // 路径
9
- const templatePrettierPath = path.join(templatePath, 'prettier')
10
- const targetPath = path.join(process.cwd(), projectName)
11
- const targetPackageJsonPath = path.join(targetPath, 'package.json')
9
+ const templatePrettierPath = path.join(templatePath, 'prettier');
10
+ const targetPath = path.join(process.cwd(), projectName);
11
+ const targetPackageJsonPath = path.join(targetPath, 'package.json');
12
12
 
13
13
  // 文件
14
- const targetPkg = await fs.readJson(targetPackageJsonPath)
15
- const prettierPkg = await fs.readJson(path.join(templatePrettierPath, 'package.json'))
14
+ const targetPkg = await fs.readJson(targetPackageJsonPath);
15
+ const prettierPkg = await fs.readJson(
16
+ path.join(templatePrettierPath, 'package.json')
17
+ );
16
18
 
17
19
  // 添加package.json的内容
18
20
  targetPkg.scripts = {
19
21
  ...targetPkg.scripts,
20
22
  ...prettierPkg.scripts,
21
- }
23
+ };
22
24
 
23
25
  targetPkg.devDependencies = {
24
26
  ...targetPkg.devDependencies,
25
27
  ...prettierPkg.devDependencies,
26
- }
28
+ };
27
29
 
28
- await fs.writeJson(targetPackageJsonPath, targetPkg, { spaces: 2 })
30
+ await fs.writeJson(targetPackageJsonPath, targetPkg, { spaces: 2 });
29
31
 
30
- // 复制.prettierignore文件
31
- const prettierignorePath = path.join(templatePrettierPath, '.prettierignore')
32
- fs.copy(prettierignorePath, path.join(targetPath, '.prettierignore'))
33
- // 复制.prettierrc.js文件
34
- const prettierrc = path.join(templatePrettierPath, '.prettierrc')
35
- fs.copy(prettierrc, path.join(targetPath, '.prettierrc.js'))
36
- }
32
+ // 复制.prettierrc文件
33
+ const prettierrc = path.join(templatePrettierPath, '.prettierrc');
34
+ fs.copy(prettierrc, path.join(targetPath, '.prettierrc'));
35
+ };
37
36
 
38
- export default addPrettier
37
+ export default addPrettier;
@@ -0,0 +1,29 @@
1
+ import ejs from 'ejs';
2
+ import { templatePath } from '#utils/URL.js';
3
+ import fs from 'fs-extra';
4
+ import path from 'path';
5
+
6
+ const addAboutView = async (
7
+ projectName,
8
+ usePiniaPluginPersistedstate,
9
+ useVueRouter
10
+ ) => {
11
+ if (!useVueRouter) return;
12
+ await fs.writeFile(
13
+ path.join(process.cwd(), projectName, 'src', 'views', 'AboutView.vue'),
14
+ ejs.render(
15
+ await fs.readFile(
16
+ path.join(templatePath, 'vue-router', 'views', 'AboutView.vue.ejs'),
17
+ 'utf-8'
18
+ ),
19
+ {
20
+ usePiniaPluginPersistedstate,
21
+ }
22
+ )
23
+ );
24
+ await fs.remove(
25
+ path.join(process.cwd(), projectName, 'src', 'AboutView.vue.ejs')
26
+ );
27
+ };
28
+
29
+ export default addAboutView;
@@ -0,0 +1,46 @@
1
+ import { templatePath } from '../../URL.js';
2
+ import path from 'path';
3
+ import fs from 'fs-extra';
4
+
5
+ const addVueRouter = async (projectName, flag) => {
6
+ // 没有选择vueRouter则直接返回
7
+ if (!flag) return;
8
+ // 路径
9
+ const templateVueRouterPath = path.join(templatePath, 'vue-router');
10
+ const targetPath = path.join(process.cwd(), projectName);
11
+ const targetSrcPath = path.join(targetPath, 'src');
12
+ const targetPackageJsonPath = path.join(targetPath, 'package.json');
13
+
14
+ // 文件
15
+ const targetPkg = await fs.readJson(targetPackageJsonPath);
16
+ const vueRouterPkg = await fs.readJson(
17
+ path.join(templateVueRouterPath, 'package.json')
18
+ );
19
+
20
+ // 添加package.json的内容
21
+ targetPkg.dependencies = {
22
+ ...targetPkg.dependencies,
23
+ ...vueRouterPkg.dependencies,
24
+ };
25
+
26
+ await fs.writeJson(targetPackageJsonPath, targetPkg, { spaces: 2 });
27
+
28
+ // 复制components文件
29
+ fs.copySync(
30
+ path.join(templateVueRouterPath, 'components'),
31
+ path.join(targetSrcPath, 'components'),
32
+ { overwrite: false }
33
+ );
34
+ // 复制router文件
35
+ fs.copySync(
36
+ path.join(templateVueRouterPath, 'router'),
37
+ path.join(targetSrcPath, 'router')
38
+ );
39
+ // 复制views文件
40
+ fs.copySync(
41
+ path.join(templateVueRouterPath, 'views'),
42
+ path.join(targetSrcPath, 'views')
43
+ );
44
+ };
45
+
46
+ export default addVueRouter;
package/eslint.config.mjs DELETED
@@ -1,27 +0,0 @@
1
- import js from '@eslint/js'
2
- import globals from 'globals'
3
- import json from '@eslint/json'
4
- import { defineConfig } from 'eslint/config'
5
- import prettierPlugin from 'eslint-plugin-prettier'
6
-
7
- export default defineConfig([
8
- {
9
- files: ['**/*.{js,mjs,cjs}'],
10
- plugins: { js, prettier: prettierPlugin },
11
- extends: ['js/recommended'],
12
- languageOptions: { globals: globals.node },
13
- rules: {
14
- 'prettier/prettier': [
15
- 'warn',
16
- {
17
- $schema: 'https://json.schemastore.org/prettierrc',
18
- semi: false,
19
- singleQuote: true,
20
- printWidth: 100,
21
- endOfLine: 'auto',
22
- },
23
- ],
24
- },
25
- },
26
- { files: ['**/*.json'], plugins: { json }, language: 'json/json', extends: ['json/recommended'] },
27
- ])
@@ -1,36 +0,0 @@
1
- # 依赖包
2
- node_modules/
3
-
4
- # 构建产物 (Build Outputs)
5
- dist/
6
- build/
7
- out/
8
- .next/
9
- .nuxt/
10
-
11
- # 测试覆盖率报告
12
- coverage/
13
-
14
- # 静态资源 (通常不检查图片、字体或视频)
15
- public/
16
- assets/
17
-
18
- # 配置文件
19
- .cache/
20
- .temp/
21
- .tmp/
22
-
23
- # 库文件或压缩后的文件
24
- *.min.js
25
- *.bundle.js
26
-
27
- # 锁文件 (虽然通常是 json/yaml,但最好排除)
28
- package-lock.json
29
- yarn.lock
30
- pnpm-lock.yaml
31
-
32
- # 本地环境变量文件
33
- .env*
34
-
35
- # 流程图或文档生成工具产物
36
- docs/.vitepress/dist
@@ -1,7 +0,0 @@
1
- # .prettierignore
2
- node_modules
3
- dist
4
- build
5
- coverage
6
- package-lock.json
7
- *.min.js
@@ -1,3 +0,0 @@
1
- {
2
- "recommendations": ["Vue.volar"]
3
- }