@kithinji/pod 1.0.21 → 1.0.23

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.
Files changed (40) hide show
  1. package/README.md +453 -0
  2. package/dist/main.js +408 -218
  3. package/dist/main.js.map +2 -2
  4. package/dist/types/deploy/deploy.d.ts.map +1 -1
  5. package/package.json +31 -8
  6. package/build.js +0 -22
  7. package/src/add/component/component.ts +0 -496
  8. package/src/add/component/index.ts +0 -1
  9. package/src/add/index.ts +0 -3
  10. package/src/add/module/index.ts +0 -1
  11. package/src/add/module/module.ts +0 -545
  12. package/src/add/new/index.ts +0 -198
  13. package/src/config/config.ts +0 -141
  14. package/src/config/index.ts +0 -1
  15. package/src/deploy/deploy.ts +0 -592
  16. package/src/deploy/index.ts +0 -1
  17. package/src/dev/index.ts +0 -1
  18. package/src/dev/project.ts +0 -45
  19. package/src/dev/server.ts +0 -191
  20. package/src/docker/docker.ts +0 -697
  21. package/src/docker/index.ts +0 -1
  22. package/src/macros/expand_macros.ts +0 -791
  23. package/src/macros/index.ts +0 -2
  24. package/src/macros/macro_executer.ts +0 -189
  25. package/src/main.ts +0 -106
  26. package/src/plugins/analyzers/graph.ts +0 -279
  27. package/src/plugins/css/index.ts +0 -25
  28. package/src/plugins/generators/generate_controller.ts +0 -308
  29. package/src/plugins/generators/generate_rsc.ts +0 -274
  30. package/src/plugins/generators/generate_server_component.ts +0 -455
  31. package/src/plugins/generators/tsx_server_stub.ts +0 -315
  32. package/src/plugins/index.ts +0 -3
  33. package/src/plugins/my.ts +0 -282
  34. package/src/plugins/transformers/j2d.ts +0 -1080
  35. package/src/store/index.ts +0 -1
  36. package/src/store/store.ts +0 -44
  37. package/src/utils/cases.ts +0 -15
  38. package/src/utils/create.ts +0 -26
  39. package/src/utils/index.ts +0 -2
  40. package/tsconfig.json +0 -27
@@ -1,2 +0,0 @@
1
- export * from "./expand_macros";
2
- export * from "./macro_executer";
@@ -1,189 +0,0 @@
1
- import * as vm from "node:vm";
2
- import * as esbuild from "esbuild";
3
- import * as path from "node:path";
4
- import Module from "node:module";
5
- import * as fs from "node:fs";
6
-
7
- type MacroFunction = Function & { name: string };
8
- type LoadedMacros = Record<string, MacroFunction>;
9
-
10
- export class MacroExecutor {
11
- private cache = new Map<string, LoadedMacros>();
12
-
13
- getMacro(specifier: string, macroName?: string): MacroFunction {
14
- if (!this.cache.has(specifier)) {
15
- this.load(specifier);
16
- }
17
- const macros = this.cache.get(specifier)!;
18
- if (macroName) {
19
- const fn = macros[macroName];
20
- if (!fn) {
21
- throw new Error(`Macro "${macroName}" not found in ${specifier}`);
22
- }
23
- return fn;
24
- }
25
- const names = Object.keys(macros);
26
- if (names.length === 1) {
27
- return macros[names[0]];
28
- }
29
- if (macros.default) {
30
- return macros.default;
31
- }
32
- throw new Error(`Multiple macros in ${specifier}: ${names.join(", ")}`);
33
- }
34
-
35
- private load(specifier: string) {
36
- const requireFromHere = Module.createRequire(
37
- process.cwd() + "/package.json"
38
- );
39
- const entry = requireFromHere.resolve(specifier);
40
-
41
- const { outputFiles } = esbuild.buildSync({
42
- entryPoints: [entry],
43
- bundle: true,
44
- write: false,
45
- platform: "node",
46
- format: "cjs",
47
- external: [
48
- ...Module.builtinModules,
49
- ...Module.builtinModules.map((m) => `node:${m}`),
50
- ],
51
- target: "node18",
52
- mainFields: ["module", "main"],
53
- conditions: ["node", "import", "require"],
54
- packages: "bundle",
55
- logLevel: "warning",
56
- });
57
-
58
- const code = outputFiles[0].text;
59
- const sandboxRequire = Module.createRequire(entry);
60
-
61
- const sandbox: any = {
62
- // Module system
63
- module: { exports: {} },
64
- exports: {},
65
- require: sandboxRequire,
66
-
67
- console,
68
- Buffer,
69
- URL,
70
- URLSearchParams,
71
- TextEncoder,
72
- TextDecoder,
73
- atob,
74
- btoa,
75
-
76
- __filename: entry,
77
- __dirname: path.dirname(entry),
78
-
79
- process: {
80
- env: process.env,
81
- cwd: process.cwd,
82
- version: process.version,
83
- versions: process.versions,
84
- platform: process.platform,
85
- arch: process.arch,
86
- argv: process.argv,
87
- execPath: process.execPath,
88
- pid: process.pid,
89
- },
90
-
91
- setTimeout,
92
- setInterval,
93
- setImmediate,
94
- clearTimeout,
95
- clearInterval,
96
- clearImmediate,
97
-
98
- Promise,
99
-
100
- Object,
101
- Array,
102
- String,
103
- Number,
104
- Boolean,
105
- Date,
106
- Math,
107
- JSON,
108
- RegExp,
109
- Error,
110
- TypeError,
111
- RangeError,
112
- SyntaxError,
113
- Map,
114
- Set,
115
- WeakMap,
116
- WeakSet,
117
- Symbol,
118
- BigInt,
119
- Proxy,
120
- Reflect,
121
- };
122
-
123
- sandbox.global = sandbox;
124
- sandbox.globalThis = sandbox;
125
-
126
- const context = vm.createContext(sandbox, {
127
- name: `macro-${path.basename(entry)}`,
128
- codeGeneration: {
129
- strings: true,
130
- wasm: false,
131
- },
132
- });
133
-
134
- try {
135
- const script = new vm.Script(code, {
136
- filename: entry,
137
- lineOffset: 0,
138
- columnOffset: 0,
139
- });
140
-
141
- script.runInContext(context, {
142
- breakOnSigint: true,
143
- });
144
- } catch (error) {
145
- throw new Error(
146
- `Failed to execute macro from ${specifier}: ${
147
- error instanceof Error ? error.message : String(error)
148
- }`
149
- );
150
- }
151
-
152
- const macros: LoadedMacros = {};
153
- const exports = sandbox.module.exports;
154
-
155
- if (typeof exports === "function") {
156
- macros.default = exports;
157
- } else if (typeof exports === "object" && exports !== null) {
158
- for (const [name, value] of Object.entries(exports)) {
159
- if (typeof value === "function" && name.endsWith("$")) {
160
- macros[name] = value as MacroFunction;
161
- }
162
- }
163
-
164
- if (typeof exports.default === "function") {
165
- macros.default = exports.default;
166
- }
167
- }
168
-
169
- if (!Object.keys(macros).length) {
170
- throw new Error(`No macros found in ${specifier}`);
171
- }
172
-
173
- this.cache.set(specifier, macros);
174
- }
175
-
176
- clearCache(specifier?: string) {
177
- if (specifier) {
178
- this.cache.delete(specifier);
179
- } else {
180
- this.cache.clear();
181
- }
182
- }
183
- }
184
-
185
- const macroExecutor = new MacroExecutor();
186
-
187
- export function macroExecuter(): MacroExecutor {
188
- return macroExecutor;
189
- }
package/src/main.ts DELETED
@@ -1,106 +0,0 @@
1
- #!/usr/bin/env node
2
- import { Command } from "commander";
3
- import { startDevServer } from "./dev";
4
-
5
- import * as store from "./store";
6
- export { store };
7
-
8
- import * as config from "./config";
9
- export { config };
10
-
11
- export * from "./config/config";
12
-
13
- import * as macros from "./macros";
14
- export { macros };
15
-
16
- export * from "./macros/expand_macros";
17
-
18
- import * as plugins from "./plugins";
19
- export { plugins };
20
- export * from "./plugins/css";
21
-
22
- import { addComponent, addNew } from "./add";
23
- import { addFeature } from "./add/module";
24
-
25
- import path from "path";
26
- import { execSync } from "child_process";
27
- import { dockerize } from "./docker";
28
- import { deploy } from "./deploy";
29
- import chalk from "chalk";
30
-
31
- const program = new Command();
32
-
33
- program.name("pod").description("Pod cli tool").version("1.0.21");
34
-
35
- program
36
- .command("new <name>")
37
- .description("Start a new Pod Project")
38
- .action(async (name: string) => {
39
- await addNew(name);
40
-
41
- const appDir = path.resolve(process.cwd(), name);
42
-
43
- const shell =
44
- process.platform === "win32"
45
- ? process.env.ComSpec || "cmd.exe"
46
- : "/bin/sh";
47
-
48
- console.log("Installing dependencies...");
49
- execSync("npm install", { stdio: "inherit", cwd: appDir, shell });
50
-
51
- console.log("Starting development server...");
52
- execSync("npm run dev", { stdio: "inherit", cwd: appDir, shell });
53
-
54
- console.log(`All done! Your app "${name}" is running in development mode.`);
55
- });
56
-
57
- program
58
- .command("dev")
59
- .description("Start Pod development server")
60
- .action(async (opts) => {
61
- await startDevServer();
62
- });
63
-
64
- program
65
- .command("add <type> <name>")
66
- .description("Add a component (c) or a feature (f)")
67
- .action(async (type, name) => {
68
- try {
69
- if (type === "c") {
70
- await addComponent(name);
71
- } else if (type === "f") {
72
- await addFeature(name);
73
- } else {
74
- console.error("❌ Unknown type. Use 'c' or 'f'.");
75
- }
76
- } catch (err: any) {
77
- console.error("❌ Error:", err.message);
78
- }
79
- });
80
-
81
- program
82
- .command("dockerize <env>")
83
- .description("Dockerize a pod project.")
84
- .action(async (env) => {
85
- try {
86
- await dockerize(env);
87
- } catch (err: any) {
88
- console.error("❌ Error:", err.message);
89
- }
90
- });
91
-
92
- program
93
- .command("deploy")
94
- .description("Deploy to a target environment")
95
- .argument("<target>", "Target environment (e.g., ec2)")
96
- .option("--force-install", "Force reinstallation even if already installed")
97
- .action(async (target: string, options: { forceEnsure?: boolean }) => {
98
- try {
99
- await deploy(target, options);
100
- } catch (error: any) {
101
- console.error(chalk.red(error.message));
102
- process.exit(1);
103
- }
104
- });
105
-
106
- program.parse(process.argv);
@@ -1,279 +0,0 @@
1
- import { parseSync } from "@swc/core";
2
- import * as fs from "fs";
3
- import * as path from "path";
4
- import type { Module, Decorator } from "@swc/core";
5
- import { Store } from "@/store";
6
-
7
- type SymbolKind =
8
- | "class"
9
- | "function"
10
- | "variable"
11
- | "interface"
12
- | "type"
13
- | "enum"
14
- | "namespace"
15
- | "unknown";
16
-
17
- interface SymbolInfo {
18
- name: string;
19
- kind: SymbolKind;
20
- decorators?: string[];
21
- isDefault?: boolean;
22
- }
23
-
24
- interface ImportInfo {
25
- sourcePath: string;
26
- resolvedPath: string | null;
27
- symbols: SymbolInfo[];
28
- }
29
-
30
- export interface FileNode {
31
- filePath: string;
32
- isTsx: boolean;
33
- directive: "public" | "interactive" | null;
34
- imports: ImportInfo[];
35
- exports: SymbolInfo[];
36
- }
37
-
38
- export interface DependencyGraph {
39
- [filePath: string]: FileNode;
40
- }
41
-
42
- function resolveFilePath(fromFile: string, importPath: string): string | null {
43
- if (!importPath.startsWith(".")) return null;
44
-
45
- const dir = path.dirname(fromFile);
46
- const basePath = path.resolve(dir, importPath);
47
-
48
- const extensions = ["", ".ts", ".tsx", ".js", ".jsx"];
49
- for (const ext of extensions) {
50
- const fullPath = basePath + ext;
51
- if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile())
52
- return fullPath;
53
- }
54
-
55
- const indexFiles = ["/index.ts", "/index.tsx", "/index.js", "/index.jsx"];
56
- for (const indexFile of indexFiles) {
57
- const fullPath = basePath + indexFile;
58
- if (fs.existsSync(fullPath) && fs.statSync(fullPath).isFile())
59
- return fullPath;
60
- }
61
-
62
- return null;
63
- }
64
-
65
- function extractDecorators(decorators?: Decorator[]): string[] {
66
- if (!decorators) return [];
67
- return decorators
68
- .map((d) => {
69
- const exp = d.expression;
70
- if (exp.type === "CallExpression" && exp.callee.type === "Identifier")
71
- return exp.callee.value;
72
- if (exp.type === "Identifier") return exp.value;
73
- return "unknown";
74
- })
75
- .filter((n) => n !== "unknown");
76
- }
77
-
78
- function extractDirective(ast: Module): "public" | "interactive" | null {
79
- for (const item of ast.body) {
80
- if (
81
- item.type === "ExpressionStatement" &&
82
- item.expression.type === "StringLiteral"
83
- ) {
84
- const val = item.expression.value;
85
- if (val === "use public") return "public";
86
- if (val === "use interactive") return "interactive";
87
- } else {
88
- break;
89
- }
90
- }
91
- return null;
92
- }
93
-
94
- function extractImports(
95
- ast: Module
96
- ): Array<{ path: string; specifiers: any[] }> {
97
- const imports: Array<{ path: string; specifiers: any[] }> = [];
98
- for (const item of ast.body) {
99
- if (item.type === "ImportDeclaration") {
100
- imports.push({ path: item.source.value, specifiers: item.specifiers });
101
- }
102
- }
103
- return imports;
104
- }
105
-
106
- function extractExports(
107
- ast: Module,
108
- currentFile: string,
109
- graph: DependencyGraph,
110
- processFile: (fp: string) => void
111
- ): SymbolInfo[] {
112
- const exports: SymbolInfo[] = [];
113
-
114
- for (const item of ast.body) {
115
- if (item.type === "ExportDeclaration" && item.declaration) {
116
- const decl = item.declaration;
117
-
118
- if (decl.type === "ClassDeclaration" && decl.identifier) {
119
- const decorators = extractDecorators(decl.decorators);
120
- exports.push({
121
- name: decl.identifier.value,
122
- kind: "class",
123
- decorators: decorators.length > 0 ? decorators : undefined,
124
- });
125
- } else if (decl.type === "FunctionDeclaration" && decl.identifier) {
126
- exports.push({ name: decl.identifier.value, kind: "function" });
127
- } else if (decl.type === "VariableDeclaration") {
128
- for (const declarator of decl.declarations) {
129
- if (declarator.id.type === "Identifier") {
130
- exports.push({ name: declarator.id.value, kind: "variable" });
131
- }
132
- }
133
- } else if (decl.type === "TsInterfaceDeclaration") {
134
- exports.push({ name: decl.id.value, kind: "interface" });
135
- } else if (decl.type === "TsTypeAliasDeclaration") {
136
- exports.push({ name: decl.id.value, kind: "type" });
137
- } else if (decl.type === "TsEnumDeclaration") {
138
- exports.push({ name: decl.id.value, kind: "enum" });
139
- }
140
- }
141
-
142
- if (item.type === "ExportNamedDeclaration" && item.source) {
143
- const resolved = resolveFilePath(currentFile, item.source.value);
144
- if (resolved) {
145
- processFile(resolved);
146
- const sourceExports = graph[resolved]?.exports || [];
147
- for (const spec of item.specifiers) {
148
- if (spec.type === "ExportSpecifier") {
149
- const exp = sourceExports.find((e) => e.name === spec.orig.value);
150
- exports.push({
151
- name: spec.exported?.value || spec.orig.value,
152
- kind: exp?.kind || "unknown",
153
- decorators: exp?.decorators,
154
- });
155
- }
156
- }
157
- }
158
- }
159
-
160
- if (item.type === "ExportAllDeclaration") {
161
- const resolved = resolveFilePath(currentFile, item.source.value);
162
- if (resolved) {
163
- processFile(resolved);
164
- const sourceExports = graph[resolved]?.exports || [];
165
- for (const exp of sourceExports) {
166
- exports.push({ ...exp });
167
- }
168
- }
169
- }
170
-
171
- if (item.type === "ExportDefaultDeclaration") {
172
- const decl = item.decl;
173
- let kind: SymbolKind = "unknown";
174
- let decorators: string[] | undefined;
175
-
176
- if (decl.type === "ClassExpression") {
177
- kind = "class";
178
- decorators = extractDecorators(decl.decorators);
179
- } else if (decl.type === "FunctionExpression") {
180
- kind = "function";
181
- } else if (decl.type === "TsInterfaceDeclaration") {
182
- kind = "interface";
183
- }
184
-
185
- exports.push({
186
- name: "default",
187
- kind,
188
- isDefault: true,
189
- decorators: decorators?.length ? decorators : undefined,
190
- });
191
- }
192
-
193
- if (item.type === "ExportDefaultExpression") {
194
- exports.push({ name: "default", kind: "unknown", isDefault: true });
195
- }
196
- }
197
-
198
- return exports;
199
- }
200
-
201
- export function buildGraph(entryPoints: string[]): DependencyGraph {
202
- const graph: DependencyGraph = {};
203
- const visited = new Set<string>();
204
-
205
- function processFile(filePath: string): void {
206
- const allowedExt = [".ts", ".tsx", ".js", ".jsx"];
207
- if (!allowedExt.includes(path.extname(filePath))) return;
208
- if (visited.has(filePath)) return;
209
- visited.add(filePath);
210
-
211
- if (!fs.existsSync(filePath)) {
212
- console.warn(`File not found: ${filePath}`);
213
- return;
214
- }
215
-
216
- const isTsx = [".tsx", ".jsx"].includes(path.extname(filePath));
217
- const store = Store.getInstance();
218
- const newCode = store.get<string>(filePath);
219
- const content = newCode ? newCode[0] : fs.readFileSync(filePath, "utf-8");
220
-
221
- const ast = parseSync(content, {
222
- syntax: "typescript",
223
- tsx: isTsx,
224
- decorators: true,
225
- });
226
-
227
- const directive = extractDirective(ast);
228
- const rawImports = extractImports(ast);
229
- const exports = extractExports(ast, filePath, graph, processFile);
230
-
231
- for (const { path: importPath } of rawImports) {
232
- const resolved = resolveFilePath(filePath, importPath);
233
- if (resolved) processFile(resolved);
234
- }
235
-
236
- const imports: ImportInfo[] = rawImports.map(
237
- ({ path: importPath, specifiers }) => {
238
- const resolvedPath = resolveFilePath(filePath, importPath);
239
- const sourceExports =
240
- resolvedPath && graph[resolvedPath]
241
- ? graph[resolvedPath].exports
242
- : [];
243
- const symbols: SymbolInfo[] = [];
244
-
245
- for (const spec of specifiers) {
246
- if (spec.type === "ImportDefaultSpecifier") {
247
- const def = sourceExports.find((e) => e.isDefault);
248
- symbols.push({
249
- name: spec.local.value,
250
- kind: def?.kind || "unknown",
251
- decorators: def?.decorators,
252
- isDefault: true,
253
- });
254
- } else if (spec.type === "ImportNamespaceSpecifier") {
255
- symbols.push({ name: spec.local.value, kind: "namespace" });
256
- } else if (spec.type === "ImportSpecifier") {
257
- const importedName = spec.imported
258
- ? spec.imported.value
259
- : spec.local.value;
260
- const exp = sourceExports.find((e) => e.name === importedName);
261
- symbols.push({
262
- name: importedName,
263
- kind: exp?.kind || "unknown",
264
- decorators: exp?.decorators,
265
- });
266
- }
267
- }
268
-
269
- return { sourcePath: importPath, resolvedPath, symbols };
270
- }
271
- );
272
-
273
- graph[filePath] = { filePath, isTsx, directive, imports, exports };
274
- }
275
-
276
- for (const entry of entryPoints) processFile(path.resolve(entry));
277
-
278
- return graph;
279
- }
@@ -1,25 +0,0 @@
1
- import { Store } from "@/store";
2
- import { PluginBuild } from "esbuild";
3
- import * as fs from "fs";
4
-
5
- export function stylePlugin(store: Store) {
6
- return {
7
- name: "style",
8
- setup(build: PluginBuild) {
9
- build.onEnd(() => {
10
- const styleRules = store.get("style_rules");
11
-
12
- if (!styleRules || styleRules.length === 0) {
13
- console.log("No style rules generated");
14
- return;
15
- }
16
-
17
- const allRules = styleRules.flat();
18
- const uniqueRules = [...new Set(allRules)];
19
-
20
- const cssOutput = uniqueRules.join("\n");
21
- fs.writeFileSync("public/index.css", cssOutput);
22
- });
23
- },
24
- };
25
- }