Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/cli/src/getTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Task = { dir: string; script: string; manifest: BaseManifest };
export async function getTaskList(taskNames: string[]): Promise<Task[][]> {
const packages: Package[] = [];

for await (const filePath of glob("{apps,packages}/*/package.json", { cwd })) {
for await (const filePath of glob(["package.json", "{apps,packages}/*/package.json"], { cwd })) {
const absPath = join(cwd, filePath);
const { default: manifest } = await import(absPath, { with: { type: "json" } });
packages.push({ rootDir: dirname(absPath), manifest });
Expand All @@ -29,7 +29,10 @@ export async function getTaskList(taskNames: string[]): Promise<Task[][]> {
dirs.flatMap(dir =>
taskNames.flatMap(task => {
const manifest = graph[dir].package.manifest;
if (manifest?.scripts && task in manifest.scripts) return { dir, script: manifest.scripts[task], manifest };
if (manifest?.scripts && task in manifest.scripts) {
const script = manifest.scripts[task];
if (!script.includes("vite-plus")) return { dir, script, manifest };
}
return [];
})
)
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/runTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join } from "node:path";
import { parseArgs } from "node:util";
import { multiplex, type Command } from "multiplexer";
import { getTaskList } from "./getTasks.ts";
import { spawn } from "node:child_process";

export async function runTasks(): Promise<void> {
const { positionals } = parseArgs({ allowPositionals: true });
Expand All @@ -28,6 +29,9 @@ export async function runTasks(): Promise<void> {
);
}

multiplex(commands);
const all = commands.flat();
if (all.length > 1) multiplex(commands);
else if (all.length === 1) spawn(all[0].cmd, all[0].args, { stdio: "inherit" });
else console.error("404 Task Not Found");
}
}
4 changes: 4 additions & 0 deletions packages/global/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@
},
"engines": {
"node": ">=20.11.0"
},
"dependencies": {
"@clack/core": "^0.5.0",
"@clack/prompts": "^0.11.0"
}
}
16 changes: 11 additions & 5 deletions packages/global/src/command/new.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { cp } from "node:fs/promises";
import { cp, readdir } from "node:fs/promises";
import { join } from "node:path";

export default async function copyTemplateFiles(targetDir: string) {
await copyFiles(targetDir);
const templatesDir = join(import.meta.dirname, "../../templates");

export async function getAvailableTemplates(): Promise<string[]> {
const dirs = await readdir(templatesDir);
return dirs;
}

export async function copyTemplateFiles(templateDir: string, targetDir: string): Promise<void> {
await copyFiles(templateDir, targetDir);
}

async function copyFiles(targetDir: string) {
const templateDir = join(import.meta.dirname, "../../template");
async function copyFiles(templateDir: string, targetDir: string): Promise<void> {
await cp(templateDir, targetDir, { force: true, recursive: true });
}
70 changes: 70 additions & 0 deletions packages/global/src/command/tasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { join } from "node:path";
import { spawn } from "node:child_process";
import { intro, select, outro, text, confirm, tasks } from "@clack/prompts";
import { getAvailableTemplates, copyTemplateFiles } from "./new.ts";

export const questionnaire = async (): Promise<void> => {
intro("Let's create a new Vite+ project");

const availableTemplates = await getAvailableTemplates();

const targetDir = await text({
message: "Where should we create your project?",
placeholder: "./",
initialValue: "./",
validate(value) {
if (!value || value.startsWith("..") || !value.startsWith(".")) return "Please enter a relative path";
}
});

const isUseTypeScript = await select({
message: "Do you plan to use TypeScript?",
options: [
{ value: "ts", label: "TypeScript" },
{ value: "js", label: "JavaScript with JSDoc" }
]
});

const templateDir = await select({
message: "Please choose a project template",
options: availableTemplates.map(template => ({
value: template,
label: template
}))
});

const isInstallDependencies = await confirm({
message: "Do you want to install dependencies?",
initialValue: true
});

const t = [
{
title: "Copying template files",
task: async () => {
const sourceTemplateDir = join(import.meta.dirname, "../../templates", templateDir);
const targetDirPath = join(process.cwd(), targetDir);
await copyTemplateFiles(sourceTemplateDir, targetDirPath);
return "Copied template files";
}
}
];

if (isInstallDependencies) {
t.push({
title: "Installing dependencies",
task: async () => {
await new Promise(resolve => {
const targetDirPath = join(process.cwd(), targetDir);
const p = spawn("pnpm", ["install"], { cwd: targetDirPath });
p.on("exit", resolve);
});
return "Installed dependencies using pnpm";
}
});
}

await tasks(t);

outro("Enjoy Vite+");
};
9 changes: 3 additions & 6 deletions packages/global/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { execFileSync } from "node:child_process";
import { parseArgs } from "node:util";
import copyTemplateFiles from "./command/new.ts";
import { join } from "node:path";
import { questionnaire } from "./command/tasks.ts";

try {
const { positionals } = parseArgs({ allowPositionals: true });

const [command, dir] = positionals;
const [command] = positionals;

if (command === "new") {
const targetDir = dir ?? process.cwd();
await copyTemplateFiles(targetDir);
execFileSync("pnpm", ["install"], { stdio: "inherit" });
await questionnaire();
} else {
const { default: main } = await import(join(process.cwd(), "node_modules/vite-plus/dist/index.js"));
main();
Expand Down
5 changes: 5 additions & 0 deletions packages/global/templates/minimal-js/.oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rules": {
"no-eval": "error"
}
}
29 changes: 29 additions & 0 deletions packages/global/templates/minimal-js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "vite-plus-template-minimal-js",
"private": true,
"version": "0.0.0",
"type": "module",
"main": "src/index.js",
".": {
"types": "dist/index.d.ts",
"default": "src/index.js"
},
"scripts": {
"build": "tsc --build --verbose",
"dev": "vite",
"lint": "oxlint",
"all": "vite-plus task build lint"
},
"dependencies": {
"vite": "^7.0.0"
},
"devDependencies": {
"@types/node": "^24.0.4",
"multiplexer": "^0.0.0",
"oxlint": "^1.3.0",
"tsdown": "^0.12.8",
"typescript": "^5.8.3",
"vite-plus": "^0.0.0"
},
"packageManager": "pnpm@10.12.1"
}
11 changes: 11 additions & 0 deletions packages/global/templates/minimal-js/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Greetings earthlings, we have not taken over your radiooooo 🎶
*
* @param {string} name
* @returns {string}
*/
export const greet = name => {
return `Hello, ${name}!`;
};

console.log(greet("World"));
21 changes: 21 additions & 0 deletions packages/global/templates/minimal-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"lib": ["esnext", "dom", "dom.iterable"],
"module": "esnext",
"moduleResolution": "bundler",
"noEmitOnError": true,
"noErrorTruncation": true,
"outDir": "dist",
"resolveJsonModule": true,
"strict": true,
"target": "esnext",
"types": ["node"],
"verbatimModuleSyntax": true
},
"include": ["src"]
}
2 changes: 2 additions & 0 deletions packages/global/templates/minimal/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=http://localhost:4873
//localhost:4873/:_authToken=fake
1 change: 1 addition & 0 deletions packages/global/templates/minimal/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script type="module" src="./src/index.ts"></script>
28 changes: 28 additions & 0 deletions packages/global/templates/minimal/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "vite-plus-template-minimal-js",
"private": true,
"version": "0.0.0",
"type": "module",
".": {
"types": "dist/index.d.ts",
"default": "dist/index.js"
},
"scripts": {
"build": "tsc --build --verbose",
"dev": "vite",
"lint": "oxlint",
"all": "vite-plus task build lint"
},
"dependencies": {
"vite": "^7.0.0"
},
"devDependencies": {
"@types/node": "^24.0.4",
"multiplexer": "^0.0.0",
"oxlint": "^1.3.0",
"tsdown": "^0.12.8",
"typescript": "^5.8.3",
"vite-plus": "^0.0.0"
},
"packageManager": "pnpm@10.12.1"
}
1 change: 1 addition & 0 deletions packages/global/templates/minimal/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello, world!");
17 changes: 17 additions & 0 deletions packages/global/templates/minimal/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"lib": ["esnext", "dom", "dom.iterable"],
"module": "esnext",
"moduleResolution": "bundler",
"noEmitOnError": true,
"noErrorTruncation": true,
"outDir": "dist",
"resolveJsonModule": true,
"strict": true,
"target": "esnext",
"types": ["node"],
"verbatimModuleSyntax": true
},
"include": ["src"]
}
2 changes: 2 additions & 0 deletions packages/global/templates/monorepo/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registry=http://localhost:4873
//localhost:4873/:_authToken=fake
1 change: 1 addition & 0 deletions packages/global/templates/monorepo/apps/spa/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<script type="module" src="./src/index.js"></script>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "my-vite-plus-monorepo",
"name": "vite-plus-template-monorepo",
"private": true,
"version": "0.0.0",
"type": "module",
Expand Down
33 changes: 31 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.