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,33 @@
|
|
|
1
|
+
export function addImport(source, module, defaultImport) {
|
|
2
|
+
const existing = source
|
|
3
|
+
.getImportDeclarations()
|
|
4
|
+
.find(item => item.getModuleSpecifierValue() === module);
|
|
5
|
+
if (existing) {
|
|
6
|
+
if (!existing.getDefaultImport()) {
|
|
7
|
+
existing.setDefaultImport(defaultImport);
|
|
8
|
+
}
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
source.addImportDeclaration({
|
|
12
|
+
moduleSpecifier: module,
|
|
13
|
+
defaultImport,
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export function addNamedImport(source, module, namedImport) {
|
|
17
|
+
const existing = source
|
|
18
|
+
.getImportDeclarations()
|
|
19
|
+
.find(item => item.getModuleSpecifierValue() === module);
|
|
20
|
+
if (existing) {
|
|
21
|
+
const alreadyImported = existing
|
|
22
|
+
.getNamedImports()
|
|
23
|
+
.some(item => item.getName() === namedImport);
|
|
24
|
+
if (!alreadyImported) {
|
|
25
|
+
existing.addNamedImport(namedImport);
|
|
26
|
+
}
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
source.addImportDeclaration({
|
|
30
|
+
moduleSpecifier: module,
|
|
31
|
+
namedImports: [namedImport],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Node, } from "ts-morph";
|
|
2
|
+
export function addObjectProperty(object, key, value) {
|
|
3
|
+
const existing = object.getProperty(key);
|
|
4
|
+
if (existing) {
|
|
5
|
+
throw new Error(`Property '${key}' already exists`);
|
|
6
|
+
}
|
|
7
|
+
object.addPropertyAssignment({
|
|
8
|
+
name: key,
|
|
9
|
+
initializer: value,
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
export function updateObjectProperty(object, key, value) {
|
|
13
|
+
const existing = object.getProperty(key);
|
|
14
|
+
if (!existing) {
|
|
15
|
+
throw new Error(`Property '${key}' does not exist`);
|
|
16
|
+
}
|
|
17
|
+
if (Node.isPropertyAssignment(existing)) {
|
|
18
|
+
existing.setInitializer(value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export function upsertObjectProperty(object, key, value) {
|
|
22
|
+
const existing = object.getProperty(key) ??
|
|
23
|
+
object.getProperty(`"${key}"`) ??
|
|
24
|
+
object.getProperty(`'${key}'`);
|
|
25
|
+
if (!existing) {
|
|
26
|
+
object.addPropertyAssignment({ name: key, initializer: value });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (Node.isPropertyAssignment(existing)) {
|
|
30
|
+
existing.setInitializer(value);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { backendFrameworkOptions } from "../registry/frameworks.js";
|
|
2
|
+
import { languageOptions, runtimeOptions } from "../registry/runtimes.js";
|
|
3
|
+
import { databaseOptions } from "../registry/databases.js";
|
|
4
|
+
export const backendConfig = {
|
|
5
|
+
runtimes: { required: true, options: runtimeOptions },
|
|
6
|
+
frameworks: { required: true, options: backendFrameworkOptions },
|
|
7
|
+
languages: { required: true, options: languageOptions },
|
|
8
|
+
databases: { required: false, options: databaseOptions },
|
|
9
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { bundlerOptions } from "../registry/bundlers.js";
|
|
2
|
+
import { frontendFrameworkOptions } from "../registry/frameworks.js";
|
|
3
|
+
import { stylingOptions } from "../registry/styling.js";
|
|
4
|
+
import { routingOptions } from "../registry/routing.js";
|
|
5
|
+
export const frontendConfig = {
|
|
6
|
+
bundlers: { required: true, options: bundlerOptions },
|
|
7
|
+
frameworks: { required: true, options: frontendFrameworkOptions },
|
|
8
|
+
languages: {
|
|
9
|
+
required: true,
|
|
10
|
+
options: [
|
|
11
|
+
{ name: "TypeScript", value: "typescript" },
|
|
12
|
+
{ name: "JavaScript", value: "javascript" },
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
styling: { required: false, options: stylingOptions },
|
|
16
|
+
routing: { required: false, options: routingOptions },
|
|
17
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const fullStackOptions = [
|
|
2
|
+
{
|
|
3
|
+
name: "MERN Stack",
|
|
4
|
+
value: "mern",
|
|
5
|
+
description: "MongoDB, Express, React and Node.js",
|
|
6
|
+
frontend: ["react", "vite"],
|
|
7
|
+
backend: ["nodejs", "express"],
|
|
8
|
+
database: ["mongodb"],
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: "PERN Stack",
|
|
12
|
+
value: "pern",
|
|
13
|
+
description: "PostgreSQL, Express, React and Node.js",
|
|
14
|
+
frontend: ["react", "vite"],
|
|
15
|
+
backend: ["nodejs", "express"],
|
|
16
|
+
database: ["postgresql"],
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: "Custom Stack",
|
|
20
|
+
value: "custom",
|
|
21
|
+
description: "Build your own full-stack combination",
|
|
22
|
+
frontend: [],
|
|
23
|
+
backend: [],
|
|
24
|
+
database: [],
|
|
25
|
+
},
|
|
26
|
+
];
|
|
27
|
+
export const fullStackPreset = {
|
|
28
|
+
required: true,
|
|
29
|
+
options: fullStackOptions,
|
|
30
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { cp, mkdir, stat } from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
const moduleDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
5
|
+
const cliRoot = path.resolve(moduleDirectory, "../..");
|
|
6
|
+
const DEFAULT_TEMPLATE_ROOT = path.resolve(cliRoot, "../template/frontend");
|
|
7
|
+
const DEFAULT_TEMPLATE_SOURCE = path.join(DEFAULT_TEMPLATE_ROOT, "vite-react/raw");
|
|
8
|
+
const DEFAULT_TYPESCRIPT_TEMPLATE_SOURCE = path.join(DEFAULT_TEMPLATE_ROOT, "vite-react-ts/raw");
|
|
9
|
+
const EXCLUDED_NAMES = new Set([
|
|
10
|
+
".git",
|
|
11
|
+
".env",
|
|
12
|
+
".DS_Store",
|
|
13
|
+
"node_modules",
|
|
14
|
+
"coverage",
|
|
15
|
+
"package.json",
|
|
16
|
+
"package-lock.json",
|
|
17
|
+
]);
|
|
18
|
+
function resolveTemplateSource(technologies) {
|
|
19
|
+
if (process.env.ORIGO_TEMPLATE_SOURCE) {
|
|
20
|
+
return path.resolve(process.env.ORIGO_TEMPLATE_SOURCE);
|
|
21
|
+
}
|
|
22
|
+
return new Set(technologies).has("typescript")
|
|
23
|
+
? DEFAULT_TYPESCRIPT_TEMPLATE_SOURCE
|
|
24
|
+
: DEFAULT_TEMPLATE_SOURCE;
|
|
25
|
+
}
|
|
26
|
+
function shouldCopy(source) {
|
|
27
|
+
const sourcePath = typeof source === "string" ? source : fileURLToPath(source);
|
|
28
|
+
const name = path.basename(sourcePath);
|
|
29
|
+
return (!EXCLUDED_NAMES.has(name) &&
|
|
30
|
+
!name.startsWith(".env.") &&
|
|
31
|
+
!name.endsWith(".log"));
|
|
32
|
+
}
|
|
33
|
+
export async function copyTemplate(projectDirectory, technologies = []) {
|
|
34
|
+
const sourceDirectory = resolveTemplateSource(technologies);
|
|
35
|
+
let sourceStats;
|
|
36
|
+
try {
|
|
37
|
+
sourceStats = await stat(sourceDirectory);
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
41
|
+
throw new Error(`Could not access template source ${sourceDirectory}: ${reason}`);
|
|
42
|
+
}
|
|
43
|
+
if (!sourceStats.isDirectory()) {
|
|
44
|
+
throw new Error(`Template source is not a directory: ${sourceDirectory}`);
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
await mkdir(projectDirectory, { recursive: true });
|
|
48
|
+
await cp(sourceDirectory, projectDirectory, {
|
|
49
|
+
recursive: true,
|
|
50
|
+
filter: shouldCopy,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
55
|
+
throw new Error(`Could not copy template from ${sourceDirectory}: ${reason}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { fullStackOptions } from "../config/fullstack.js";
|
|
2
|
+
import { packageRegistry } from "../registry/packages.js";
|
|
3
|
+
import { resolvePackageVersions, } from "./version-resolver.js";
|
|
4
|
+
function expandPresets(technologies) {
|
|
5
|
+
return technologies.flatMap((technology) => {
|
|
6
|
+
const preset = fullStackOptions.find((option) => option.value === technology);
|
|
7
|
+
return preset
|
|
8
|
+
? [...preset.frontend, ...preset.backend, ...preset.database]
|
|
9
|
+
: [technology];
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function sort(record) {
|
|
13
|
+
return Object.fromEntries(Object.entries(record).sort(([left], [right]) => left.localeCompare(right)));
|
|
14
|
+
}
|
|
15
|
+
export function collectDependencies(technologies) {
|
|
16
|
+
const dependencies = new Set();
|
|
17
|
+
const devDependencies = new Set();
|
|
18
|
+
const scripts = {};
|
|
19
|
+
for (const technology of new Set(expandPresets(technologies))) {
|
|
20
|
+
const metadata = packageRegistry[technology];
|
|
21
|
+
if (!metadata) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
metadata.dependencies?.forEach((name) => dependencies.add(name));
|
|
25
|
+
metadata.devDependencies?.forEach((name) => devDependencies.add(name));
|
|
26
|
+
Object.assign(scripts, metadata.scripts);
|
|
27
|
+
}
|
|
28
|
+
devDependencies.forEach((name) => dependencies.delete(name));
|
|
29
|
+
return {
|
|
30
|
+
dependencies: [...dependencies].sort(),
|
|
31
|
+
devDependencies: [...devDependencies].sort(),
|
|
32
|
+
scripts: sort(scripts),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export async function resolveDependencies(technologies, options = {}) {
|
|
36
|
+
const collected = collectDependencies(technologies);
|
|
37
|
+
const versions = await resolvePackageVersions([...collected.dependencies, ...collected.devDependencies], options);
|
|
38
|
+
return {
|
|
39
|
+
dependencies: Object.fromEntries(collected.dependencies.map((name) => [name, versions[name]])),
|
|
40
|
+
devDependencies: Object.fromEntries(collected.devDependencies.map((name) => [name, versions[name]])),
|
|
41
|
+
scripts: collected.scripts,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
const execFileAsync = promisify(execFile);
|
|
4
|
+
export async function installDependencies(projectDirectory) {
|
|
5
|
+
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
6
|
+
await execFileAsync(npm, ["install", "--no-audit", "--no-fund"], {
|
|
7
|
+
cwd: projectDirectory,
|
|
8
|
+
maxBuffer: 10 * 1024 * 1024,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
export function resolveInsideRoot(root, relativePath) {
|
|
3
|
+
if (!relativePath) {
|
|
4
|
+
throw new Error("A destination path is required");
|
|
5
|
+
}
|
|
6
|
+
const rootPath = path.resolve(root);
|
|
7
|
+
const resolved = path.isAbsolute(relativePath)
|
|
8
|
+
? path.resolve(relativePath)
|
|
9
|
+
: path.resolve(rootPath, relativePath);
|
|
10
|
+
if (resolved !== rootPath && !resolved.startsWith(`${rootPath}${path.sep}`)) {
|
|
11
|
+
throw new Error(`Destination path escapes the project root: ${relativePath}`);
|
|
12
|
+
}
|
|
13
|
+
return resolved;
|
|
14
|
+
}
|
|
15
|
+
export function toRootRelativePath(root, absolutePath) {
|
|
16
|
+
const rootPath = path.resolve(root);
|
|
17
|
+
const resolved = path.resolve(absolutePath);
|
|
18
|
+
if (resolved !== rootPath && !resolved.startsWith(`${rootPath}${path.sep}`)) {
|
|
19
|
+
throw new Error(`Path escapes the project root: ${absolutePath}`);
|
|
20
|
+
}
|
|
21
|
+
return path.relative(rootPath, resolved).split(path.sep).join("/");
|
|
22
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
const NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
|
|
3
|
+
export function isPathLike(value) {
|
|
4
|
+
return (value === "." ||
|
|
5
|
+
value === ".." ||
|
|
6
|
+
value.startsWith("./") ||
|
|
7
|
+
value.startsWith("../") ||
|
|
8
|
+
value.includes("/") ||
|
|
9
|
+
value.includes("\\") ||
|
|
10
|
+
path.isAbsolute(value));
|
|
11
|
+
}
|
|
12
|
+
function validateProjectName(value) {
|
|
13
|
+
if (!NAME_PATTERN.test(value)) {
|
|
14
|
+
throw new Error(`Invalid project name: ${value}`);
|
|
15
|
+
}
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function normalizePackageName(value) {
|
|
19
|
+
return (value
|
|
20
|
+
.trim()
|
|
21
|
+
.toLowerCase()
|
|
22
|
+
.replace(/[^a-z0-9._-]+/g, "-")
|
|
23
|
+
.replace(/^[-_.]+/, "") || "origo-app");
|
|
24
|
+
}
|
|
25
|
+
export function resolveProjectTarget(projectInput, targetPathInput) {
|
|
26
|
+
const projectNameInput = projectInput.trim();
|
|
27
|
+
if (!projectNameInput) {
|
|
28
|
+
throw new Error("Project name is required");
|
|
29
|
+
}
|
|
30
|
+
const targetPath = (targetPathInput ?? projectNameInput).trim();
|
|
31
|
+
if (!targetPath) {
|
|
32
|
+
throw new Error("Project path is required");
|
|
33
|
+
}
|
|
34
|
+
const projectDirectory = path.resolve(process.cwd(), targetPath);
|
|
35
|
+
const hasExplicitTargetPath = Boolean(targetPathInput?.trim());
|
|
36
|
+
const projectName = !hasExplicitTargetPath && isPathLike(projectNameInput)
|
|
37
|
+
? normalizePackageName(path.basename(projectDirectory))
|
|
38
|
+
: validateProjectName(projectNameInput);
|
|
39
|
+
return { projectName, projectDirectory };
|
|
40
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
import { logger } from "../ui/logger.js";
|
|
4
|
+
const execFileAsync = promisify(execFile);
|
|
5
|
+
const versionCache = new Map();
|
|
6
|
+
async function mapWithConcurrency(items, limit, mapper) {
|
|
7
|
+
const results = new Array(items.length);
|
|
8
|
+
let nextIndex = 0;
|
|
9
|
+
await Promise.all(Array.from({ length: Math.min(limit, items.length) }, async () => {
|
|
10
|
+
while (nextIndex < items.length) {
|
|
11
|
+
const index = nextIndex;
|
|
12
|
+
nextIndex += 1;
|
|
13
|
+
results[index] = await mapper(items[index]);
|
|
14
|
+
}
|
|
15
|
+
}));
|
|
16
|
+
return results;
|
|
17
|
+
}
|
|
18
|
+
function encodePackageName(name) {
|
|
19
|
+
return name.startsWith("@")
|
|
20
|
+
? `@${encodeURIComponent(name.slice(1))}`
|
|
21
|
+
: encodeURIComponent(name);
|
|
22
|
+
}
|
|
23
|
+
function parseVersion(version) {
|
|
24
|
+
const match = /^v?(\d+)(?:\.(\d+))?(?:\.(\d+))?/.exec(version);
|
|
25
|
+
if (!match) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
return [Number(match[1]), Number(match[2] ?? 0), Number(match[3] ?? 0)];
|
|
29
|
+
}
|
|
30
|
+
function compareVersions(left, right) {
|
|
31
|
+
if (!left || !right) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
for (let index = 0; index < 3; index += 1) {
|
|
35
|
+
if (left[index] !== right[index]) {
|
|
36
|
+
return left[index] - right[index];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
function getRegistryUrl(options) {
|
|
42
|
+
return (options.registryUrl ??
|
|
43
|
+
process.env.NPM_CONFIG_REGISTRY ??
|
|
44
|
+
"https://registry.npmjs.org").replace(/\/$/, "");
|
|
45
|
+
}
|
|
46
|
+
async function npmView(name, options) {
|
|
47
|
+
const npm = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
48
|
+
const args = ["view", name, "version", "--json"];
|
|
49
|
+
if (options.registryUrl) {
|
|
50
|
+
args.push("--registry", getRegistryUrl(options));
|
|
51
|
+
}
|
|
52
|
+
const { stdout } = await execFileAsync(npm, args, {
|
|
53
|
+
timeout: options.timeoutMs ?? 20000,
|
|
54
|
+
maxBuffer: 1024 * 1024,
|
|
55
|
+
});
|
|
56
|
+
const parsed = JSON.parse(stdout);
|
|
57
|
+
if (Array.isArray(parsed)) {
|
|
58
|
+
return typeof parsed[0] === "string" ? parsed[0] : undefined;
|
|
59
|
+
}
|
|
60
|
+
return typeof parsed === "string" ? parsed : undefined;
|
|
61
|
+
}
|
|
62
|
+
async function fetchPackument(name, options) {
|
|
63
|
+
const url = `${getRegistryUrl(options)}/${encodePackageName(name)}`;
|
|
64
|
+
const response = await fetch(url, {
|
|
65
|
+
headers: { Accept: "application/vnd.npm.install-v1+json" },
|
|
66
|
+
signal: AbortSignal.timeout(options.timeoutMs ?? 20000),
|
|
67
|
+
});
|
|
68
|
+
if (!response.ok) {
|
|
69
|
+
throw new Error(`npm registry returned ${response.status}`);
|
|
70
|
+
}
|
|
71
|
+
return (await response.json());
|
|
72
|
+
}
|
|
73
|
+
async function findVersion(name, options) {
|
|
74
|
+
try {
|
|
75
|
+
const latest = await npmView(name, options);
|
|
76
|
+
if (latest) {
|
|
77
|
+
return latest;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
catch { }
|
|
81
|
+
const packument = await fetchPackument(name, options);
|
|
82
|
+
const versions = packument.versions ?? {};
|
|
83
|
+
const latest = packument["dist-tags"]?.latest;
|
|
84
|
+
const candidates = Object.keys(versions)
|
|
85
|
+
.filter((version) => !version.includes("-"))
|
|
86
|
+
.sort((left, right) => compareVersions(parseVersion(right), parseVersion(left)));
|
|
87
|
+
if (latest && !latest.includes("-")) {
|
|
88
|
+
candidates.unshift(latest);
|
|
89
|
+
}
|
|
90
|
+
for (const candidate of new Set(candidates)) {
|
|
91
|
+
if (!versions[candidate]?.deprecated) {
|
|
92
|
+
return candidate;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
throw new Error(`No version found for ${name}`);
|
|
96
|
+
}
|
|
97
|
+
export async function resolvePackageVersion(name, options = {}) {
|
|
98
|
+
const key = `${getRegistryUrl(options)}|${name}`;
|
|
99
|
+
const cached = versionCache.get(key);
|
|
100
|
+
if (cached) {
|
|
101
|
+
return cached;
|
|
102
|
+
}
|
|
103
|
+
const pending = (async () => {
|
|
104
|
+
let lastError;
|
|
105
|
+
for (let attempt = 0; attempt < 3; attempt += 1) {
|
|
106
|
+
try {
|
|
107
|
+
return await findVersion(name, options);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
lastError = error;
|
|
111
|
+
if (attempt < 2) {
|
|
112
|
+
await new Promise((resolve) => setTimeout(resolve, 250 * (attempt + 1)));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
throw lastError;
|
|
117
|
+
})().catch((error) => {
|
|
118
|
+
versionCache.delete(key);
|
|
119
|
+
throw error;
|
|
120
|
+
});
|
|
121
|
+
versionCache.set(key, pending);
|
|
122
|
+
return pending;
|
|
123
|
+
}
|
|
124
|
+
export async function resolvePackageVersions(names, options = {}) {
|
|
125
|
+
const entries = await mapWithConcurrency([...new Set(names)], 3, async (name) => {
|
|
126
|
+
try {
|
|
127
|
+
const version = await resolvePackageVersion(name, options);
|
|
128
|
+
return [name, `^${version}`];
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
132
|
+
logger.warn(`Could not resolve ${name}: ${reason}. Using latest.`);
|
|
133
|
+
return [name, "latest"];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
return Object.fromEntries(entries.sort(([left], [right]) => left.localeCompare(right)));
|
|
137
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const tailwindV3Dependencies = {
|
|
2
|
+
devDependencies: ["tailwindcss", "postcss", "autoprefixer"],
|
|
3
|
+
};
|
|
4
|
+
export const tailwindV4Dependencies = {
|
|
5
|
+
devDependencies: ["tailwindcss", "@tailwindcss/vite"],
|
|
6
|
+
};
|
|
7
|
+
export const tailwindDependencies = tailwindV4Dependencies;
|
|
8
|
+
export function getTailwindDependencies(version) {
|
|
9
|
+
return version === "v3" ? tailwindV3Dependencies : tailwindV4Dependencies;
|
|
10
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { resolveFrontendProfile } from "../../../../generators/frontend/resolvers/profile.js";
|
|
2
|
+
import { generateTailwind } from "./generator.js";
|
|
3
|
+
export const tailwindFeature = {
|
|
4
|
+
id: "tailwind",
|
|
5
|
+
name: "Tailwind CSS",
|
|
6
|
+
requires: ["react"],
|
|
7
|
+
requiresAny: ["tailwind", "tailwind-v3", "tailwind-v4"],
|
|
8
|
+
apply(context) {
|
|
9
|
+
generateTailwind(context, resolveFrontendProfile(context));
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { generateTailwindV3 } from "./versions/v3.js";
|
|
2
|
+
import { generateTailwindV4 } from "./versions/v4.js";
|
|
3
|
+
export function resolveTailwindVersion(context) {
|
|
4
|
+
return context.has("tailwind-v3") ? "v3" : "v4";
|
|
5
|
+
}
|
|
6
|
+
export function generateTailwind(context, profile) {
|
|
7
|
+
const version = resolveTailwindVersion(context);
|
|
8
|
+
if (version === "v3") {
|
|
9
|
+
generateTailwindV3(context, profile);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
generateTailwindV4(context, profile);
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { integrateTailwindRsbuild } from "./rsbuild.js";
|
|
2
|
+
import { integrateTailwindVite } from "./vite.js";
|
|
3
|
+
import { integrateTailwindWebpack } from "./webpack.js";
|
|
4
|
+
export function applyTailwindBundlerIntegration(context, profile) {
|
|
5
|
+
const integrations = {
|
|
6
|
+
vite: integrateTailwindVite,
|
|
7
|
+
webpack: integrateTailwindWebpack,
|
|
8
|
+
rsbuild: integrateTailwindRsbuild,
|
|
9
|
+
};
|
|
10
|
+
integrations[profile.bundler](context, profile);
|
|
11
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Node, SyntaxKind } from "ts-morph";
|
|
2
|
+
import { addArrayElement, addImport, getDefineConfigObject, } from "../../../../../composer/ast/index.js";
|
|
3
|
+
export function integrateTailwindVite(context, profile) {
|
|
4
|
+
const configPath = `vite.config.${profile.configExtension}`;
|
|
5
|
+
const source = context.getSourceFile(configPath);
|
|
6
|
+
addImport(source, "@tailwindcss/vite", "tailwindcss");
|
|
7
|
+
const object = getDefineConfigObject(source);
|
|
8
|
+
const plugins = object.getProperty("plugins");
|
|
9
|
+
if (!plugins || !Node.isPropertyAssignment(plugins)) {
|
|
10
|
+
throw new Error("plugins property not found");
|
|
11
|
+
}
|
|
12
|
+
const pluginsArray = plugins.getInitializerIfKind(SyntaxKind.ArrayLiteralExpression);
|
|
13
|
+
if (!pluginsArray) {
|
|
14
|
+
throw new Error("plugins must be an array");
|
|
15
|
+
}
|
|
16
|
+
addArrayElement(pluginsArray, "tailwindcss()");
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const tailwindCssImport = '@import "tailwindcss";';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export const defaultTailwindTheme = {
|
|
2
|
+
colors: {
|
|
3
|
+
brand: {
|
|
4
|
+
50: "#f5f0ff",
|
|
5
|
+
100: "#e9ddff",
|
|
6
|
+
300: "#b987ff",
|
|
7
|
+
500: "#781bff",
|
|
8
|
+
700: "#5a12bd",
|
|
9
|
+
900: "#2d075f",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
fontFamily: {
|
|
13
|
+
sans: ["Inter", "ui-sans-serif", "system-ui", "sans-serif"],
|
|
14
|
+
},
|
|
15
|
+
};
|
|
16
|
+
export function createTailwindV3Config(theme) {
|
|
17
|
+
return {
|
|
18
|
+
content: ["./index.html", "./src/**/*.{js,jsx,ts,tsx}"],
|
|
19
|
+
theme: {
|
|
20
|
+
extend: {
|
|
21
|
+
colors: theme.colors,
|
|
22
|
+
fontFamily: theme.fontFamily,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
plugins: [],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function renderTailwindV4Theme(theme) {
|
|
29
|
+
const declarations = [];
|
|
30
|
+
for (const [name, shades] of Object.entries(theme.colors)) {
|
|
31
|
+
for (const [shade, value] of Object.entries(shades)) {
|
|
32
|
+
declarations.push(` --color-${name}-${shade}: ${value};`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const [name, family] of Object.entries(theme.fontFamily)) {
|
|
36
|
+
declarations.push(` --font-${name}: ${family.join(", ")};`);
|
|
37
|
+
}
|
|
38
|
+
return `@theme {\n${declarations.join("\n")}\n}`;
|
|
39
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { addCssBlock, parseCss, renderCss, } from "../../../../../generators/frontend/css.js";
|
|
2
|
+
import { createTailwindV3Config, defaultTailwindTheme, } from "../templates/theme.js";
|
|
3
|
+
const CSS_DIRECTIVES = `@tailwind base;
|
|
4
|
+
@tailwind components;
|
|
5
|
+
@tailwind utilities;`;
|
|
6
|
+
export function generateTailwindV3(context, _profile) {
|
|
7
|
+
const cssPath = "src/index.css";
|
|
8
|
+
const document = parseCss(context.getTextFile(cssPath));
|
|
9
|
+
addCssBlock(document, CSS_DIRECTIVES);
|
|
10
|
+
context.addTextFile(cssPath, renderCss(document));
|
|
11
|
+
context.addTextFile("tailwind.config.js", `export default ${JSON.stringify(createTailwindV3Config(defaultTailwindTheme), null, 2)};\n`);
|
|
12
|
+
context.addTextFile("postcss.config.js", `export default {
|
|
13
|
+
plugins: {
|
|
14
|
+
tailwindcss: {},
|
|
15
|
+
autoprefixer: {},
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
`);
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { addCssBlock, addCssImport, parseCss, renderCss, } from "../../../../../generators/frontend/css.js";
|
|
2
|
+
import { applyTailwindBundlerIntegration } from "../integrations/index.js";
|
|
3
|
+
import { defaultTailwindTheme, renderTailwindV4Theme, } from "../templates/theme.js";
|
|
4
|
+
export function generateTailwindV4(context, profile) {
|
|
5
|
+
applyTailwindBundlerIntegration(context, profile);
|
|
6
|
+
const cssPath = "src/index.css";
|
|
7
|
+
const document = parseCss(context.getTextFile(cssPath));
|
|
8
|
+
addCssImport(document, '@import "tailwindcss";');
|
|
9
|
+
addCssBlock(document, renderTailwindV4Theme(defaultTailwindTheme));
|
|
10
|
+
context.addTextFile(cssPath, renderCss(document));
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { resolveFrontendProfile } from "../../../../generators/frontend/resolvers/profile.js";
|
|
2
|
+
import { generateShadcn } from "./generator.js";
|
|
3
|
+
export const shadcnFeature = {
|
|
4
|
+
id: "shadcn-ui",
|
|
5
|
+
name: "shadcn/ui",
|
|
6
|
+
requires: ["react", "shadcn-ui"],
|
|
7
|
+
requiresAny: ["tailwind", "tailwind-v3", "tailwind-v4"],
|
|
8
|
+
apply(context) {
|
|
9
|
+
generateShadcn(context, resolveFrontendProfile(context));
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { configureShadcnAlias } from "./patches/vite-config.js";
|
|
2
|
+
import { configureShadcnTsConfig } from "./patches/tsconfig.js";
|
|
3
|
+
import { createComponentsJson } from "./templates/components-json.js";
|
|
4
|
+
import { shadcnUtilsJavaScript, shadcnUtilsTypeScript, } from "./templates/lib-utils.js";
|
|
5
|
+
export function generateShadcn(context, profile) {
|
|
6
|
+
const isTypeScript = profile.isTypeScript;
|
|
7
|
+
context.addTextFile("components.json", createComponentsJson(isTypeScript));
|
|
8
|
+
context.addTextFile(`src/lib/utils.${isTypeScript ? "ts" : "js"}`, isTypeScript ? shadcnUtilsTypeScript : shadcnUtilsJavaScript);
|
|
9
|
+
configureShadcnAlias(context, profile);
|
|
10
|
+
if (isTypeScript) {
|
|
11
|
+
configureShadcnTsConfig(context);
|
|
12
|
+
}
|
|
13
|
+
}
|