create-origo-app 0.1.0 → 0.1.1
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 +315 -0
- package/dist/base/backend/express/.env +3 -0
- package/dist/base/backend/express/javascript/src/app.js +25 -0
- package/dist/base/backend/express/javascript/src/config/env.js +10 -0
- package/dist/base/backend/express/javascript/src/routes/index.js +18 -0
- package/dist/base/backend/express/javascript/src/server.js +28 -0
- package/dist/base/backend/express/manifest.js +61 -0
- package/dist/base/backend/express/typescript/src/app.ts +25 -0
- package/dist/base/backend/express/typescript/src/config/env.ts +10 -0
- package/dist/base/backend/express/typescript/src/routes/index.ts +18 -0
- package/dist/base/backend/express/typescript/src/server.ts +28 -0
- package/dist/base/backend/express/typescript/tsconfig.server.json +16 -0
- package/dist/base/backend/fastify/javascript/src/app.js +16 -0
- package/dist/base/backend/fastify/javascript/src/routes/index.js +18 -0
- package/dist/base/backend/fastify/javascript/src/server.js +27 -0
- package/dist/base/backend/fastify/manifest.js +61 -0
- package/dist/base/backend/fastify/typescript/src/app.ts +16 -0
- package/dist/base/backend/fastify/typescript/src/routes/index.ts +20 -0
- package/dist/base/backend/fastify/typescript/src/server.ts +27 -0
- package/dist/base/frontend/react/app/App.css +308 -0
- package/dist/base/frontend/react/app/App.tsx +59 -0
- package/dist/base/frontend/react/app/assets/react.svg +1 -0
- package/dist/base/frontend/react/app/assets/vite.svg +1 -0
- package/dist/base/frontend/react/app/components/Counter.tsx +16 -0
- package/dist/base/frontend/react/app/components/OrigoLogo.tsx +32 -0
- package/dist/base/frontend/react/app/components/PingButton.tsx +45 -0
- package/dist/base/frontend/react/app/index.css +27 -0
- package/dist/base/frontend/react/app/main.tsx +17 -0
- package/dist/base/frontend/react/app/vite-env.d.ts +2 -0
- package/dist/base/frontend/react/html/index.html +23 -0
- package/dist/base/frontend/react/manifest.js +180 -0
- package/dist/base/frontend/react/styles/bootstrap/App.tsx +61 -0
- package/dist/base/frontend/react/styles/bootstrap/Counter.tsx +16 -0
- package/dist/base/frontend/react/styles/bootstrap/PingButton.tsx +52 -0
- package/dist/base/frontend/react/styles/bootstrap/index.css +174 -0
- package/dist/base/frontend/react/styles/sass/App.scss +231 -0
- package/dist/base/frontend/react/styles/sass/App.tsx +59 -0
- package/dist/base/frontend/react/styles/sass/PingButton.scss +33 -0
- package/dist/base/frontend/react/styles/sass/PingButton.tsx +47 -0
- package/dist/base/frontend/react/styles/sass/index.scss +30 -0
- package/dist/base/frontend/react/styles/sass/main.tsx +17 -0
- package/dist/base/frontend/react/styles/tailwind/App.tsx +66 -0
- package/dist/base/frontend/react/styles/tailwind/Counter.tsx +16 -0
- package/dist/base/frontend/react/styles/tailwind/PingButton.tsx +52 -0
- package/dist/base/frontend/shared/favicon.ico +0 -0
- package/dist/base/frontend/shared/origo-logo.svg +6 -0
- package/dist/commands/create.js +195 -10
- package/dist/commands/index.js +6 -1
- package/dist/composer/ast/arrays.js +12 -0
- package/dist/composer/ast/config.js +13 -0
- package/dist/composer/ast/context.js +73 -0
- package/dist/composer/ast/expressions.js +6 -0
- package/dist/composer/ast/imports.js +33 -0
- package/dist/composer/ast/index.js +6 -0
- package/dist/composer/ast/objects.js +32 -0
- package/dist/config/architectures.js +5 -0
- package/dist/config/backend.js +9 -0
- package/dist/config/frontend.js +17 -0
- package/dist/config/fullstack.js +30 -0
- package/dist/core/copy-template.js +57 -0
- package/dist/core/dependency-resolver.js +43 -0
- package/dist/core/install-dependencies.js +10 -0
- package/dist/core/path-safety.js +22 -0
- package/dist/core/project-target.js +40 -0
- package/dist/core/version-resolver.js +137 -0
- package/dist/features/frontend/styling/tailwind/dependencies.js +10 -0
- package/dist/features/frontend/styling/tailwind/feature.js +11 -0
- package/dist/features/frontend/styling/tailwind/generator.js +13 -0
- package/dist/features/frontend/styling/tailwind/index.js +3 -0
- package/dist/features/frontend/styling/tailwind/integrations/index.js +11 -0
- package/dist/features/frontend/styling/tailwind/integrations/rsbuild.js +3 -0
- package/dist/features/frontend/styling/tailwind/integrations/vite.js +17 -0
- package/dist/features/frontend/styling/tailwind/integrations/webpack.js +3 -0
- package/dist/features/frontend/styling/tailwind/templates/tailwind-css.js +1 -0
- package/dist/features/frontend/styling/tailwind/templates/theme.js +39 -0
- package/dist/features/frontend/styling/tailwind/versions/v3.js +19 -0
- package/dist/features/frontend/styling/tailwind/versions/v4.js +11 -0
- package/dist/features/frontend/ui/shadcn/dependencies.js +8 -0
- package/dist/features/frontend/ui/shadcn/feature.js +11 -0
- package/dist/features/frontend/ui/shadcn/generator.js +13 -0
- package/dist/features/frontend/ui/shadcn/index.js +3 -0
- package/dist/features/frontend/ui/shadcn/patches/tsconfig.js +22 -0
- package/dist/features/frontend/ui/shadcn/patches/vite-config.js +35 -0
- package/dist/features/frontend/ui/shadcn/templates/components-json.js +23 -0
- package/dist/features/frontend/ui/shadcn/templates/lib-utils.js +14 -0
- package/dist/features/index.js +29 -0
- package/dist/generators/backend/base-loader.js +33 -0
- package/dist/generators/backend/context.js +54 -0
- package/dist/generators/backend/generate.js +72 -0
- package/dist/generators/backend/index.js +4 -0
- package/dist/generators/backend/resolvers/database.js +1277 -0
- package/dist/generators/frontend/base-loader.js +23 -0
- package/dist/generators/frontend/context.js +118 -0
- package/dist/generators/frontend/css.js +34 -0
- package/dist/generators/frontend/file-writer.js +37 -0
- package/dist/generators/frontend/generate.js +46 -0
- package/dist/generators/frontend/index.js +4 -0
- package/dist/generators/frontend/resolvers/base.js +24 -0
- package/dist/generators/frontend/resolvers/bundler.js +13 -0
- package/dist/generators/frontend/resolvers/index.js +5 -0
- package/dist/generators/frontend/resolvers/language.js +55 -0
- package/dist/generators/frontend/resolvers/profile.js +41 -0
- package/dist/generators/frontend/resolvers/typescript.js +29 -0
- package/dist/generators/frontend/template.js +3 -0
- package/dist/generators/frontend/validate.js +31 -0
- package/dist/generators/package-json/build-package-json.js +33 -0
- package/dist/generators/package-json/index.js +2 -0
- package/dist/generators/package-json/types.js +1 -0
- package/dist/generators/package-json/write-package-json.js +9 -0
- package/dist/prompts/architecture.js +5 -0
- package/dist/prompts/compatibility.js +18 -0
- package/dist/prompts/custom-fullstack.js +10 -0
- package/dist/prompts/custom-stack.js +12 -0
- package/dist/prompts/database-package.js +15 -0
- package/dist/prompts/project-name.js +25 -0
- package/dist/prompts/tech-stack.js +54 -0
- package/dist/registry/bundlers.js +4 -0
- package/dist/registry/databases.js +36 -0
- package/dist/registry/features/development.js +40 -0
- package/dist/registry/features/quality.js +33 -0
- package/dist/registry/features/testing.js +36 -0
- package/dist/registry/features/ui.js +37 -0
- package/dist/registry/frameworks.js +9 -0
- package/dist/registry/packages.js +231 -0
- package/dist/registry/routing.js +12 -0
- package/dist/registry/runtimes.js +7 -0
- package/dist/registry/styling.js +7 -0
- package/dist/types/project.js +1 -0
- package/dist/ui/banner.js +0 -1
- package/dist/ui/checkbox.js +51 -0
- package/package.json +36 -4
- package/dist/cli.js +0 -22
- package/dist/ui/multiselect.js +0 -22
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { getReactBaseFiles, } from "../../base/frontend/react/manifest.js";
|
|
5
|
+
export function getBaseDirectory() {
|
|
6
|
+
return path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "base");
|
|
7
|
+
}
|
|
8
|
+
export async function loadReactBaseFiles(style = "vanilla", fullStack = false) {
|
|
9
|
+
const baseDirectory = getBaseDirectory();
|
|
10
|
+
return Promise.all(getReactBaseFiles(style, fullStack).map(async (file) => {
|
|
11
|
+
const sourcePath = path.join(baseDirectory, file.source);
|
|
12
|
+
try {
|
|
13
|
+
const content = await readFile(sourcePath, {
|
|
14
|
+
encoding: file.kind === "text" ? "utf8" : undefined,
|
|
15
|
+
});
|
|
16
|
+
return { ...file, content };
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
20
|
+
throw new Error(`Could not load base file ${file.source}: ${reason}`);
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { createAstContext } from "../../composer/ast/context.js";
|
|
3
|
+
import { resolveInsideRoot, toRootRelativePath, } from "../../core/path-safety.js";
|
|
4
|
+
const SOURCE_FILE_PATTERN = /\.(ts|tsx|js|jsx|mts|mjs|cts|cjs)$/;
|
|
5
|
+
function normalizeRelative(value, label) {
|
|
6
|
+
const normalized = value.replace(/\\/g, "/");
|
|
7
|
+
if (!normalized) {
|
|
8
|
+
return "";
|
|
9
|
+
}
|
|
10
|
+
if (normalized.startsWith("/") ||
|
|
11
|
+
normalized.split("/").includes("..")) {
|
|
12
|
+
throw new Error(`${label} escapes the project root: ${value}`);
|
|
13
|
+
}
|
|
14
|
+
return path.posix.normalize(normalized).replace(/^\.\//, "");
|
|
15
|
+
}
|
|
16
|
+
export class FrontendGenerationContext {
|
|
17
|
+
projectDirectory;
|
|
18
|
+
projectName;
|
|
19
|
+
technologies;
|
|
20
|
+
options;
|
|
21
|
+
ast;
|
|
22
|
+
rootDirectory;
|
|
23
|
+
files = new Map();
|
|
24
|
+
physicalPaths = new Map();
|
|
25
|
+
constructor(options) {
|
|
26
|
+
this.projectDirectory = options.projectDirectory;
|
|
27
|
+
this.projectName = options.projectName;
|
|
28
|
+
this.technologies = new Set(options.technologies);
|
|
29
|
+
this.options = options;
|
|
30
|
+
this.ast = createAstContext(options.projectDirectory);
|
|
31
|
+
this.rootDirectory = normalizeRelative(options.rootDirectory ?? "", "Frontend root directory");
|
|
32
|
+
}
|
|
33
|
+
has(technology) {
|
|
34
|
+
return this.technologies.has(technology);
|
|
35
|
+
}
|
|
36
|
+
addFile(relativePath, content, conflict = "ensure", atProjectRoot = false) {
|
|
37
|
+
const logicalPath = normalizeRelative(relativePath, "Destination path");
|
|
38
|
+
const physicalRelative = atProjectRoot
|
|
39
|
+
? logicalPath
|
|
40
|
+
: path.posix.join(this.rootDirectory, logicalPath);
|
|
41
|
+
const absolutePath = resolveInsideRoot(this.projectDirectory, physicalRelative);
|
|
42
|
+
const physicalPath = toRootRelativePath(this.projectDirectory, absolutePath);
|
|
43
|
+
this.files.set(logicalPath, { path: physicalPath, content, conflict });
|
|
44
|
+
this.physicalPaths.set(logicalPath, physicalPath);
|
|
45
|
+
if (typeof content === "string" && SOURCE_FILE_PATTERN.test(physicalPath)) {
|
|
46
|
+
this.ast.createSourceFile(physicalPath, content);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
addRootFile(relativePath, content, conflict = "ensure") {
|
|
50
|
+
this.addFile(relativePath, content, conflict, true);
|
|
51
|
+
}
|
|
52
|
+
addRootJsonFile(relativePath, value, conflict = "ensure") {
|
|
53
|
+
this.addRootFile(relativePath, `${JSON.stringify(value, null, 2)}\n`, conflict);
|
|
54
|
+
}
|
|
55
|
+
addTextFile(relativePath, content, conflict = "ensure") {
|
|
56
|
+
this.addFile(relativePath, content, conflict);
|
|
57
|
+
}
|
|
58
|
+
addJsonFile(relativePath, value, conflict = "ensure") {
|
|
59
|
+
this.addTextFile(relativePath, `${JSON.stringify(value, null, 2)}\n`, conflict);
|
|
60
|
+
}
|
|
61
|
+
getFile(relativePath) {
|
|
62
|
+
return this.files.get(normalizeRelative(relativePath, "Destination path"));
|
|
63
|
+
}
|
|
64
|
+
getTextFile(relativePath) {
|
|
65
|
+
const file = this.getFile(relativePath);
|
|
66
|
+
if (!file || typeof file.content !== "string") {
|
|
67
|
+
throw new Error(`Generated text file not found: ${relativePath}`);
|
|
68
|
+
}
|
|
69
|
+
return file.content;
|
|
70
|
+
}
|
|
71
|
+
hasFile(relativePath) {
|
|
72
|
+
return this.getFile(relativePath) !== undefined;
|
|
73
|
+
}
|
|
74
|
+
getSourceFile(relativePath) {
|
|
75
|
+
const logicalPath = normalizeRelative(relativePath, "Source path");
|
|
76
|
+
const physicalPath = this.physicalPaths.get(logicalPath);
|
|
77
|
+
if (!physicalPath) {
|
|
78
|
+
throw new Error(`Source file not found: ${relativePath}`);
|
|
79
|
+
}
|
|
80
|
+
return this.ast.getSourceFile(physicalPath);
|
|
81
|
+
}
|
|
82
|
+
getSourceFileIfExists(relativePath) {
|
|
83
|
+
const logicalPath = normalizeRelative(relativePath, "Source path");
|
|
84
|
+
const physicalPath = this.physicalPaths.get(logicalPath);
|
|
85
|
+
return physicalPath ? this.ast.getSourceFileIfExists(physicalPath) : undefined;
|
|
86
|
+
}
|
|
87
|
+
renameFile(from, to) {
|
|
88
|
+
const file = this.getFile(from);
|
|
89
|
+
const physicalPath = this.physicalPaths.get(normalizeRelative(from, "Source path"));
|
|
90
|
+
if (!file || !physicalPath) {
|
|
91
|
+
throw new Error(`Generated file not found: ${from}`);
|
|
92
|
+
}
|
|
93
|
+
const content = this.ast.getSourceFile(physicalPath).getFullText();
|
|
94
|
+
const conflict = file.conflict;
|
|
95
|
+
const fromLogical = normalizeRelative(from, "Source path");
|
|
96
|
+
this.ast.removeSourceFile(physicalPath);
|
|
97
|
+
this.files.delete(fromLogical);
|
|
98
|
+
this.physicalPaths.delete(fromLogical);
|
|
99
|
+
this.addFile(to, content, conflict);
|
|
100
|
+
}
|
|
101
|
+
listFiles() {
|
|
102
|
+
return [...this.files.values()].sort((left, right) => left.path.localeCompare(right.path));
|
|
103
|
+
}
|
|
104
|
+
finalize() {
|
|
105
|
+
const logicalByPhysical = new Map([...this.physicalPaths].map(([logicalPath, physicalPath]) => [
|
|
106
|
+
physicalPath,
|
|
107
|
+
logicalPath,
|
|
108
|
+
]));
|
|
109
|
+
for (const [physicalPath, content] of this.ast.finalize()) {
|
|
110
|
+
const logicalPath = logicalByPhysical.get(physicalPath);
|
|
111
|
+
const file = logicalPath ? this.files.get(logicalPath) : undefined;
|
|
112
|
+
if (file) {
|
|
113
|
+
file.content = content;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return this.listFiles();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export function parseCss(content) {
|
|
2
|
+
const lines = content.split("\n");
|
|
3
|
+
const imports = [];
|
|
4
|
+
const body = [];
|
|
5
|
+
for (const line of lines) {
|
|
6
|
+
if (line.trimStart().startsWith("@import")) {
|
|
7
|
+
imports.push(line.trim());
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
body.push(line);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return { imports, body };
|
|
14
|
+
}
|
|
15
|
+
export function addCssImport(document, statement) {
|
|
16
|
+
if (!document.imports.includes(statement)) {
|
|
17
|
+
document.imports.push(statement);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
export function addCssBlock(document, block) {
|
|
21
|
+
const normalized = block.trim();
|
|
22
|
+
if (document.body.join("\n").includes(normalized)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
document.body.push("", normalized);
|
|
26
|
+
}
|
|
27
|
+
export function renderCss(document) {
|
|
28
|
+
const sections = [];
|
|
29
|
+
if (document.imports.length) {
|
|
30
|
+
sections.push(document.imports.join("\n"));
|
|
31
|
+
}
|
|
32
|
+
sections.push(document.body.join("\n").replace(/^\n+/, ""));
|
|
33
|
+
return `${sections.join("\n\n").replace(/\n+$/, "")}\n`;
|
|
34
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { lstat, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { resolveInsideRoot } from "../../core/path-safety.js";
|
|
4
|
+
function contentMatches(existing, content) {
|
|
5
|
+
const incoming = Buffer.isBuffer(content) ? content : Buffer.from(content);
|
|
6
|
+
return existing.equals(incoming);
|
|
7
|
+
}
|
|
8
|
+
export async function writeGeneratedFiles(projectDirectory, files) {
|
|
9
|
+
for (const file of files) {
|
|
10
|
+
const destination = resolveInsideRoot(projectDirectory, file.path);
|
|
11
|
+
await mkdir(path.dirname(destination), { recursive: true });
|
|
12
|
+
let existing;
|
|
13
|
+
try {
|
|
14
|
+
const stats = await lstat(destination);
|
|
15
|
+
if (stats.isSymbolicLink()) {
|
|
16
|
+
throw new Error(`Refusing to write through a symbolic link: ${file.path}`);
|
|
17
|
+
}
|
|
18
|
+
if (stats.isFile()) {
|
|
19
|
+
existing = await readFile(destination);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
if (error.code !== "ENOENT") {
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (existing) {
|
|
28
|
+
if (contentMatches(existing, file.content)) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (file.conflict !== "overwrite") {
|
|
32
|
+
throw new Error(`Refusing to overwrite existing file: ${file.path}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
await writeFile(destination, file.content);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { applyFeatures } from "../../features/index.js";
|
|
2
|
+
import { buildPackageJson } from "../package-json/build-package-json.js";
|
|
3
|
+
import { FrontendGenerationContext, } from "./context.js";
|
|
4
|
+
import { resolveReactBase, resolveBundlerConfig, resolveFrontendProfile, resolveLanguage, resolveTypeScriptConfig, } from "./resolvers/index.js";
|
|
5
|
+
import { validateGeneratedProject } from "./validate.js";
|
|
6
|
+
function projectScripts(options) {
|
|
7
|
+
const scripts = {
|
|
8
|
+
dev: options.scripts.dev ?? "vite",
|
|
9
|
+
build: options.scripts.build ?? "vite build",
|
|
10
|
+
preview: options.scripts.preview ?? "vite preview",
|
|
11
|
+
};
|
|
12
|
+
if (options.technologies.includes("typescript")) {
|
|
13
|
+
scripts.typecheck = "tsc -p tsconfig.json --noEmit";
|
|
14
|
+
}
|
|
15
|
+
return scripts;
|
|
16
|
+
}
|
|
17
|
+
export async function generateFrontendProject(options) {
|
|
18
|
+
const context = new FrontendGenerationContext(options);
|
|
19
|
+
const profile = resolveFrontendProfile(context);
|
|
20
|
+
const includePackageJson = options.includePackageJson ?? true;
|
|
21
|
+
if (includePackageJson) {
|
|
22
|
+
context.addJsonFile("package.json", buildPackageJson({
|
|
23
|
+
name: options.fullStack
|
|
24
|
+
? `${options.projectName}-client`
|
|
25
|
+
: options.projectName,
|
|
26
|
+
version: "1.0.0",
|
|
27
|
+
private: true,
|
|
28
|
+
type: "module",
|
|
29
|
+
scripts: projectScripts(options),
|
|
30
|
+
dependencies: options.dependencies,
|
|
31
|
+
devDependencies: options.devDependencies,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
await resolveReactBase(context, profile);
|
|
35
|
+
resolveLanguage(context, profile);
|
|
36
|
+
resolveBundlerConfig(context, profile);
|
|
37
|
+
resolveTypeScriptConfig(context, profile);
|
|
38
|
+
const appliedFeatures = applyFeatures(context);
|
|
39
|
+
validateGeneratedProject(context, profile, includePackageJson);
|
|
40
|
+
return {
|
|
41
|
+
files: context.finalize(),
|
|
42
|
+
appliedFeatures,
|
|
43
|
+
language: profile.language,
|
|
44
|
+
bundler: profile.bundler,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { loadReactBaseFiles } from "../base-loader.js";
|
|
2
|
+
import { renderTemplate } from "../template.js";
|
|
3
|
+
export async function resolveReactBase(context, profile) {
|
|
4
|
+
const files = await loadReactBaseFiles(profile.style, profile.isFullStack);
|
|
5
|
+
const values = {
|
|
6
|
+
TITLE: `Origo — ${profile.bundlerLabel} + React`,
|
|
7
|
+
ENTRY_SCRIPT: `/src/main.${profile.sourceExtension}`,
|
|
8
|
+
APP_FILE: `src/App.${profile.sourceExtension}`,
|
|
9
|
+
HEADLINE_PREFIX: `${profile.bundlerLabel} +`,
|
|
10
|
+
PING_IMPORT: profile.isFullStack
|
|
11
|
+
? `import PingButton from "./components/PingButton";`
|
|
12
|
+
: "",
|
|
13
|
+
PING_BUTTON: profile.isFullStack ? `<PingButton />` : "",
|
|
14
|
+
};
|
|
15
|
+
if (profile.isFullStack) {
|
|
16
|
+
context.addTextFile(".env", `VITE_API_URL=http://localhost:3000/api\n`);
|
|
17
|
+
}
|
|
18
|
+
for (const file of files) {
|
|
19
|
+
const content = typeof file.content === "string"
|
|
20
|
+
? renderTemplate(file.content, values)
|
|
21
|
+
: file.content;
|
|
22
|
+
context.addFile(file.destination, content);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function resolveBundlerConfig(context, profile) {
|
|
2
|
+
if (profile.bundler !== "vite") {
|
|
3
|
+
throw new Error(`${profile.bundlerLabel} base configuration is not implemented yet`);
|
|
4
|
+
}
|
|
5
|
+
const configPath = `vite.config.${profile.configExtension}`;
|
|
6
|
+
context.addTextFile(configPath, `import { defineConfig } from "vite";
|
|
7
|
+
import react from "@vitejs/plugin-react";
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
plugins: [react()],
|
|
11
|
+
});
|
|
12
|
+
`);
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Node, SyntaxKind } from "ts-morph";
|
|
2
|
+
const TYPE_SOURCE_FILES = [
|
|
3
|
+
"src/App.tsx",
|
|
4
|
+
"src/main.tsx",
|
|
5
|
+
"src/components/Counter.tsx",
|
|
6
|
+
"src/components/OrigoLogo.tsx",
|
|
7
|
+
"src/components/PingButton.tsx",
|
|
8
|
+
];
|
|
9
|
+
export function stripTypeScriptSyntax(source) {
|
|
10
|
+
for (const declaration of [
|
|
11
|
+
...source.getDescendantsOfKind(SyntaxKind.TypeAliasDeclaration),
|
|
12
|
+
...source.getDescendantsOfKind(SyntaxKind.InterfaceDeclaration),
|
|
13
|
+
]) {
|
|
14
|
+
declaration.remove();
|
|
15
|
+
}
|
|
16
|
+
for (const parameter of source
|
|
17
|
+
.getDescendants()
|
|
18
|
+
.filter(Node.isParameterDeclaration)) {
|
|
19
|
+
parameter.removeType();
|
|
20
|
+
}
|
|
21
|
+
for (const variable of source
|
|
22
|
+
.getDescendants()
|
|
23
|
+
.filter(Node.isVariableDeclaration)) {
|
|
24
|
+
variable.removeType();
|
|
25
|
+
}
|
|
26
|
+
for (const call of source.getDescendantsOfKind(SyntaxKind.CallExpression)) {
|
|
27
|
+
for (const typeArgument of call.getTypeArguments()) {
|
|
28
|
+
call.removeTypeArgument(typeArgument);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
for (const declaration of source.getImportDeclarations()) {
|
|
32
|
+
if (declaration.isTypeOnly()) {
|
|
33
|
+
declaration.remove();
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (const specifier of declaration.getNamedImports()) {
|
|
37
|
+
if (specifier.isTypeOnly()) {
|
|
38
|
+
specifier.remove();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function resolveLanguage(context, profile) {
|
|
44
|
+
if (profile.isTypeScript) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
for (const sourcePath of TYPE_SOURCE_FILES) {
|
|
48
|
+
if (!context.hasFile(sourcePath)) {
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
const source = context.getSourceFile(sourcePath);
|
|
52
|
+
stripTypeScriptSyntax(source);
|
|
53
|
+
context.renameFile(sourcePath, sourcePath.replace(/\.tsx$/, ".jsx"));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const bundlerLabels = {
|
|
2
|
+
vite: "Vite",
|
|
3
|
+
webpack: "Webpack",
|
|
4
|
+
rsbuild: "Rsbuild",
|
|
5
|
+
};
|
|
6
|
+
export function resolveFrontendStyle(context) {
|
|
7
|
+
if (context.has("tailwind") ||
|
|
8
|
+
context.has("tailwind-v3") ||
|
|
9
|
+
context.has("tailwind-v4")) {
|
|
10
|
+
return "tailwind";
|
|
11
|
+
}
|
|
12
|
+
if (context.has("bootstrap")) {
|
|
13
|
+
return "bootstrap";
|
|
14
|
+
}
|
|
15
|
+
if (context.has("sass") || context.has("scss")) {
|
|
16
|
+
return "sass";
|
|
17
|
+
}
|
|
18
|
+
return "vanilla";
|
|
19
|
+
}
|
|
20
|
+
export function resolveFrontendProfile(context) {
|
|
21
|
+
const language = context.has("typescript")
|
|
22
|
+
? "typescript"
|
|
23
|
+
: "javascript";
|
|
24
|
+
const bundler = context.has("webpack")
|
|
25
|
+
? "webpack"
|
|
26
|
+
: context.has("rsbuild")
|
|
27
|
+
? "rsbuild"
|
|
28
|
+
: "vite";
|
|
29
|
+
const isTypeScript = language === "typescript";
|
|
30
|
+
return {
|
|
31
|
+
framework: "react",
|
|
32
|
+
language,
|
|
33
|
+
bundler,
|
|
34
|
+
isTypeScript,
|
|
35
|
+
sourceExtension: isTypeScript ? "tsx" : "jsx",
|
|
36
|
+
configExtension: isTypeScript ? "ts" : "js",
|
|
37
|
+
bundlerLabel: bundlerLabels[bundler],
|
|
38
|
+
style: resolveFrontendStyle(context),
|
|
39
|
+
isFullStack: context.options.fullStack ?? false,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export function resolveTypeScriptConfig(context, profile) {
|
|
2
|
+
if (!profile.isTypeScript) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
context.addJsonFile("tsconfig.json", {
|
|
6
|
+
compilerOptions: {
|
|
7
|
+
target: "ES2022",
|
|
8
|
+
useDefineForClassFields: true,
|
|
9
|
+
lib: ["ES2022", "DOM", "DOM.Iterable"],
|
|
10
|
+
module: "ESNext",
|
|
11
|
+
moduleResolution: "Bundler",
|
|
12
|
+
jsx: "react-jsx",
|
|
13
|
+
strict: true,
|
|
14
|
+
noEmit: true,
|
|
15
|
+
skipLibCheck: true,
|
|
16
|
+
isolatedModules: true,
|
|
17
|
+
verbatimModuleSyntax: true,
|
|
18
|
+
noFallthroughCasesInSwitch: true,
|
|
19
|
+
noUnusedLocals: true,
|
|
20
|
+
noUnusedParameters: true,
|
|
21
|
+
},
|
|
22
|
+
include: [
|
|
23
|
+
"src",
|
|
24
|
+
profile.bundler === "vite"
|
|
25
|
+
? `vite.config.${profile.configExtension}`
|
|
26
|
+
: "src",
|
|
27
|
+
],
|
|
28
|
+
});
|
|
29
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function validateGeneratedProject(context, profile, includePackageJson = true) {
|
|
2
|
+
const required = [
|
|
3
|
+
...(includePackageJson ? ["package.json"] : []),
|
|
4
|
+
"index.html",
|
|
5
|
+
`src/App.${profile.sourceExtension}`,
|
|
6
|
+
`src/main.${profile.sourceExtension}`,
|
|
7
|
+
`vite.config.${profile.configExtension}`,
|
|
8
|
+
];
|
|
9
|
+
if (profile.isTypeScript) {
|
|
10
|
+
required.push("tsconfig.json", "src/vite-env.d.ts");
|
|
11
|
+
}
|
|
12
|
+
const styleFiles = {
|
|
13
|
+
vanilla: ["src/App.css", "src/index.css"],
|
|
14
|
+
tailwind: ["src/index.css"],
|
|
15
|
+
bootstrap: ["src/index.css"],
|
|
16
|
+
sass: ["src/App.scss", "src/index.scss"],
|
|
17
|
+
};
|
|
18
|
+
required.push(...styleFiles[profile.style]);
|
|
19
|
+
if (profile.isFullStack) {
|
|
20
|
+
required.push(".env");
|
|
21
|
+
required.push(`src/components/PingButton.${profile.sourceExtension}`);
|
|
22
|
+
if (profile.style === "sass") {
|
|
23
|
+
required.push("src/components/PingButton.scss");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
for (const relativePath of required) {
|
|
27
|
+
if (!context.hasFile(relativePath)) {
|
|
28
|
+
throw new Error(`Generated project is missing ${relativePath}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export function buildPackageJson(options) {
|
|
2
|
+
return {
|
|
3
|
+
name: options.name,
|
|
4
|
+
version: options.version ?? "1.0.0",
|
|
5
|
+
description: options.description,
|
|
6
|
+
private: options.private ?? true,
|
|
7
|
+
type: options.type ?? "module",
|
|
8
|
+
scripts: options.scripts ?? {},
|
|
9
|
+
dependencies: options.dependencies ?? {},
|
|
10
|
+
devDependencies: options.devDependencies ?? {},
|
|
11
|
+
engines: options.engines,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function buildFullStackRootPackageJson(projectName, devDependencies) {
|
|
15
|
+
return {
|
|
16
|
+
name: projectName,
|
|
17
|
+
version: "1.0.0",
|
|
18
|
+
private: true,
|
|
19
|
+
type: "module",
|
|
20
|
+
scripts: {
|
|
21
|
+
dev: 'concurrently "npm --prefix client run dev" "npm --prefix server run dev"',
|
|
22
|
+
"dev:client": "npm --prefix client run dev",
|
|
23
|
+
"dev:server": "npm --prefix server run dev",
|
|
24
|
+
build: "npm --prefix client run build && npm --prefix server run build",
|
|
25
|
+
"build:client": "npm --prefix client run build",
|
|
26
|
+
"build:server": "npm --prefix server run build",
|
|
27
|
+
preview: "npm --prefix client run preview",
|
|
28
|
+
start: "npm --prefix server run start",
|
|
29
|
+
},
|
|
30
|
+
dependencies: {},
|
|
31
|
+
devDependencies,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { writeFile, mkdir } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { buildPackageJson } from "./build-package-json.js";
|
|
4
|
+
export async function writePackageJson(projectDirectory, options) {
|
|
5
|
+
const packageJson = buildPackageJson(options);
|
|
6
|
+
const filePath = path.join(projectDirectory, "package.json");
|
|
7
|
+
await mkdir(projectDirectory, { recursive: true });
|
|
8
|
+
await writeFile(filePath, JSON.stringify(packageJson, null, 2) + "\n", "utf-8");
|
|
9
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function isCompatible(option, active) {
|
|
2
|
+
if (option.frameworks?.length && !option.frameworks.some((item) => active.has(item))) {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
if (option.bundlers?.length && !option.bundlers.some((item) => active.has(item))) {
|
|
6
|
+
return false;
|
|
7
|
+
}
|
|
8
|
+
if (option.requires?.some((item) => !active.has(item))) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
if (option.requiresAny?.length && !option.requiresAny.some((item) => active.has(item))) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
if (option.conflictsWith?.some((item) => active.has(item))) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { singleSelect } from "../ui/checkbox.js";
|
|
2
|
+
import { databaseOptions } from "../registry/databases.js";
|
|
3
|
+
import { backendFrameworkOptions, frontendFrameworkOptions, } from "../registry/frameworks.js";
|
|
4
|
+
export async function selectCustomFullStack(active) {
|
|
5
|
+
const frontend = await singleSelect("Select Frontend Technology", frontendFrameworkOptions);
|
|
6
|
+
const backend = await singleSelect("Select Backend Technology", backendFrameworkOptions.filter((option) => option.value !== "custom"));
|
|
7
|
+
const database = await singleSelect("Select Database", databaseOptions);
|
|
8
|
+
[frontend, backend, database].forEach((value) => active.add(value));
|
|
9
|
+
return [frontend, backend, database];
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { input } from "@inquirer/prompts";
|
|
2
|
+
export async function selectCustomStack() {
|
|
3
|
+
const custom = await input({
|
|
4
|
+
message: "Enter your custom technologies (comma separated)",
|
|
5
|
+
validate: (value) => value.trim().length > 0 ||
|
|
6
|
+
"Please enter at least one technology",
|
|
7
|
+
});
|
|
8
|
+
return custom
|
|
9
|
+
.split(",")
|
|
10
|
+
.map((item) => item.trim())
|
|
11
|
+
.filter(Boolean);
|
|
12
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { singleSelect } from "../ui/checkbox.js";
|
|
2
|
+
import { databasePackageOptions } from "../registry/databases.js";
|
|
3
|
+
export async function selectDatabasePackages(active) {
|
|
4
|
+
const database = active.has("mongodb")
|
|
5
|
+
? "mongodb"
|
|
6
|
+
: active.has("postgresql")
|
|
7
|
+
? "postgresql"
|
|
8
|
+
: null;
|
|
9
|
+
if (!database) {
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
const selected = await singleSelect(`Select ${database === "mongodb" ? "MongoDB" : "PostgreSQL"} package`, databasePackageOptions[database]);
|
|
13
|
+
active.add(selected);
|
|
14
|
+
return [selected];
|
|
15
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { input } from "@inquirer/prompts";
|
|
2
|
+
import { isPathLike } from "../core/project-target.js";
|
|
3
|
+
export async function promptProjectName() {
|
|
4
|
+
const name = await input({
|
|
5
|
+
message: "Project name or path",
|
|
6
|
+
default: "my-origo-app",
|
|
7
|
+
theme: {
|
|
8
|
+
prefix: "◆",
|
|
9
|
+
},
|
|
10
|
+
validate: (value) => {
|
|
11
|
+
const trimmed = value.trim();
|
|
12
|
+
if (!trimmed) {
|
|
13
|
+
return "Enter a project name or path";
|
|
14
|
+
}
|
|
15
|
+
if (isPathLike(trimmed)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (!/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(trimmed)) {
|
|
19
|
+
return "Use a project name, ./, ., or a valid path";
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return name.trim();
|
|
25
|
+
}
|