create-vite-uniapp 0.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.
@@ -0,0 +1,24 @@
1
+ import path from 'node:path';
2
+ import fs from 'fs-extra';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { getProjectInfo } from '../prompts.js';
5
+ import { log } from '../utils/logger.js';
6
+ const templatesDir = fileURLToPath(new URL('../../templates', import.meta.url));
7
+ export async function createProject(name, options) {
8
+ const result = await getProjectInfo(name);
9
+ const projectName = result.name;
10
+ const template = options?.template || result.template;
11
+ const targetDir = path.resolve(process.cwd(), projectName);
12
+ const templateDir = path.resolve(templatesDir, template);
13
+ if (!fs.existsSync(templateDir)) {
14
+ log.error(`Template "${template}" not found.`);
15
+ process.exit(1);
16
+ }
17
+ log.info(`Creating project in ${projectName}...`);
18
+ fs.copySync(templateDir, targetDir);
19
+ const gitignore = path.join(targetDir, '_gitignore');
20
+ if (fs.existsSync(gitignore)) {
21
+ fs.renameSync(gitignore, path.join(targetDir, '.gitignore'));
22
+ }
23
+ log.success('Project created successfully 🎉');
24
+ }
package/dist/cli.js ADDED
@@ -0,0 +1,15 @@
1
+ import { cac } from 'cac';
2
+ import { version } from './utils/pkg.js';
3
+ import { createProject } from './actions/create.js';
4
+ const cli = cac('create-uniapp');
5
+ export function run() {
6
+ cli
7
+ .command('[project-name]', 'Create a new UniApp project')
8
+ .option('--template <template>', 'Template name')
9
+ .action((name, options) => {
10
+ createProject(name, options);
11
+ });
12
+ cli.version(version);
13
+ cli.help();
14
+ cli.parse();
15
+ }
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { run } from './cli.js';
3
+ run();
@@ -0,0 +1,20 @@
1
+ import prompts from 'prompts';
2
+ export async function getProjectInfo(defaultName) {
3
+ return prompts([
4
+ {
5
+ type: 'text',
6
+ name: 'name',
7
+ message: 'Project name:',
8
+ initial: defaultName || 'uniapp-project'
9
+ },
10
+ {
11
+ type: 'select',
12
+ name: 'template',
13
+ message: 'Select a template:',
14
+ choices: [
15
+ { title: 'Vue3 + JavaScript', value: 'vue3-js' },
16
+ { title: 'Vue3 + TypeScript', value: 'vue3-ts' }
17
+ ]
18
+ }
19
+ ]);
20
+ }
@@ -0,0 +1,6 @@
1
+ import { green, red, blue } from 'kolorist';
2
+ export const log = {
3
+ info: (msg) => console.log(blue(msg)),
4
+ success: (msg) => console.log(green(msg)),
5
+ error: (msg) => console.log(red(msg))
6
+ };
@@ -0,0 +1,5 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import path from 'node:path';
4
+ const pkgPath = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../../package.json');
5
+ export const { version } = JSON.parse(readFileSync(pkgPath, 'utf-8'));
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "create-vite-uniapp",
3
+ "version": "0.1.0",
4
+ "description": "A fast CLI to bootstrap production-ready Uniapp projects.",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-uniapp": "dist/index.js"
8
+ },
9
+ "exports": {
10
+ ".": "./dist/index.js"
11
+ },
12
+ "files": [
13
+ "dist",
14
+ "templates"
15
+ ],
16
+ "engines": {
17
+ "node": ">=18"
18
+ },
19
+ "scripts": {
20
+ "dev": "tsx src/index.ts",
21
+ "build": "tsc"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/zeMinng/create-uniapp.git"
26
+ },
27
+ "keywords": [
28
+ "create-uniapp",
29
+ "uniapp",
30
+ "vue",
31
+ "vite",
32
+ "cli",
33
+ "scaffold",
34
+ "boilerplate",
35
+ "template"
36
+ ],
37
+ "author": "zeMinng",
38
+ "license": "MIT",
39
+ "devDependencies": {
40
+ "@types/fs-extra": "^11.0.4",
41
+ "@types/node": "^25.0.3",
42
+ "@types/prompts": "^2.4.9",
43
+ "tsx": "^4.21.0",
44
+ "typescript": "^5.9.3"
45
+ },
46
+ "dependencies": {
47
+ "cac": "^6.7.14",
48
+ "fs-extra": "^11.3.3",
49
+ "kolorist": "^1.8.0",
50
+ "prompts": "^2.4.2"
51
+ }
52
+ }
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>UniApp Vue3 TS</title>
6
+ </head>
7
+ <body>
8
+ <div id="app"></div>
9
+ <script type="module" src="/src/main.ts"></script>
10
+ </body>
11
+ </html>
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "uniapp-project",
3
+ "private": true,
4
+ "scripts": {
5
+ "dev": "vite",
6
+ "build": "vite build"
7
+ },
8
+ "dependencies": {
9
+ "vue": "^3.4.0"
10
+ },
11
+ "devDependencies": {
12
+ "@vitejs/plugin-vue": "^5.0.0",
13
+ "typescript": "^5.4.0",
14
+ "vite": "^5.0.0"
15
+ }
16
+ }
@@ -0,0 +1,10 @@
1
+ <template>
2
+ <view class="app">
3
+ <h1>UniApp Vue3 + TypeScript</h1>
4
+ <pages-index />
5
+ </view>
6
+ </template>
7
+
8
+ <script setup lang="ts">
9
+ import PagesIndex from './pages/index/index.vue'
10
+ </script>
@@ -0,0 +1,4 @@
1
+ import { createApp } from 'vue'
2
+ import App from './App.vue'
3
+
4
+ createApp(App).mount('#app')
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <view>
3
+ <p>Hello UniApp 👋</p>
4
+ </view>
5
+ </template>
6
+
7
+ <script setup lang="ts"></script>
@@ -0,0 +1,10 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ESNext",
4
+ "module": "ESNext",
5
+ "moduleResolution": "Bundler",
6
+ "strict": true,
7
+ "jsx": "preserve",
8
+ "skipLibCheck": true
9
+ }
10
+ }
@@ -0,0 +1,6 @@
1
+ import { defineConfig } from 'vite'
2
+ import vue from '@vitejs/plugin-vue'
3
+
4
+ export default defineConfig({
5
+ plugins: [vue()]
6
+ })