create-template-project 0.2.0 → 0.3.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.
- package/README.md +3 -3
- package/dist/config/dependencies.json +10 -14
- package/dist/index.js +1221 -0
- package/dist/templates/base/files/.husky/commit-msg +1 -0
- package/dist/templates/base/files/.husky/pre-commit +1 -0
- package/dist/templates/base/files/.prettierignore +3 -0
- package/dist/templates/base/files/package.json +1 -1
- package/dist/templates/base/files/vitest.config.ts +10 -1
- package/dist/templates/cli/files/package.json +4 -3
- package/dist/templates/cli/files/src/index.test.ts +10 -2
- package/dist/templates/cli/files/src/index.ts +4 -1
- package/dist/templates/cli/files/src/lib.ts +10 -0
- package/dist/templates/cli/files/vite.config.ts +22 -0
- package/dist/templates/web-app/files/src/App.test.tsx +9 -0
- package/dist/templates/web-app/files/src/App.tsx +14 -0
- package/dist/templates/web-app/files/src/index.tsx +1 -14
- package/dist/templates/web-app/files/vite.config.ts +4 -0
- package/dist/templates/web-fullstack/files/client/src/App.test.tsx +5 -2
- package/dist/templates/web-fullstack/files/client/vite.config.ts +4 -0
- package/dist/templates/web-fullstack/files/package.json +1 -2
- package/dist/templates/web-fullstack/files/server/src/index.test.ts +24 -3
- package/dist/templates/web-fullstack/files/server/src/trpc.ts +1 -1
- package/dist/templates/web-fullstack/files/server/vite.config.ts +6 -3
- package/dist/templates/web-vanilla/files/index.html +1 -1
- package/dist/templates/web-vanilla/files/src/index.test.ts +9 -2
- package/dist/templates/web-vanilla/files/src/index.ts +3 -1
- package/dist/templates/web-vanilla/files/src/lib.ts +9 -0
- package/dist/templates/web-vanilla/files/vite.config.ts +4 -0
- package/package.json +13 -18
- package/dist/cli.mjs +0 -308
- package/dist/generators/info.mjs +0 -58
- package/dist/generators/project.mjs +0 -387
- package/dist/index.d.mts +0 -4
- package/dist/index.mjs +0 -35
- package/dist/templates/base/index.mjs +0 -55
- package/dist/templates/cli/files/tsdown.config.ts +0 -3
- package/dist/templates/cli/index.mjs +0 -29
- package/dist/templates/web-app/files/src/index.test.ts +0 -5
- package/dist/templates/web-app/index.mjs +0 -69
- package/dist/templates/web-fullstack/index.mjs +0 -78
- package/dist/templates/web-vanilla/index.mjs +0 -45
- package/dist/types.mjs +0 -30
- package/dist/utils/file.mjs +0 -119
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
//#region src/templates/web-vanilla/index.ts
|
|
4
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
-
const getWebVanillaTemplate = (_opts) => {
|
|
6
|
-
return {
|
|
7
|
-
name: "web-vanilla",
|
|
8
|
-
description: "A modern, standalone web page template with built-in development and testing tooling.",
|
|
9
|
-
components: [
|
|
10
|
-
{
|
|
11
|
-
name: "Vite",
|
|
12
|
-
description: "Fast frontend build tool and development server."
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
name: "Vitest",
|
|
16
|
-
description: "Modern testing framework with browser support."
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
name: "Playwright",
|
|
20
|
-
description: "Comprehensive end-to-end testing for modern web apps."
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
dependencies: {},
|
|
24
|
-
devDependencies: {
|
|
25
|
-
vite: "vite",
|
|
26
|
-
vitest: "vitest",
|
|
27
|
-
"@vitest/browser": "@vitest/browser",
|
|
28
|
-
"@vitest/browser-playwright": "@vitest/browser-playwright",
|
|
29
|
-
playwright: "playwright",
|
|
30
|
-
"@playwright/test": "@playwright/test"
|
|
31
|
-
},
|
|
32
|
-
scripts: {
|
|
33
|
-
dev: "vite",
|
|
34
|
-
build: "vite build",
|
|
35
|
-
preview: "vite preview",
|
|
36
|
-
test: "vitest run",
|
|
37
|
-
"test:ui": "vitest",
|
|
38
|
-
"test:e2e": "playwright test"
|
|
39
|
-
},
|
|
40
|
-
files: [],
|
|
41
|
-
templateDir: path.resolve(__dirname, "files")
|
|
42
|
-
};
|
|
43
|
-
};
|
|
44
|
-
//#endregion
|
|
45
|
-
export { getWebVanillaTemplate };
|
package/dist/types.mjs
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
//#region src/types.ts
|
|
3
|
-
const TemplateTypeSchema = z.enum([
|
|
4
|
-
"cli",
|
|
5
|
-
"web-vanilla",
|
|
6
|
-
"web-app",
|
|
7
|
-
"web-fullstack"
|
|
8
|
-
]);
|
|
9
|
-
const PackageManagerSchema = z.enum([
|
|
10
|
-
"npm",
|
|
11
|
-
"pnpm",
|
|
12
|
-
"yarn"
|
|
13
|
-
]);
|
|
14
|
-
const ProjectOptionsSchema = z.object({
|
|
15
|
-
template: TemplateTypeSchema,
|
|
16
|
-
projectName: z.string().min(1, "Project name is required"),
|
|
17
|
-
packageManager: PackageManagerSchema.optional().default("npm"),
|
|
18
|
-
createGithubRepository: z.boolean().optional().default(false),
|
|
19
|
-
directory: z.string(),
|
|
20
|
-
overwrite: z.boolean().optional().default(false),
|
|
21
|
-
update: z.boolean().optional().default(false),
|
|
22
|
-
skipBuild: z.boolean().optional().default(false),
|
|
23
|
-
installDependencies: z.boolean().optional().default(false),
|
|
24
|
-
build: z.boolean().optional().default(false),
|
|
25
|
-
dev: z.boolean().optional().default(false),
|
|
26
|
-
open: z.boolean().optional().default(false),
|
|
27
|
-
silent: z.boolean().optional().default(false)
|
|
28
|
-
});
|
|
29
|
-
//#endregion
|
|
30
|
-
export { ProjectOptionsSchema, TemplateTypeSchema };
|
package/dist/utils/file.mjs
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import fs from "node:fs/promises";
|
|
3
|
-
import debugLib from "debug";
|
|
4
|
-
import { execa } from "execa";
|
|
5
|
-
//#region src/utils/file.ts
|
|
6
|
-
const debug = debugLib("create-template-project:utils:file");
|
|
7
|
-
async function getAllFiles(dirPath, arrayOfFiles = []) {
|
|
8
|
-
const files = await fs.readdir(dirPath);
|
|
9
|
-
for (const file of files) if ((await fs.stat(path.join(dirPath, file))).isDirectory()) arrayOfFiles = await getAllFiles(path.join(dirPath, file), arrayOfFiles);
|
|
10
|
-
else arrayOfFiles.push(path.join(dirPath, file));
|
|
11
|
-
return arrayOfFiles;
|
|
12
|
-
}
|
|
13
|
-
function processContent(filePath, content, opts, addedDeps) {
|
|
14
|
-
const { projectName, template } = opts;
|
|
15
|
-
let description = "";
|
|
16
|
-
switch (template) {
|
|
17
|
-
case "cli":
|
|
18
|
-
description = "A modern Node.js CLI application with TypeScript and automated tooling.";
|
|
19
|
-
break;
|
|
20
|
-
case "web-vanilla":
|
|
21
|
-
description = "A standalone web page/application for modern browsers.";
|
|
22
|
-
break;
|
|
23
|
-
case "web-fullstack":
|
|
24
|
-
description = "A full-stack monorepo with an Express server and a React/MUI client.";
|
|
25
|
-
break;
|
|
26
|
-
case "web-app":
|
|
27
|
-
description = "A React application with MUI and TanStack Query.";
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
let processed = content.replaceAll("{{projectName}}", projectName).replaceAll("{{description}}", description);
|
|
31
|
-
if (filePath.includes(".github/workflows/node.js.yml")) {
|
|
32
|
-
const pm = opts.packageManager || "npm";
|
|
33
|
-
let installCommand = "npm ci";
|
|
34
|
-
let pmSetup = "";
|
|
35
|
-
if (pm === "pnpm") {
|
|
36
|
-
installCommand = "pnpm install --frozen-lockfile";
|
|
37
|
-
pmSetup = "- uses: pnpm/action-setup@v4\n with:\n version: 9";
|
|
38
|
-
} else if (pm === "yarn") installCommand = "yarn install --frozen-lockfile";
|
|
39
|
-
let playwrightSetup = "";
|
|
40
|
-
if (template === "web-fullstack" || template === "web-app" || template === "web-vanilla") playwrightSetup = "- name: Install Playwright Browsers & Deps\n run: npx playwright install --with-deps chromium";
|
|
41
|
-
processed = processed.replaceAll("{{packageManager}}", pm).replaceAll("{{installCommand}}", installCommand).replaceAll("# [PM_SETUP]", pmSetup).replaceAll("# [PLAYWRIGHT_SETUP]", playwrightSetup);
|
|
42
|
-
processed = processed.replace(/^\s*# \[PM_SETUP\]\s*\n/m, "");
|
|
43
|
-
processed = processed.replace(/^\s*# \[PLAYWRIGHT_SETUP\]\s*\n/m, "");
|
|
44
|
-
}
|
|
45
|
-
if (template === "web-vanilla" && filePath === "index.html") processed = processed.replace("{{scriptSrc}}", opts.skipBuild ? "./src/index.js" : "./dist/index.mjs");
|
|
46
|
-
if (filePath === "CONTRIBUTING.md" && addedDeps.length > 0) {
|
|
47
|
-
processed += "\n## Dependencies\n\n";
|
|
48
|
-
const uniqueDeps = Array.from(new Set(addedDeps.map((d) => JSON.stringify(d)))).map((s) => JSON.parse(s));
|
|
49
|
-
for (const dep of uniqueDeps) processed += `- **${dep.name}**: ${dep.description}\n`;
|
|
50
|
-
}
|
|
51
|
-
if ((template === "web-fullstack" || template === "web-vanilla" || template === "web-app") && filePath === "tsconfig.json") processed = processed.replace(/\/\* Language and Environment \*\/[\s\S]*?\/\* Strict Type-Checking Options \*\//, "/* Language and Environment */\n \"target\": \"ES2023\" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,\n \"lib\": [\"ES2023\", \"DOM\", \"DOM.Iterable\"] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,\n \"module\": \"ESNext\" /* Specify what module code is generated. */,\n \"moduleResolution\": \"bundler\" /* Specify how TypeScript looks up a file from a given module specifier. */,\n \"esModuleInterop\": true /* Emit additional JavaScript to ease support for importing CommonJS modules. */,\n \"resolveJsonModule\": true /* Enable importing .json files. */,\n \"allowImportingTsExtensions\": true /* Allow imports to include TypeScript file extensions. */,\n \"noEmit\": true /* Disable emitting files from a compilation. */,\n \"jsx\": \"react-jsx\" /* Specify what JSX code is generated. */,\n\n /* Strict Type-Checking Options */");
|
|
52
|
-
if (template === "web-fullstack" && filePath === "tsconfig.json") processed = processed.replace(/"include":\s*\[\s*"src\/\*\*\/\*"\s*\]/, "\"include\": [\"client/src/**/*\", \"server/src/**/*\"]");
|
|
53
|
-
return processed;
|
|
54
|
-
}
|
|
55
|
-
function mergePackageJson(target, source) {
|
|
56
|
-
if (source.scripts) target.scripts = {
|
|
57
|
-
...target.scripts,
|
|
58
|
-
...source.scripts
|
|
59
|
-
};
|
|
60
|
-
if (source.dependencies) target.dependencies = {
|
|
61
|
-
...target.dependencies,
|
|
62
|
-
...source.dependencies
|
|
63
|
-
};
|
|
64
|
-
if (source.devDependencies) target.devDependencies = {
|
|
65
|
-
...target.devDependencies,
|
|
66
|
-
...source.devDependencies
|
|
67
|
-
};
|
|
68
|
-
if (source.workspaces) target.workspaces = source.workspaces;
|
|
69
|
-
}
|
|
70
|
-
function isSeedFile(filePath) {
|
|
71
|
-
return [
|
|
72
|
-
"src/",
|
|
73
|
-
"client/src/",
|
|
74
|
-
"server/src/",
|
|
75
|
-
"backend/src/",
|
|
76
|
-
"frontend/src/"
|
|
77
|
-
].some((dir) => filePath.startsWith(dir)) || [
|
|
78
|
-
"index.html",
|
|
79
|
-
"App.tsx",
|
|
80
|
-
"main.tsx",
|
|
81
|
-
"index.tsx"
|
|
82
|
-
].some((file) => filePath === file);
|
|
83
|
-
}
|
|
84
|
-
async function mergeFile(filePath, existing, template, log) {
|
|
85
|
-
debug("Merging file: %s", filePath);
|
|
86
|
-
const tempBase = filePath + ".base.tmp";
|
|
87
|
-
const tempNew = filePath + ".new.tmp";
|
|
88
|
-
try {
|
|
89
|
-
await fs.writeFile(tempNew, template);
|
|
90
|
-
await fs.writeFile(tempBase, "");
|
|
91
|
-
try {
|
|
92
|
-
const stdio = debug.enabled ? "inherit" : "pipe";
|
|
93
|
-
debug("Executing: git merge-file %s %s %s", filePath, tempBase, tempNew);
|
|
94
|
-
await execa("git", [
|
|
95
|
-
"merge-file",
|
|
96
|
-
filePath,
|
|
97
|
-
tempBase,
|
|
98
|
-
tempNew
|
|
99
|
-
], {
|
|
100
|
-
stdio,
|
|
101
|
-
preferLocal: true
|
|
102
|
-
});
|
|
103
|
-
return (await fs.readFile(filePath, "utf8")).trim() !== template.trim() ? "merged" : "updated";
|
|
104
|
-
} catch (e) {
|
|
105
|
-
if (e.exitCode === 1) return "conflict";
|
|
106
|
-
else {
|
|
107
|
-
debug("Git merge-file failed: %O", e);
|
|
108
|
-
const detail = e.stdout || e.stderr ? `\n\nOutput:\n${e.stdout}\n${e.stderr}` : "";
|
|
109
|
-
log.error(`Failed to merge ${filePath}: ${e.message}${detail}`);
|
|
110
|
-
return "error";
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
} finally {
|
|
114
|
-
await fs.rm(tempBase, { force: true });
|
|
115
|
-
await fs.rm(tempNew, { force: true });
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
//#endregion
|
|
119
|
-
export { getAllFiles, isSeedFile, mergeFile, mergePackageJson, processContent };
|