Skip to content

Commit

Permalink
Merge pull request #20 from biaov/release/v1.6.0
Browse files Browse the repository at this point in the history
更新代码
  • Loading branch information
biaov authored Jul 24, 2024
2 parents b53efb9 + a7e2e7e commit daae3d6
Show file tree
Hide file tree
Showing 8 changed files with 828 additions and 1,331 deletions.
6 changes: 6 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 默认模板仓库地址
# 其它模板地址: https://github.com/biaov/project-template.git
VITE_TEMPLATE_GIT_URL='https://gitee.com/biaovorg/project-template.git'

# VSCode 配置仓库地址
VITE_VSCODE_GIT_URL='https://gitee.com/biaovorg/vscode-config.git#master'
2,095 changes: 780 additions & 1,315 deletions package-lock.json

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-mine",
"private": false,
"version": "1.5.2",
"version": "1.6.0",
"exports": "./dist/index.js",
"main": "./dist/index.js",
"type": "module",
Expand Down Expand Up @@ -56,16 +56,16 @@
"chalk": "^5.3.0",
"commander": "^12.1.0",
"download-git-repo": "^3.0.2",
"inquirer": "^9.2.22",
"inquirer": "^10.1.2",
"log-symbols": "^6.0.0",
"ora": "^8.0.1",
"update-notifier": "^7.0.0"
"update-notifier": "^7.1.0"
},
"devDependencies": {
"@types/node": "^20.12.12",
"@types/node": "^20.14.12",
"@types/update-notifier": "^6.0.8",
"prettier": "^3.2.5",
"typescript": "^5.4.5",
"vite": "^5.2.11"
"prettier": "^3.3.3",
"typescript": "^5.5.4",
"vite": "^5.3.4"
}
}
4 changes: 3 additions & 1 deletion src/commander/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import log from '@/utils/log' // 日志
import { templateUrls, templateNames, installTools, toolCommands } from '@/config' // 全局变量
import { SavePresetInfo, GetPresetInfo, FormatePreset } from '@/utils/functions' // 全局方法
import { version } from '@/../package.json' // 包信息
import { PresetInfo, Template } from './types'
import { downloadVSCodeConfig } from './vscode'
import type { PresetInfo, Template } from './types'

const { iconError, iconSuccess, success, info, error, warning } = log
const { yellow, red, blueBright, cyanBright } = chalk
Expand Down Expand Up @@ -203,6 +204,7 @@ export const DownLibrary = ({ installTool, projectName, template }: PresetInfo)

spinner.succeed('模板下载成功')
info()
downloadVSCodeConfig({ projectName })
spinner.start(`>> 正在安装依赖插件,可能要等一会...`)
const { install, start } = toolCommands[installTool]
exec(install, { cwd: processCwd }, err => {
Expand Down
9 changes: 9 additions & 0 deletions src/commander/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ export interface PresetInfo extends Template {
projectName: string
installTool: InstallToolKey
}

/**
* 方法 downloadVSCodeConfig
*/
export namespace DownloadVSCodeConfig {
export interface Option {
projectName: string
}
}
21 changes: 21 additions & 0 deletions src/commander/vscode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import download from 'download-git-repo' // 用于下载项目模板
import { cpSync, rmSync } from 'fs' // 读写文件
import { join } from 'path'
import type { DownloadVSCodeConfig } from './types'

const fileOption = { recursive: true, force: true }

/**
* 下载 vscode 配置文件
*/
export const downloadVSCodeConfig = ({ projectName }: DownloadVSCodeConfig.Option) => {
const tempFileName = `${+new Date()}`
const processCwd = `${process.cwd()}\\${projectName}\\${tempFileName}`
const projectPath = join(process.cwd(), projectName)
const tempPath = join(projectPath, tempFileName)

download(`direct:${import.meta.env.VITE_VSCODE_GIT_URL}`, tempPath, { clone: true }, async (err: Error): Promise<void> => {
!err && cpSync(join(tempPath, '.vscode'), join(projectPath, '.vscode'), fileOption)
rmSync(tempPath, fileOption)
})
}
8 changes: 1 addition & 7 deletions src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
/**
* 默认的模板地址,也可以配置其它模板地址
* 其它模板地址: https://github.com/biaov/project-template.git
*/
const defaultTemplateUrl = 'https://gitee.com/biaovorg/project-template.git'

/**
* 模板预设
* [模板下载地址]: [模板名称, ...]
*/
const templatePresets = {
[defaultTemplateUrl]: ['vue', 'react', 'uni-app', 'electron', 'node', 'cli']
[import.meta.env.VITE_TEMPLATE_GIT_URL]: ['vue', 'react', 'uni-app', 'electron', 'node', 'cli']
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"isolatedModules": true,
"esModuleInterop": true,
"lib": ["esnext"],
"types": ["node"],
"types": ["vite/client", "node"],
"skipLibCheck": true,
"baseUrl": "./",

Expand Down

0 comments on commit daae3d6

Please sign in to comment.