swallowkit 1.0.0-beta.6 → 1.0.0-beta.7
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.ja.md +12 -6
- package/README.md +12 -6
- package/dist/cli/commands/dev.d.ts +8 -0
- package/dist/cli/commands/dev.d.ts.map +1 -1
- package/dist/cli/commands/dev.js +238 -30
- package/dist/cli/commands/dev.js.map +1 -1
- package/dist/cli/commands/init.d.ts +5 -0
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +723 -285
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/scaffold.d.ts +3 -0
- package/dist/cli/commands/scaffold.d.ts.map +1 -1
- package/dist/cli/commands/scaffold.js +181 -17
- package/dist/cli/commands/scaffold.js.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/core/config.d.ts +2 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +28 -0
- package/dist/core/config.js.map +1 -1
- package/dist/core/scaffold/functions-generator.d.ts +5 -0
- package/dist/core/scaffold/functions-generator.d.ts.map +1 -1
- package/dist/core/scaffold/functions-generator.js +431 -0
- package/dist/core/scaffold/functions-generator.js.map +1 -1
- package/dist/core/scaffold/model-parser.d.ts +1 -1
- package/dist/core/scaffold/model-parser.js +1 -1
- package/dist/core/scaffold/nextjs-generator.js +1 -1
- package/dist/core/scaffold/openapi-generator.d.ts +3 -0
- package/dist/core/scaffold/openapi-generator.d.ts.map +1 -0
- package/dist/core/scaffold/openapi-generator.js +190 -0
- package/dist/core/scaffold/openapi-generator.js.map +1 -0
- package/dist/database/base-model.d.ts +3 -3
- package/dist/database/base-model.js +3 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/package-manager.d.ts +2 -1
- package/dist/utils/package-manager.d.ts.map +1 -1
- package/dist/utils/package-manager.js +10 -6
- package/dist/utils/package-manager.js.map +1 -1
- package/package.json +2 -1
- package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +445 -0
- package/src/__tests__/__snapshots__/nextjs-generator.test.ts.snap +194 -0
- package/src/__tests__/__snapshots__/ui-generator.test.ts.snap +524 -0
- package/src/__tests__/config.test.ts +122 -0
- package/src/__tests__/dev.test.ts +42 -0
- package/src/__tests__/fixtures.ts +83 -0
- package/src/__tests__/functions-generator.test.ts +101 -0
- package/src/__tests__/init.test.ts +59 -0
- package/src/__tests__/nextjs-generator.test.ts +97 -0
- package/src/__tests__/openapi-generator.test.ts +43 -0
- package/src/__tests__/package-manager.test.ts +189 -0
- package/src/__tests__/scaffold.test.ts +39 -0
- package/src/__tests__/string-utils.test.ts +75 -0
- package/src/__tests__/ui-generator.test.ts +144 -0
- package/src/cli/commands/create-model.ts +141 -0
- package/src/cli/commands/dev.ts +794 -0
- package/src/cli/commands/index.ts +8 -0
- package/src/cli/commands/init.ts +3363 -0
- package/src/cli/commands/provision.ts +193 -0
- package/src/cli/commands/scaffold.ts +786 -0
- package/src/cli/index.ts +73 -0
- package/src/core/config.ts +244 -0
- package/src/core/scaffold/functions-generator.ts +674 -0
- package/src/core/scaffold/model-parser.ts +627 -0
- package/src/core/scaffold/nextjs-generator.ts +217 -0
- package/src/core/scaffold/openapi-generator.ts +212 -0
- package/src/core/scaffold/ui-generator.ts +945 -0
- package/src/database/base-model.ts +184 -0
- package/src/database/client.ts +140 -0
- package/src/database/repository.ts +104 -0
- package/src/database/runtime-check.ts +25 -0
- package/src/index.ts +27 -0
- package/src/types/index.ts +45 -0
- package/src/utils/package-manager.ts +229 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { execSync } from "child_process";
|
|
4
|
+
import { BackendLanguage } from "../types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Supported package managers
|
|
8
|
+
*/
|
|
9
|
+
export type PackageManager = "npm" | "pnpm";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Package manager command mappings
|
|
13
|
+
*/
|
|
14
|
+
export interface PackageManagerCommands {
|
|
15
|
+
/** The binary name: "npm" or "pnpm" */
|
|
16
|
+
name: PackageManager;
|
|
17
|
+
/** Install all dependencies: "pnpm install" / "npm install" */
|
|
18
|
+
install: string;
|
|
19
|
+
/** Install with lockfile: "pnpm install --frozen-lockfile" / "npm ci" */
|
|
20
|
+
ci: string;
|
|
21
|
+
/** Add a dependency: "pnpm add" / "npm install" */
|
|
22
|
+
add: string;
|
|
23
|
+
/** Add a dev dependency: "pnpm add -D" / "npm install -D" */
|
|
24
|
+
addDev: string;
|
|
25
|
+
/** Add a global dependency: "pnpm add -g" / "npm install -g" */
|
|
26
|
+
addGlobal: string;
|
|
27
|
+
/** Execute a package binary: "pnpm exec" / "npx" */
|
|
28
|
+
exec: string;
|
|
29
|
+
/** Download & execute: "pnpm dlx" / "npx" */
|
|
30
|
+
dlx: string;
|
|
31
|
+
/** Run a script: "pnpm run" / "npm run" */
|
|
32
|
+
run: string;
|
|
33
|
+
/** Run a script with filter: "pnpm run --filter <ws>" / "npm run --workspace=<ws>" */
|
|
34
|
+
runFilter: (workspace: string) => string;
|
|
35
|
+
/** Start script: "pnpm start" / "npm start" */
|
|
36
|
+
start: string;
|
|
37
|
+
/** Install production only (in temp dir for CI): "pnpm install --prod" / "npm install --omit=dev" */
|
|
38
|
+
installProd: string;
|
|
39
|
+
/** create-next-app flag: "--use-pnpm" / (none for npm) */
|
|
40
|
+
createNextAppFlag: string | null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the full command mapping for the given package manager
|
|
45
|
+
*/
|
|
46
|
+
export function getCommands(pm: PackageManager): PackageManagerCommands {
|
|
47
|
+
if (pm === "pnpm") {
|
|
48
|
+
return {
|
|
49
|
+
name: "pnpm",
|
|
50
|
+
install: "pnpm install",
|
|
51
|
+
ci: "pnpm install --frozen-lockfile",
|
|
52
|
+
add: "pnpm add",
|
|
53
|
+
addDev: "pnpm add -D",
|
|
54
|
+
addGlobal: "pnpm add -g",
|
|
55
|
+
exec: "pnpm exec",
|
|
56
|
+
dlx: "pnpm dlx",
|
|
57
|
+
run: "pnpm run",
|
|
58
|
+
runFilter: (ws) => `pnpm run --filter ${ws}`,
|
|
59
|
+
start: "pnpm start",
|
|
60
|
+
installProd: "pnpm install --prod",
|
|
61
|
+
createNextAppFlag: "--use-pnpm",
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// npm
|
|
66
|
+
return {
|
|
67
|
+
name: "npm",
|
|
68
|
+
install: "npm install",
|
|
69
|
+
ci: "npm ci",
|
|
70
|
+
add: "npm install",
|
|
71
|
+
addDev: "npm install -D",
|
|
72
|
+
addGlobal: "npm install -g",
|
|
73
|
+
exec: "npx",
|
|
74
|
+
dlx: "npx",
|
|
75
|
+
run: "npm run",
|
|
76
|
+
runFilter: (ws) => `npm run --workspace=${ws}`,
|
|
77
|
+
start: "npm start",
|
|
78
|
+
installProd: "npm install --omit=dev",
|
|
79
|
+
createNextAppFlag: null,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Detect the preferred package manager for new project initialisation.
|
|
85
|
+
*
|
|
86
|
+
* Strategy (pnpm-preferred):
|
|
87
|
+
* 1. If pnpm is installed on the system → always use pnpm
|
|
88
|
+
* (even when invoked via `npx`, since `npx` is often used out of habit)
|
|
89
|
+
* 2. Otherwise → npm
|
|
90
|
+
*
|
|
91
|
+
* This is intentionally independent of `npm_config_user_agent` so that
|
|
92
|
+
* `npx swallowkit init` still creates a pnpm project when pnpm is available.
|
|
93
|
+
*/
|
|
94
|
+
export function detectFromUserAgent(): PackageManager {
|
|
95
|
+
return isPnpmInstalled() ? "pnpm" : "npm";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check whether pnpm is available on the system PATH.
|
|
100
|
+
*/
|
|
101
|
+
function isPnpmInstalled(): boolean {
|
|
102
|
+
try {
|
|
103
|
+
execSync("pnpm --version", { stdio: "ignore" });
|
|
104
|
+
return true;
|
|
105
|
+
} catch {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Detect the package manager used in an existing project directory
|
|
112
|
+
* by checking for lockfiles.
|
|
113
|
+
*
|
|
114
|
+
* Priority: pnpm-lock.yaml > package-lock.json > fallback to detectFromUserAgent()
|
|
115
|
+
*/
|
|
116
|
+
export function detectFromProject(projectDir?: string): PackageManager {
|
|
117
|
+
const dir = projectDir || process.cwd();
|
|
118
|
+
|
|
119
|
+
if (fs.existsSync(path.join(dir, "pnpm-lock.yaml"))) {
|
|
120
|
+
return "pnpm";
|
|
121
|
+
}
|
|
122
|
+
if (fs.existsSync(path.join(dir, "package-lock.json"))) {
|
|
123
|
+
return "npm";
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// No lockfile found — fall back to user agent detection
|
|
127
|
+
return detectFromUserAgent();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Get spawn arguments (command + args array) for the package manager.
|
|
132
|
+
* Useful when calling spawn() directly.
|
|
133
|
+
*
|
|
134
|
+
* Examples:
|
|
135
|
+
* spawnArgs("pnpm", ["add", "next@latest"]) => { cmd: "pnpm", args: ["add", "next@latest"] }
|
|
136
|
+
* spawnArgs("npm", ["add", "next@latest"]) => { cmd: "npm", args: ["install", "next@latest"] }
|
|
137
|
+
*/
|
|
138
|
+
export function spawnArgs(
|
|
139
|
+
pm: PackageManager,
|
|
140
|
+
args: string[]
|
|
141
|
+
): { cmd: string; args: string[] } {
|
|
142
|
+
return { cmd: pm, args };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Workspace configuration helpers
|
|
147
|
+
*/
|
|
148
|
+
export function getWorkspaceConfig(pm: PackageManager, workspaces: string[]) {
|
|
149
|
+
if (pm === "pnpm") {
|
|
150
|
+
return {
|
|
151
|
+
/** pnpm uses pnpm-workspace.yaml */
|
|
152
|
+
type: "file" as const,
|
|
153
|
+
filename: "pnpm-workspace.yaml",
|
|
154
|
+
content: `packages:\n${workspaces.map((w) => ` - ${w}`).join("\n")}\n`,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// npm uses "workspaces" field in package.json
|
|
159
|
+
return {
|
|
160
|
+
type: "packageJson" as const,
|
|
161
|
+
field: "workspaces",
|
|
162
|
+
value: workspaces,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* CI/CD setup step for GitHub Actions
|
|
168
|
+
*/
|
|
169
|
+
export function getCiSetupStep(pm: PackageManager): string {
|
|
170
|
+
if (pm === "pnpm") {
|
|
171
|
+
return ` - name: Setup pnpm
|
|
172
|
+
uses: pnpm/action-setup@v4`;
|
|
173
|
+
}
|
|
174
|
+
// npm: no extra setup needed (comes with Node.js)
|
|
175
|
+
return "";
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* CI/CD setup steps for Azure Pipelines
|
|
180
|
+
*/
|
|
181
|
+
export function getAzurePipelinesSetup(pm: PackageManager): string {
|
|
182
|
+
if (pm === "pnpm") {
|
|
183
|
+
return ` - script: |
|
|
184
|
+
corepack enable
|
|
185
|
+
corepack prepare pnpm@latest --activate
|
|
186
|
+
displayName: 'Setup pnpm'`;
|
|
187
|
+
}
|
|
188
|
+
// npm: no extra step needed
|
|
189
|
+
return "";
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Build script for generated package.json (depends on workspace command syntax)
|
|
194
|
+
*/
|
|
195
|
+
export function getBuildScript(pm: PackageManager): string {
|
|
196
|
+
const copyStandaloneAssets = `node -e "const fs=require('fs');fs.mkdirSync('.next/standalone/.next',{recursive:true});if(fs.existsSync('.next/static'))fs.cpSync('.next/static','.next/standalone/.next/static',{recursive:true});if(fs.existsSync('public'))fs.cpSync('public','.next/standalone/public',{recursive:true});"`;
|
|
197
|
+
|
|
198
|
+
if (pm === "pnpm") {
|
|
199
|
+
return `pnpm run --filter shared build && next build --webpack && ${copyStandaloneAssets}`;
|
|
200
|
+
}
|
|
201
|
+
return `npm run --workspace=shared build && next build --webpack && ${copyStandaloneAssets}`;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Functions prestart script
|
|
206
|
+
*/
|
|
207
|
+
export function getFunctionsPrestart(pm: PackageManager): string {
|
|
208
|
+
if (pm === "pnpm") {
|
|
209
|
+
return "pnpm run build";
|
|
210
|
+
}
|
|
211
|
+
return "npm run build";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Functions:start script for root package.json
|
|
216
|
+
*/
|
|
217
|
+
export function getFunctionsStartScript(
|
|
218
|
+
pm: PackageManager,
|
|
219
|
+
backendLanguage: BackendLanguage = "typescript"
|
|
220
|
+
): string {
|
|
221
|
+
if (backendLanguage === "typescript") {
|
|
222
|
+
if (pm === "pnpm") {
|
|
223
|
+
return "cd functions && pnpm start";
|
|
224
|
+
}
|
|
225
|
+
return "cd functions && npm start";
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return "cd functions && func start";
|
|
229
|
+
}
|