Skip to content

Commit

Permalink
feat: pakName
Browse files Browse the repository at this point in the history
  • Loading branch information
FliPPeDround committed Jul 3, 2023
1 parent d84bad1 commit d886f38
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 8 deletions.
34 changes: 33 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ async function init() {
else if (!existsSync(root))
mkdirSync(root)

if (result.projectName) {
const pkg = {
name: result.projectName.toLocaleLowerCase().replace(/\s/g, '-'),
version: '0.0.0',
}
writeFileSync(
resolve(root, 'package.json'),
JSON.stringify(pkg, null, 2),
)
}

if (result.templateType!.type !== 'custom') {
await dowloadTemplate(result.templateType!.url, root)
return
Expand All @@ -74,6 +85,22 @@ async function init() {

render('base')

if (result.needsJsx)
render('config/jsx')

if (result.needsPinia)
render('config/pinia')
if (result.needsVitest)
render('config/vitest')

if (result.needsTypeScript) {
render('config/typescript')
render('tsconfig/base')

if (result.needsVitest)
render('tsconfig/vitest')
}

const dataStore: Record<string, any> = {}
// Process callbacks
for (const cb of callbacks)
Expand Down Expand Up @@ -137,4 +164,9 @@ async function init() {
}
}

init()
try {
await init()
}
catch {
process.exit(1)
}
15 changes: 15 additions & 0 deletions src/template/base/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.4"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",
"vite": "^4.3.9"
}
}
6 changes: 1 addition & 5 deletions src/template/config/jsx/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
{
"dependencies": {
"vue": "^3.3.4"
},
"devDependencies": {
"@vitejs/plugin-vue-jsx": "^3.0.1",
"vite": "^4.3.9"
"@vitejs/plugin-vue-jsx": "^3.0.1"
}
}
15 changes: 15 additions & 0 deletions src/template/config/jsx/vite.config.js.data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default function getData({ oldData }) {
const vueJsxPlugin = {
name: 'vueJsx',
importer: 'import vueJsx from \'@vitejs/plugin-vue-jsx\'',
initializer: 'vueJsx()',
}

return {
...oldData,
// Append the vueJsx plugin right after the vue plugin
plugins: oldData.plugins.flatMap(plugin =>
plugin.id === 'uni' ? [plugin, vueJsxPlugin] : plugin,
),
}
}
3 changes: 1 addition & 2 deletions src/template/config/pinia/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"pinia": "^2.1.3",
"vue": "^3.3.4"
"pinia": "^2.1.3"
}
}
1 change: 1 addition & 0 deletions src/template/config/typescript/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
11 changes: 11 additions & 0 deletions src/template/config/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"scripts": {
"type-check": "vue-tsc --noEmit -p tsconfig.app.json --composite false"
},
"devDependencies": {
"@dcloudio/types": "^3.3.3",
"@types/node": "^18.16.17",
"typescript": "~5.0.4",
"vue-tsc": "^1.6.5"
}
}

0 comments on commit d886f38

Please sign in to comment.