Skip to content

Commit 88afe04

Browse files
committed
feat: pinia
1 parent 4e66092 commit 88afe04

File tree

8 files changed

+70
-2
lines changed

8 files changed

+70
-2
lines changed

index.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ type Result = {
9898
shouldOverwrite?: boolean
9999
packageName?: string
100100
needsTypeScript?: boolean
101+
needsPinia?: boolean
101102
needsVitest?: boolean
102103
needsEslint?: boolean
103104
needsStylelint?: boolean
@@ -137,7 +138,7 @@ function renderTemplate(
137138
let content = ejs.render(template, result)
138139

139140
if (filename === 'package.json.ejs') {
140-
content = content.replace(',\n trailing-comma', '')
141+
content = content.replaceAll(',\n trailing-comma', '')
141142
}
142143

143144
fs.writeFileSync(dest.replace(/\.ejs$/, ''), content)
@@ -330,6 +331,14 @@ async function init() {
330331
active: '是',
331332
inactive: '否',
332333
},
334+
{
335+
name: 'needsPinia',
336+
type: 'toggle',
337+
message: '是否引入 Pinia 用于状态管理?(试验)',
338+
initial: false,
339+
active: '是',
340+
inactive: '否',
341+
},
333342
{
334343
name: 'needsVitest',
335344
type: 'toggle',
@@ -383,6 +392,7 @@ async function init() {
383392
shouldOverwrite = false,
384393
packageName = projectName ?? defaultProjectName,
385394
needsTypeScript = false,
395+
needsPinia = false,
386396
needsVitest = false,
387397
needsEslint = false,
388398
needsStylelint = false,
@@ -414,6 +424,7 @@ async function init() {
414424
renderTemplate(path.resolve(templateRoot, templateName), root, {
415425
packageName,
416426
needsTypeScript,
427+
needsPinia,
417428
needsVitest,
418429
needsEslint,
419430
needsStylelint,
@@ -433,6 +444,14 @@ async function init() {
433444
render('javascript')
434445
}
435446

447+
if (needsPinia) {
448+
if (needsTypeScript) {
449+
render('pinia-typescript')
450+
} else {
451+
render('pinia')
452+
}
453+
}
454+
436455
if (needsEslint) {
437456
render('eslint')
438457
}
@@ -464,6 +483,7 @@ async function init() {
464483
packageManager,
465484
projectName: projectName ?? packageName ?? defaultProjectName,
466485
needsTypeScript,
486+
needsPinia,
467487
needsVitest,
468488
needsEslint,
469489
needsStylelint,

template/base/package.json.ejs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
},
3131
"dependencies": {
3232
"@babel/runtime": "^7.27.0",
33-
"@vue-mini/core": "^1.2.2"
33+
"@vue-mini/core": "^1.2.2",
34+
<%_ if (needsPinia) { _%>
35+
"@vue-mini/pinia": "^0.1.2",
36+
<%_ } _%>
37+
trailing-comma
3438
},
3539
"devDependencies": {
3640
"@babel/core": "^7.26.10",

template/pinia-typescript/src/app.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createApp } from '@vue-mini/core';
2+
import './pinia';
3+
4+
createApp(() => {
5+
console.log('App Launched!');
6+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createPinia } from '@vue-mini/pinia';
2+
3+
export const pinia = createPinia();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ref, computed } from '@vue-mini/core';
2+
import { defineStore } from '@vue-mini/pinia';
3+
4+
export const useCountStore = defineStore('count', () => {
5+
const count = ref(0);
6+
const double = computed(() => count.value * 2);
7+
8+
const increment = () => {
9+
count.value++;
10+
};
11+
12+
return { count, double, increment };
13+
});

template/pinia/src/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { createApp } from '@vue-mini/core';
2+
import './pinia';
3+
4+
createApp(() => {
5+
console.log('App Launched!');
6+
});

template/pinia/src/pinia.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { createPinia } from '@vue-mini/pinia';
2+
3+
export const pinia = createPinia();

template/pinia/src/stores/count.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { ref, computed } from '@vue-mini/core';
2+
import { defineStore } from '@vue-mini/pinia';
3+
4+
export const useCountStore = defineStore('count', () => {
5+
const count = ref(0);
6+
const double = computed(() => count.value * 2);
7+
8+
const increment = () => {
9+
count.value++;
10+
};
11+
12+
return { count, double, increment };
13+
});

0 commit comments

Comments
 (0)