@kithinji/pod 1.0.31 → 1.0.32
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/dist/main.js +349 -211
- package/dist/main.js.map +4 -4
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -11,7 +11,7 @@ import { Command } from "commander";
|
|
|
11
11
|
// src/dev/server.ts
|
|
12
12
|
import * as esbuild2 from "esbuild";
|
|
13
13
|
import { spawn } from "child_process";
|
|
14
|
-
import * as
|
|
14
|
+
import * as fs7 from "fs/promises";
|
|
15
15
|
import { WebSocketServer, WebSocket } from "ws";
|
|
16
16
|
|
|
17
17
|
// src/config/config.ts
|
|
@@ -55,8 +55,8 @@ async function loadJsConfig(configPath) {
|
|
|
55
55
|
}
|
|
56
56
|
async function loadTsConfig(configPath) {
|
|
57
57
|
try {
|
|
58
|
-
const
|
|
59
|
-
const result = await
|
|
58
|
+
const esbuild4 = await import("esbuild");
|
|
59
|
+
const result = await esbuild4.build({
|
|
60
60
|
entryPoints: [configPath],
|
|
61
61
|
bundle: true,
|
|
62
62
|
platform: "node",
|
|
@@ -93,7 +93,9 @@ function getDefaultConfig() {
|
|
|
93
93
|
build: {
|
|
94
94
|
outDir: "dist",
|
|
95
95
|
sourcemap: true,
|
|
96
|
-
minify: false
|
|
96
|
+
minify: false,
|
|
97
|
+
types: false,
|
|
98
|
+
decorators: false
|
|
97
99
|
},
|
|
98
100
|
plugins: [],
|
|
99
101
|
client_plugins: [],
|
|
@@ -121,6 +123,7 @@ var plugins_exports = {};
|
|
|
121
123
|
__export(plugins_exports, {
|
|
122
124
|
buildGraph: () => buildGraph,
|
|
123
125
|
stylePlugin: () => stylePlugin,
|
|
126
|
+
useCompilePlugin: () => useCompilePlugin,
|
|
124
127
|
useMyPlugin: () => useMyPlugin
|
|
125
128
|
});
|
|
126
129
|
|
|
@@ -137,6 +140,7 @@ __export(macros_exports, {
|
|
|
137
140
|
expandMacros: () => expandMacros,
|
|
138
141
|
extractValueFromNode: () => extractValueFromNode,
|
|
139
142
|
getGlobalMacroGraph: () => getGlobalMacroGraph,
|
|
143
|
+
macroContext: () => macroContext,
|
|
140
144
|
macroExecuter: () => macroExecuter,
|
|
141
145
|
resetGlobalMacroGraph: () => resetGlobalMacroGraph
|
|
142
146
|
});
|
|
@@ -353,6 +357,22 @@ var Store = class _Store {
|
|
|
353
357
|
};
|
|
354
358
|
|
|
355
359
|
// src/macros/expand_macros.ts
|
|
360
|
+
var currentMacroContext = null;
|
|
361
|
+
function macroContext() {
|
|
362
|
+
if (!currentMacroContext) {
|
|
363
|
+
throw new Error("macroContext() called outside of macro execution");
|
|
364
|
+
}
|
|
365
|
+
return currentMacroContext;
|
|
366
|
+
}
|
|
367
|
+
function withMacroContext(context2, fn) {
|
|
368
|
+
const previousContext = currentMacroContext;
|
|
369
|
+
currentMacroContext = context2;
|
|
370
|
+
try {
|
|
371
|
+
return fn();
|
|
372
|
+
} finally {
|
|
373
|
+
currentMacroContext = previousContext;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
356
376
|
var MacroDependencyGraph = class {
|
|
357
377
|
constructor(projectRoot) {
|
|
358
378
|
this.nodes = /* @__PURE__ */ new Map();
|
|
@@ -406,17 +426,17 @@ var MacroDependencyGraph = class {
|
|
|
406
426
|
const visited = /* @__PURE__ */ new Set();
|
|
407
427
|
const inProgress = /* @__PURE__ */ new Set();
|
|
408
428
|
const sorted = [];
|
|
409
|
-
const visit = (key,
|
|
429
|
+
const visit = (key, path17 = []) => {
|
|
410
430
|
if (visited.has(key)) return;
|
|
411
431
|
if (inProgress.has(key)) {
|
|
412
|
-
const cycle = [...
|
|
432
|
+
const cycle = [...path17, key].join(" -> ");
|
|
413
433
|
throw new Error(`Circular macro dependency detected: ${cycle}`);
|
|
414
434
|
}
|
|
415
435
|
const node = this.nodes.get(key);
|
|
416
436
|
if (!node) return;
|
|
417
437
|
inProgress.add(key);
|
|
418
438
|
for (const depKey of node.dependencies) {
|
|
419
|
-
visit(depKey, [...
|
|
439
|
+
visit(depKey, [...path17, key]);
|
|
420
440
|
}
|
|
421
441
|
inProgress.delete(key);
|
|
422
442
|
visited.add(key);
|
|
@@ -812,7 +832,7 @@ async function expandMacros(source, filePath, projectRoot = process.cwd()) {
|
|
|
812
832
|
macroNode.sourceFile,
|
|
813
833
|
compilerOptions
|
|
814
834
|
);
|
|
815
|
-
const
|
|
835
|
+
const macroContext2 = {
|
|
816
836
|
node,
|
|
817
837
|
sourceFile: macroNode.sourceFile,
|
|
818
838
|
ts,
|
|
@@ -832,7 +852,10 @@ async function expandMacros(source, filePath, projectRoot = process.cwd()) {
|
|
|
832
852
|
resolveIdentifier: resolver.resolveIdentifierToNode
|
|
833
853
|
};
|
|
834
854
|
try {
|
|
835
|
-
const result2 =
|
|
855
|
+
const result2 = withMacroContext(
|
|
856
|
+
macroContext2,
|
|
857
|
+
() => macro(...node.arguments)
|
|
858
|
+
);
|
|
836
859
|
if (!result2 || typeof result2 !== "object" || !("kind" in result2)) {
|
|
837
860
|
throw new Error(`Macro '${name}' must return a TypeScript AST node`);
|
|
838
861
|
}
|
|
@@ -878,7 +901,7 @@ async function expandMacros(source, filePath, projectRoot = process.cwd()) {
|
|
|
878
901
|
sourceFile,
|
|
879
902
|
compilerOptions
|
|
880
903
|
);
|
|
881
|
-
const
|
|
904
|
+
const macroContext2 = {
|
|
882
905
|
node,
|
|
883
906
|
sourceFile,
|
|
884
907
|
ts,
|
|
@@ -898,7 +921,10 @@ async function expandMacros(source, filePath, projectRoot = process.cwd()) {
|
|
|
898
921
|
resolveIdentifier: resolver.resolveIdentifierToNode
|
|
899
922
|
};
|
|
900
923
|
try {
|
|
901
|
-
const result2 =
|
|
924
|
+
const result2 = withMacroContext(
|
|
925
|
+
macroContext2,
|
|
926
|
+
() => macro(...node.arguments)
|
|
927
|
+
);
|
|
902
928
|
if (!result2 || typeof result2 !== "object" || !("kind" in result2)) {
|
|
903
929
|
throw new Error(
|
|
904
930
|
`Macro '${name}' must return a TypeScript AST node`
|
|
@@ -1629,16 +1655,16 @@ var ASTUtilities = class {
|
|
|
1629
1655
|
});
|
|
1630
1656
|
return cloned;
|
|
1631
1657
|
}
|
|
1632
|
-
walkAndTransform(node,
|
|
1658
|
+
walkAndTransform(node, transform3) {
|
|
1633
1659
|
if (!node || typeof node !== "object") return;
|
|
1634
|
-
|
|
1660
|
+
transform3(node);
|
|
1635
1661
|
for (const key in node) {
|
|
1636
1662
|
if (this.shouldSkipKey(key)) continue;
|
|
1637
1663
|
const value = node[key];
|
|
1638
1664
|
if (Array.isArray(value)) {
|
|
1639
|
-
value.forEach((item) => this.walkAndTransform(item,
|
|
1665
|
+
value.forEach((item) => this.walkAndTransform(item, transform3));
|
|
1640
1666
|
} else if (value && typeof value === "object") {
|
|
1641
|
-
this.walkAndTransform(value,
|
|
1667
|
+
this.walkAndTransform(value, transform3);
|
|
1642
1668
|
}
|
|
1643
1669
|
}
|
|
1644
1670
|
}
|
|
@@ -1798,22 +1824,22 @@ var ElementTransformer = class {
|
|
|
1798
1824
|
this.jsxUtils = jsxUtils;
|
|
1799
1825
|
this.observableManager = observableManager;
|
|
1800
1826
|
}
|
|
1801
|
-
transformElement(
|
|
1802
|
-
if (this.t.isJSXFragment(
|
|
1827
|
+
transformElement(path17, scope, context2) {
|
|
1828
|
+
if (this.t.isJSXFragment(path17.node)) {
|
|
1803
1829
|
return this.transformFragment(
|
|
1804
|
-
|
|
1830
|
+
path17,
|
|
1805
1831
|
scope,
|
|
1806
1832
|
context2
|
|
1807
1833
|
);
|
|
1808
1834
|
}
|
|
1809
1835
|
return this.transformJSXElement(
|
|
1810
|
-
|
|
1836
|
+
path17,
|
|
1811
1837
|
scope,
|
|
1812
1838
|
context2
|
|
1813
1839
|
);
|
|
1814
1840
|
}
|
|
1815
|
-
transformJSXElement(
|
|
1816
|
-
const jsxElement =
|
|
1841
|
+
transformJSXElement(path17, scope, context2) {
|
|
1842
|
+
const jsxElement = path17.node;
|
|
1817
1843
|
const tag = this.jsxUtils.getComponentName(jsxElement.openingElement.name);
|
|
1818
1844
|
const isComponent = this.jsxUtils.isComponentTag(tag);
|
|
1819
1845
|
if (isComponent && tag) {
|
|
@@ -1928,7 +1954,7 @@ var ElementTransformer = class {
|
|
|
1928
1954
|
}
|
|
1929
1955
|
return { id: elId, statements };
|
|
1930
1956
|
}
|
|
1931
|
-
transformFragment(
|
|
1957
|
+
transformFragment(path17, scope, context2) {
|
|
1932
1958
|
const fragId = scope.generateUidIdentifier("frag");
|
|
1933
1959
|
const statements = [];
|
|
1934
1960
|
statements.push(
|
|
@@ -1946,7 +1972,7 @@ var ElementTransformer = class {
|
|
|
1946
1972
|
])
|
|
1947
1973
|
);
|
|
1948
1974
|
this.processDOMChildren(
|
|
1949
|
-
|
|
1975
|
+
path17.node.children,
|
|
1950
1976
|
fragId,
|
|
1951
1977
|
statements,
|
|
1952
1978
|
scope,
|
|
@@ -2335,7 +2361,7 @@ function j2d({ types: t }) {
|
|
|
2335
2361
|
name: "jsx-to-dom",
|
|
2336
2362
|
visitor: {
|
|
2337
2363
|
Program: {
|
|
2338
|
-
exit(
|
|
2364
|
+
exit(path17, state) {
|
|
2339
2365
|
if (state.helpersImported) return;
|
|
2340
2366
|
const helpers = [
|
|
2341
2367
|
{ local: "$insert", imported: "insert" },
|
|
@@ -2346,7 +2372,7 @@ function j2d({ types: t }) {
|
|
|
2346
2372
|
{ local: "$effect", imported: "effect" }
|
|
2347
2373
|
];
|
|
2348
2374
|
for (const helper of helpers) {
|
|
2349
|
-
|
|
2375
|
+
path17.unshiftContainer(
|
|
2350
2376
|
"body",
|
|
2351
2377
|
t.importDeclaration(
|
|
2352
2378
|
[
|
|
@@ -2362,10 +2388,10 @@ function j2d({ types: t }) {
|
|
|
2362
2388
|
state.helpersImported = true;
|
|
2363
2389
|
}
|
|
2364
2390
|
},
|
|
2365
|
-
ClassMethod(
|
|
2366
|
-
if (
|
|
2391
|
+
ClassMethod(path17) {
|
|
2392
|
+
if (path17.getData("processed")) return;
|
|
2367
2393
|
let hasJSX = false;
|
|
2368
|
-
|
|
2394
|
+
path17.traverse({
|
|
2369
2395
|
JSXElement() {
|
|
2370
2396
|
hasJSX = true;
|
|
2371
2397
|
},
|
|
@@ -2374,11 +2400,11 @@ function j2d({ types: t }) {
|
|
|
2374
2400
|
}
|
|
2375
2401
|
});
|
|
2376
2402
|
if (!hasJSX) return;
|
|
2377
|
-
|
|
2378
|
-
const body =
|
|
2403
|
+
path17.setData("processed", true);
|
|
2404
|
+
const body = path17.node.body;
|
|
2379
2405
|
if (!t.isBlockStatement(body)) return;
|
|
2380
2406
|
const observables = /* @__PURE__ */ new Map();
|
|
2381
|
-
|
|
2407
|
+
path17.traverse({
|
|
2382
2408
|
JSXElement(jsxPath) {
|
|
2383
2409
|
observableManager.collectObservables(
|
|
2384
2410
|
jsxPath.node,
|
|
@@ -2402,7 +2428,7 @@ function j2d({ types: t }) {
|
|
|
2402
2428
|
const observableSignals = /* @__PURE__ */ new Map();
|
|
2403
2429
|
const signalDeclarations = [];
|
|
2404
2430
|
for (const [key, observable] of observables) {
|
|
2405
|
-
const signalId =
|
|
2431
|
+
const signalId = path17.scope.generateUidIdentifier("sig");
|
|
2406
2432
|
observableSignals.set(key, signalId);
|
|
2407
2433
|
signalDeclarations.push(
|
|
2408
2434
|
t.variableDeclaration("const", [
|
|
@@ -2420,7 +2446,7 @@ function j2d({ types: t }) {
|
|
|
2420
2446
|
astUtils.insertBeforeReturn(body.body, signalDeclarations);
|
|
2421
2447
|
}
|
|
2422
2448
|
const context2 = { observables, observableSignals };
|
|
2423
|
-
|
|
2449
|
+
path17.traverse({
|
|
2424
2450
|
JSXElement(jsxPath) {
|
|
2425
2451
|
if (jsxPath.getData("processed")) return;
|
|
2426
2452
|
jsxPath.setData("processed", true);
|
|
@@ -2729,8 +2755,8 @@ function stringifyType3(typeNode) {
|
|
|
2729
2755
|
}
|
|
2730
2756
|
function generateStubCode(stub) {
|
|
2731
2757
|
const className = stub.name;
|
|
2732
|
-
const
|
|
2733
|
-
if (
|
|
2758
|
+
const build2 = stub.methods.find((p) => p.name == "build");
|
|
2759
|
+
if (build2 == void 0) {
|
|
2734
2760
|
throw new Error("Component has no build function");
|
|
2735
2761
|
}
|
|
2736
2762
|
const decoratorsStr = stub.decorators.length > 0 ? stub.decorators.join("\n") + "\n" : "";
|
|
@@ -2953,8 +2979,8 @@ async function swcTransform(source, pathStr, tsx = false, react) {
|
|
|
2953
2979
|
resolveDir
|
|
2954
2980
|
};
|
|
2955
2981
|
}
|
|
2956
|
-
function parseFileMetadata(source,
|
|
2957
|
-
const isTsx =
|
|
2982
|
+
function parseFileMetadata(source, path17) {
|
|
2983
|
+
const isTsx = path17.endsWith(".tsx");
|
|
2958
2984
|
const isClientFile = source.startsWith('"use client"') || source.startsWith("'use client'");
|
|
2959
2985
|
const isPublicFile = source.startsWith('"use public"') || source.startsWith("'use public'");
|
|
2960
2986
|
let directive = null;
|
|
@@ -2962,7 +2988,7 @@ function parseFileMetadata(source, path16) {
|
|
|
2962
2988
|
else if (isPublicFile) directive = "public";
|
|
2963
2989
|
return {
|
|
2964
2990
|
source,
|
|
2965
|
-
path:
|
|
2991
|
+
path: path17,
|
|
2966
2992
|
isTsx,
|
|
2967
2993
|
directive,
|
|
2968
2994
|
isPublicFile,
|
|
@@ -2970,58 +2996,58 @@ function parseFileMetadata(source, path16) {
|
|
|
2970
2996
|
};
|
|
2971
2997
|
}
|
|
2972
2998
|
var ServerBuildTransformer = class {
|
|
2973
|
-
async transformPublicFile(source,
|
|
2974
|
-
const controllerCode = generateController(
|
|
2999
|
+
async transformPublicFile(source, path17) {
|
|
3000
|
+
const controllerCode = generateController(path17, source);
|
|
2975
3001
|
if (controllerCode) {
|
|
2976
3002
|
source = `${source}
|
|
2977
3003
|
|
|
2978
3004
|
${controllerCode}
|
|
2979
3005
|
`;
|
|
2980
3006
|
}
|
|
2981
|
-
return swcTransform(source,
|
|
3007
|
+
return swcTransform(source, path17);
|
|
2982
3008
|
}
|
|
2983
|
-
async transformRegularTypeScript(source,
|
|
3009
|
+
async transformRegularTypeScript(source, path17, isPublic) {
|
|
2984
3010
|
if (isPublic) {
|
|
2985
|
-
return this.transformPublicFile(source,
|
|
3011
|
+
return this.transformPublicFile(source, path17);
|
|
2986
3012
|
}
|
|
2987
|
-
return swcTransform(source,
|
|
3013
|
+
return swcTransform(source, path17);
|
|
2988
3014
|
}
|
|
2989
|
-
async transformServerTsx(source,
|
|
2990
|
-
return swcTransform(source,
|
|
3015
|
+
async transformServerTsx(source, path17) {
|
|
3016
|
+
return swcTransform(source, path17, true, {
|
|
2991
3017
|
runtime: "automatic",
|
|
2992
3018
|
importSource: "@kithinji/orca"
|
|
2993
3019
|
});
|
|
2994
3020
|
}
|
|
2995
|
-
async transformClientTsxStub(source,
|
|
2996
|
-
const stubSource = generateServerStub(
|
|
2997
|
-
return swcTransform(stubSource,
|
|
3021
|
+
async transformClientTsxStub(source, path17) {
|
|
3022
|
+
const stubSource = generateServerStub(path17, source);
|
|
3023
|
+
return swcTransform(stubSource, path17);
|
|
2998
3024
|
}
|
|
2999
3025
|
async process(metadata, onClientFound) {
|
|
3000
3026
|
const expandedSource = await expandMacros(metadata.source, metadata.path);
|
|
3001
3027
|
const expandedMetadata = { ...metadata, source: expandedSource };
|
|
3002
|
-
const { source, path:
|
|
3028
|
+
const { source, path: path17, isTsx, isClientFile, isPublicFile } = expandedMetadata;
|
|
3003
3029
|
if (isTsx) {
|
|
3004
3030
|
if (isClientFile) {
|
|
3005
|
-
onClientFound(
|
|
3006
|
-
const clientCode = await this.transformClientTsxStub(source,
|
|
3031
|
+
onClientFound(path17);
|
|
3032
|
+
const clientCode = await this.transformClientTsxStub(source, path17);
|
|
3007
3033
|
const store = Store.getInstance();
|
|
3008
|
-
store.set(
|
|
3034
|
+
store.set(path17, clientCode.contents);
|
|
3009
3035
|
return clientCode;
|
|
3010
3036
|
}
|
|
3011
|
-
return this.transformServerTsx(source,
|
|
3037
|
+
return this.transformServerTsx(source, path17);
|
|
3012
3038
|
}
|
|
3013
|
-
return this.transformRegularTypeScript(source,
|
|
3039
|
+
return this.transformRegularTypeScript(source, path17, isPublicFile);
|
|
3014
3040
|
}
|
|
3015
3041
|
};
|
|
3016
3042
|
var ClientBuildTransformer = class {
|
|
3017
|
-
async transformClientTsx(source,
|
|
3018
|
-
const swcResult = await swcTransform(source,
|
|
3043
|
+
async transformClientTsx(source, path17) {
|
|
3044
|
+
const swcResult = await swcTransform(source, path17, true, {
|
|
3019
3045
|
runtime: "preserve"
|
|
3020
3046
|
});
|
|
3021
3047
|
const babelResult = await babel.transformAsync(
|
|
3022
3048
|
swcResult.contents,
|
|
3023
3049
|
{
|
|
3024
|
-
filename:
|
|
3050
|
+
filename: path17,
|
|
3025
3051
|
sourceType: "module",
|
|
3026
3052
|
plugins: [j2d],
|
|
3027
3053
|
parserOpts: {
|
|
@@ -3037,37 +3063,37 @@ var ClientBuildTransformer = class {
|
|
|
3037
3063
|
resolveDir: swcResult.resolveDir
|
|
3038
3064
|
};
|
|
3039
3065
|
}
|
|
3040
|
-
async transformServerComponent(node, source,
|
|
3041
|
-
const scSource = generateServerComponent(
|
|
3042
|
-
return swcTransform(scSource,
|
|
3066
|
+
async transformServerComponent(node, source, path17) {
|
|
3067
|
+
const scSource = generateServerComponent(path17, source);
|
|
3068
|
+
return swcTransform(scSource, path17);
|
|
3043
3069
|
}
|
|
3044
|
-
async transformPublicFileRpc(node, source,
|
|
3045
|
-
const stubSource = generateRpcStub(
|
|
3046
|
-
return swcTransform(stubSource,
|
|
3070
|
+
async transformPublicFileRpc(node, source, path17) {
|
|
3071
|
+
const stubSource = generateRpcStub(path17, source);
|
|
3072
|
+
return swcTransform(stubSource, path17);
|
|
3047
3073
|
}
|
|
3048
|
-
async transformSharedCode(source,
|
|
3049
|
-
return swcTransform(source,
|
|
3074
|
+
async transformSharedCode(source, path17) {
|
|
3075
|
+
return swcTransform(source, path17);
|
|
3050
3076
|
}
|
|
3051
3077
|
async process(node, metadata) {
|
|
3052
3078
|
const expandedSource = await expandMacros(metadata.source, metadata.path);
|
|
3053
3079
|
const expandedMetadata = { ...metadata, source: expandedSource };
|
|
3054
|
-
const { source, path:
|
|
3080
|
+
const { source, path: path17, isTsx, directive } = expandedMetadata;
|
|
3055
3081
|
if (isTsx) {
|
|
3056
3082
|
if (directive === "client") {
|
|
3057
|
-
return this.transformClientTsx(source,
|
|
3083
|
+
return this.transformClientTsx(source, path17);
|
|
3058
3084
|
} else if (directive === null) {
|
|
3059
|
-
return this.transformServerComponent(node, source,
|
|
3085
|
+
return this.transformServerComponent(node, source, path17);
|
|
3060
3086
|
} else {
|
|
3061
3087
|
throw new Error(
|
|
3062
|
-
`Unexpected directive "${directive}" for TSX file: ${
|
|
3088
|
+
`Unexpected directive "${directive}" for TSX file: ${path17}`
|
|
3063
3089
|
);
|
|
3064
3090
|
}
|
|
3065
3091
|
}
|
|
3066
3092
|
if (directive === "public") {
|
|
3067
|
-
return this.transformPublicFileRpc(node, source,
|
|
3093
|
+
return this.transformPublicFileRpc(node, source, path17);
|
|
3068
3094
|
}
|
|
3069
3095
|
if (directive === null) {
|
|
3070
|
-
return this.transformSharedCode(source,
|
|
3096
|
+
return this.transformSharedCode(source, path17);
|
|
3071
3097
|
}
|
|
3072
3098
|
return {
|
|
3073
3099
|
contents: source,
|
|
@@ -3080,8 +3106,8 @@ function useMyPlugin(options) {
|
|
|
3080
3106
|
const clientTransformer = new ClientBuildTransformer();
|
|
3081
3107
|
return {
|
|
3082
3108
|
name: "Orca",
|
|
3083
|
-
setup(
|
|
3084
|
-
|
|
3109
|
+
setup(build2) {
|
|
3110
|
+
build2.onLoad(
|
|
3085
3111
|
{ filter: /\.tsx?$/ },
|
|
3086
3112
|
async (args) => {
|
|
3087
3113
|
const source = await fs2.readFile(args.path, "utf8");
|
|
@@ -3307,8 +3333,8 @@ import * as fs4 from "fs";
|
|
|
3307
3333
|
function stylePlugin(store) {
|
|
3308
3334
|
return {
|
|
3309
3335
|
name: "style",
|
|
3310
|
-
setup(
|
|
3311
|
-
|
|
3336
|
+
setup(build2) {
|
|
3337
|
+
build2.onEnd(() => {
|
|
3312
3338
|
const styleRules = store.get("style_rules");
|
|
3313
3339
|
if (!styleRules || styleRules.length === 0) {
|
|
3314
3340
|
console.log("No style rules generated");
|
|
@@ -3323,16 +3349,90 @@ function stylePlugin(store) {
|
|
|
3323
3349
|
};
|
|
3324
3350
|
}
|
|
3325
3351
|
|
|
3326
|
-
// src/
|
|
3352
|
+
// src/plugins/compile.ts
|
|
3327
3353
|
import * as fs5 from "fs/promises";
|
|
3354
|
+
import * as path8 from "path";
|
|
3355
|
+
import { transform as transform2 } from "@swc/core";
|
|
3356
|
+
function parseFileMetadata2(source, path17, decorators) {
|
|
3357
|
+
return {
|
|
3358
|
+
source,
|
|
3359
|
+
path: path17,
|
|
3360
|
+
decorators
|
|
3361
|
+
};
|
|
3362
|
+
}
|
|
3363
|
+
async function swcTransform2(source, pathStr, tsx = false, react) {
|
|
3364
|
+
const resolveDir = path8.dirname(pathStr);
|
|
3365
|
+
const swcResult = await transform2(source, {
|
|
3366
|
+
filename: pathStr,
|
|
3367
|
+
jsc: {
|
|
3368
|
+
parser: {
|
|
3369
|
+
syntax: "typescript",
|
|
3370
|
+
tsx,
|
|
3371
|
+
decorators: true
|
|
3372
|
+
},
|
|
3373
|
+
transform: {
|
|
3374
|
+
legacyDecorator: true,
|
|
3375
|
+
decoratorMetadata: true,
|
|
3376
|
+
react
|
|
3377
|
+
},
|
|
3378
|
+
target: "esnext"
|
|
3379
|
+
},
|
|
3380
|
+
isModule: true
|
|
3381
|
+
});
|
|
3382
|
+
return {
|
|
3383
|
+
contents: swcResult.code,
|
|
3384
|
+
loader: "js",
|
|
3385
|
+
resolveDir
|
|
3386
|
+
};
|
|
3387
|
+
}
|
|
3388
|
+
var BuildTransformer = class {
|
|
3389
|
+
async transformTypeScript(source, path17) {
|
|
3390
|
+
return swcTransform2(source, path17);
|
|
3391
|
+
}
|
|
3392
|
+
async process(metadata) {
|
|
3393
|
+
const expandedSource = await expandMacros(metadata.source, metadata.path);
|
|
3394
|
+
const expandedMetadata = { ...metadata, source: expandedSource };
|
|
3395
|
+
const { source, path: path17, decorators } = expandedMetadata;
|
|
3396
|
+
if (!decorators) {
|
|
3397
|
+
return {
|
|
3398
|
+
contents: source,
|
|
3399
|
+
loader: "ts"
|
|
3400
|
+
};
|
|
3401
|
+
}
|
|
3402
|
+
return this.transformTypeScript(source, path17);
|
|
3403
|
+
}
|
|
3404
|
+
};
|
|
3405
|
+
function useCompilePlugin(options) {
|
|
3406
|
+
const transformer = new BuildTransformer();
|
|
3407
|
+
return {
|
|
3408
|
+
name: "Orca",
|
|
3409
|
+
setup(build2) {
|
|
3410
|
+
build2.onLoad(
|
|
3411
|
+
{ filter: /\.tsx?$/ },
|
|
3412
|
+
async (args) => {
|
|
3413
|
+
const source = await fs5.readFile(args.path, "utf8");
|
|
3414
|
+
const metadata = parseFileMetadata2(
|
|
3415
|
+
source,
|
|
3416
|
+
args.path,
|
|
3417
|
+
options.decorators
|
|
3418
|
+
);
|
|
3419
|
+
return transformer.process(metadata);
|
|
3420
|
+
}
|
|
3421
|
+
);
|
|
3422
|
+
}
|
|
3423
|
+
};
|
|
3424
|
+
}
|
|
3425
|
+
|
|
3426
|
+
// src/html/index.ts
|
|
3427
|
+
import * as fs6 from "fs/promises";
|
|
3328
3428
|
var HtmlPreprocessor = class {
|
|
3329
3429
|
constructor(options = {}) {
|
|
3330
3430
|
this.options = options;
|
|
3331
3431
|
}
|
|
3332
3432
|
async processFile(inputPath, outputPath) {
|
|
3333
|
-
const html = await
|
|
3433
|
+
const html = await fs6.readFile(inputPath, "utf-8");
|
|
3334
3434
|
const processed = await this.process(html);
|
|
3335
|
-
await
|
|
3435
|
+
await fs6.writeFile(outputPath, processed, "utf-8");
|
|
3336
3436
|
}
|
|
3337
3437
|
async process(html) {
|
|
3338
3438
|
let result = html;
|
|
@@ -3469,8 +3569,8 @@ export async function navigate(event, url) {
|
|
|
3469
3569
|
function createVirtualModulePlugin(virtualFiles) {
|
|
3470
3570
|
return {
|
|
3471
3571
|
name: "virtual-module",
|
|
3472
|
-
setup(
|
|
3473
|
-
|
|
3572
|
+
setup(build2) {
|
|
3573
|
+
build2.onResolve({ filter: /^virtual:/ }, (args) => {
|
|
3474
3574
|
if (virtualFiles[args.path]) {
|
|
3475
3575
|
return {
|
|
3476
3576
|
path: args.path,
|
|
@@ -3478,7 +3578,7 @@ function createVirtualModulePlugin(virtualFiles) {
|
|
|
3478
3578
|
};
|
|
3479
3579
|
}
|
|
3480
3580
|
});
|
|
3481
|
-
|
|
3581
|
+
build2.onLoad({ filter: /.*/, namespace: "virtual" }, (args) => {
|
|
3482
3582
|
const virtualFile = virtualFiles[args.path];
|
|
3483
3583
|
if (virtualFile) {
|
|
3484
3584
|
return {
|
|
@@ -3535,7 +3635,7 @@ var HotReloadManager = class {
|
|
|
3535
3635
|
};
|
|
3536
3636
|
async function copyAndProcessHtml(hotReloadPort, preprocessorOptions) {
|
|
3537
3637
|
try {
|
|
3538
|
-
await
|
|
3638
|
+
await fs7.mkdir("public", { recursive: true });
|
|
3539
3639
|
const preprocessor = new HtmlPreprocessor({
|
|
3540
3640
|
transformers: [createHotReloadTransformer(hotReloadPort)],
|
|
3541
3641
|
injectScripts: ["./navigate.js"],
|
|
@@ -3552,15 +3652,15 @@ async function copyAndProcessHtml(hotReloadPort, preprocessorOptions) {
|
|
|
3552
3652
|
}
|
|
3553
3653
|
async function cleanDirectories() {
|
|
3554
3654
|
await Promise.all([
|
|
3555
|
-
|
|
3556
|
-
|
|
3655
|
+
fs7.rm("dist", { recursive: true, force: true }),
|
|
3656
|
+
fs7.rm("public", { recursive: true, force: true })
|
|
3557
3657
|
]);
|
|
3558
3658
|
}
|
|
3559
3659
|
function createRestartServerPlugin(serverProcess, onServerBuildComplete, hotReloadManager) {
|
|
3560
3660
|
return {
|
|
3561
3661
|
name: "restart-server",
|
|
3562
|
-
setup(
|
|
3563
|
-
|
|
3662
|
+
setup(build2) {
|
|
3663
|
+
build2.onEnd((result) => {
|
|
3564
3664
|
if (result.errors.length > 0) {
|
|
3565
3665
|
console.error(
|
|
3566
3666
|
`Server build failed with ${result.errors.length} error(s)`
|
|
@@ -3661,8 +3761,8 @@ async function startDevServer() {
|
|
|
3661
3761
|
}),
|
|
3662
3762
|
{
|
|
3663
3763
|
name: "client-build-logger",
|
|
3664
|
-
setup(
|
|
3665
|
-
|
|
3764
|
+
setup(build2) {
|
|
3765
|
+
build2.onEnd((result) => {
|
|
3666
3766
|
if (result.errors.length > 0) {
|
|
3667
3767
|
console.error(
|
|
3668
3768
|
`Client build failed with ${result.errors.length} error(s)`
|
|
@@ -3701,6 +3801,7 @@ async function startDevServer() {
|
|
|
3701
3801
|
minify: config.build?.minify ?? false,
|
|
3702
3802
|
plugins: [
|
|
3703
3803
|
...config.plugins?.map((cb) => cb(store)) || [],
|
|
3804
|
+
...config.server_plugins?.map((cb) => cb(store)) || [],
|
|
3704
3805
|
useMyPlugin({
|
|
3705
3806
|
isServerBuild: true,
|
|
3706
3807
|
onClientFound: async (filePath) => {
|
|
@@ -3756,8 +3857,8 @@ __export(config_exports, {
|
|
|
3756
3857
|
});
|
|
3757
3858
|
|
|
3758
3859
|
// src/add/component/component.ts
|
|
3759
|
-
import * as
|
|
3760
|
-
import * as
|
|
3860
|
+
import * as fs8 from "fs";
|
|
3861
|
+
import * as path9 from "path";
|
|
3761
3862
|
import * as ts2 from "typescript";
|
|
3762
3863
|
var ComponentDefinition = class {
|
|
3763
3864
|
};
|
|
@@ -3923,40 +4024,40 @@ Processing dependencies for "${name}": [${component.dependencies.join(
|
|
|
3923
4024
|
addComponent(dependency, processedComponents);
|
|
3924
4025
|
}
|
|
3925
4026
|
}
|
|
3926
|
-
const componentModulePath =
|
|
4027
|
+
const componentModulePath = path9.join(
|
|
3927
4028
|
process.cwd(),
|
|
3928
4029
|
"src/component/component.module.ts"
|
|
3929
4030
|
);
|
|
3930
|
-
const componentPath =
|
|
4031
|
+
const componentPath = path9.join(
|
|
3931
4032
|
process.cwd(),
|
|
3932
4033
|
`src/component/component/${name}.component.tsx`
|
|
3933
4034
|
);
|
|
3934
|
-
const componentDir =
|
|
3935
|
-
const appModulePath =
|
|
3936
|
-
if (!
|
|
3937
|
-
const moduleDir =
|
|
3938
|
-
if (!
|
|
3939
|
-
|
|
4035
|
+
const componentDir = path9.dirname(componentPath);
|
|
4036
|
+
const appModulePath = path9.join(process.cwd(), "src/app/app.module.ts");
|
|
4037
|
+
if (!fs8.existsSync(componentModulePath)) {
|
|
4038
|
+
const moduleDir = path9.dirname(componentModulePath);
|
|
4039
|
+
if (!fs8.existsSync(moduleDir)) {
|
|
4040
|
+
fs8.mkdirSync(moduleDir, { recursive: true });
|
|
3940
4041
|
}
|
|
3941
|
-
|
|
4042
|
+
fs8.writeFileSync(componentModulePath, createModule(), "utf-8");
|
|
3942
4043
|
}
|
|
3943
|
-
if (!
|
|
3944
|
-
|
|
4044
|
+
if (!fs8.existsSync(componentDir)) {
|
|
4045
|
+
fs8.mkdirSync(componentDir, { recursive: true });
|
|
3945
4046
|
}
|
|
3946
|
-
if (!
|
|
3947
|
-
|
|
4047
|
+
if (!fs8.existsSync(componentPath)) {
|
|
4048
|
+
fs8.writeFileSync(componentPath, component.generate(), "utf-8");
|
|
3948
4049
|
console.log(`Created ${name}.component.tsx`);
|
|
3949
4050
|
} else {
|
|
3950
4051
|
console.log(`${name}.component.tsx already exists, skipping file creation`);
|
|
3951
4052
|
}
|
|
3952
|
-
const moduleContent =
|
|
4053
|
+
const moduleContent = fs8.readFileSync(componentModulePath, "utf-8");
|
|
3953
4054
|
const updatedModule = updateModuleWithComponent(moduleContent, name);
|
|
3954
|
-
|
|
3955
|
-
if (
|
|
3956
|
-
const appModuleContent =
|
|
4055
|
+
fs8.writeFileSync(componentModulePath, updatedModule, "utf-8");
|
|
4056
|
+
if (fs8.existsSync(appModulePath)) {
|
|
4057
|
+
const appModuleContent = fs8.readFileSync(appModulePath, "utf-8");
|
|
3957
4058
|
const updatedAppModule = ensureComponentModuleImported(appModuleContent);
|
|
3958
4059
|
if (updatedAppModule !== appModuleContent) {
|
|
3959
|
-
|
|
4060
|
+
fs8.writeFileSync(appModulePath, updatedAppModule, "utf-8");
|
|
3960
4061
|
}
|
|
3961
4062
|
}
|
|
3962
4063
|
}
|
|
@@ -4142,28 +4243,28 @@ function toPascalCase(str) {
|
|
|
4142
4243
|
}
|
|
4143
4244
|
|
|
4144
4245
|
// src/utils/create.ts
|
|
4145
|
-
import * as
|
|
4146
|
-
import * as
|
|
4246
|
+
import * as fs9 from "fs";
|
|
4247
|
+
import * as path10 from "path";
|
|
4147
4248
|
function createStructure(basePath, entry) {
|
|
4148
|
-
|
|
4249
|
+
fs9.mkdirSync(basePath, { recursive: true });
|
|
4149
4250
|
entry.files?.forEach((file) => {
|
|
4150
|
-
|
|
4251
|
+
fs9.writeFileSync(path10.join(basePath, file.name), file.content);
|
|
4151
4252
|
});
|
|
4152
4253
|
entry.dirs?.forEach((dir) => {
|
|
4153
|
-
const dirPath =
|
|
4254
|
+
const dirPath = path10.join(basePath, dir.name || "");
|
|
4154
4255
|
createStructure(dirPath, dir);
|
|
4155
4256
|
});
|
|
4156
4257
|
}
|
|
4157
4258
|
|
|
4158
4259
|
// src/add/new/index.ts
|
|
4159
|
-
import
|
|
4260
|
+
import path12 from "path";
|
|
4160
4261
|
|
|
4161
4262
|
// src/add/module/module.ts
|
|
4162
|
-
import * as
|
|
4163
|
-
import * as
|
|
4263
|
+
import * as path11 from "path";
|
|
4264
|
+
import * as fs10 from "fs";
|
|
4164
4265
|
import * as ts3 from "typescript";
|
|
4165
4266
|
function addFeature(name) {
|
|
4166
|
-
const featureDir =
|
|
4267
|
+
const featureDir = path11.join(process.cwd(), "src", "features", name);
|
|
4167
4268
|
addModule(name, featureDir);
|
|
4168
4269
|
updateFeaturesIndex(name);
|
|
4169
4270
|
updateAppModule(name);
|
|
@@ -4215,7 +4316,7 @@ function addModule(name, baseDir, root) {
|
|
|
4215
4316
|
createStructure(baseDir, structure);
|
|
4216
4317
|
}
|
|
4217
4318
|
function updateFeaturesIndex(featureName) {
|
|
4218
|
-
const featuresIndexPath =
|
|
4319
|
+
const featuresIndexPath = path11.join(
|
|
4219
4320
|
process.cwd(),
|
|
4220
4321
|
"src",
|
|
4221
4322
|
"features",
|
|
@@ -4223,8 +4324,8 @@ function updateFeaturesIndex(featureName) {
|
|
|
4223
4324
|
);
|
|
4224
4325
|
const moduleName = toPascalCase(featureName + "_Module");
|
|
4225
4326
|
const importPath = `./${featureName}/${featureName}.module`;
|
|
4226
|
-
if (
|
|
4227
|
-
let content =
|
|
4327
|
+
if (fs10.existsSync(featuresIndexPath)) {
|
|
4328
|
+
let content = fs10.readFileSync(featuresIndexPath, "utf-8");
|
|
4228
4329
|
const sourceFile = ts3.createSourceFile(
|
|
4229
4330
|
"index.ts",
|
|
4230
4331
|
content,
|
|
@@ -4250,24 +4351,24 @@ function updateFeaturesIndex(featureName) {
|
|
|
4250
4351
|
}
|
|
4251
4352
|
const exportStatement = `export { ${moduleName} } from "${importPath}";
|
|
4252
4353
|
`;
|
|
4253
|
-
|
|
4354
|
+
fs10.appendFileSync(featuresIndexPath, exportStatement);
|
|
4254
4355
|
} else {
|
|
4255
|
-
const featuresDir =
|
|
4256
|
-
if (!
|
|
4257
|
-
|
|
4356
|
+
const featuresDir = path11.dirname(featuresIndexPath);
|
|
4357
|
+
if (!fs10.existsSync(featuresDir)) {
|
|
4358
|
+
fs10.mkdirSync(featuresDir, { recursive: true });
|
|
4258
4359
|
}
|
|
4259
4360
|
const exportStatement = `export { ${moduleName} } from "${importPath}";
|
|
4260
4361
|
`;
|
|
4261
|
-
|
|
4362
|
+
fs10.writeFileSync(featuresIndexPath, exportStatement, "utf-8");
|
|
4262
4363
|
}
|
|
4263
4364
|
}
|
|
4264
4365
|
function updateAppModule(featureName) {
|
|
4265
|
-
const appModulePath =
|
|
4266
|
-
if (!
|
|
4366
|
+
const appModulePath = path11.join(process.cwd(), "src", "app", "app.module.ts");
|
|
4367
|
+
if (!fs10.existsSync(appModulePath)) {
|
|
4267
4368
|
return;
|
|
4268
4369
|
}
|
|
4269
4370
|
const moduleName = toPascalCase(featureName + "_Module");
|
|
4270
|
-
let content =
|
|
4371
|
+
let content = fs10.readFileSync(appModulePath, "utf-8");
|
|
4271
4372
|
const sourceFile = ts3.createSourceFile(
|
|
4272
4373
|
"app.module.ts",
|
|
4273
4374
|
content,
|
|
@@ -4291,7 +4392,7 @@ function updateAppModule(featureName) {
|
|
|
4291
4392
|
});
|
|
4292
4393
|
if (hasImport) {
|
|
4293
4394
|
content = addToModuleImportsArray(content, sourceFile, moduleName);
|
|
4294
|
-
|
|
4395
|
+
fs10.writeFileSync(appModulePath, content, "utf-8");
|
|
4295
4396
|
return;
|
|
4296
4397
|
}
|
|
4297
4398
|
let lastImportEnd = 0;
|
|
@@ -4310,7 +4411,7 @@ function updateAppModule(featureName) {
|
|
|
4310
4411
|
true
|
|
4311
4412
|
);
|
|
4312
4413
|
content = addToModuleImportsArray(content, newSourceFile, moduleName);
|
|
4313
|
-
|
|
4414
|
+
fs10.writeFileSync(appModulePath, content, "utf-8");
|
|
4314
4415
|
}
|
|
4315
4416
|
function addToModuleImportsArray(content, sourceFile, moduleName) {
|
|
4316
4417
|
let decoratorNode;
|
|
@@ -4637,7 +4738,7 @@ export class ${componentName} {
|
|
|
4637
4738
|
|
|
4638
4739
|
// src/add/new/index.ts
|
|
4639
4740
|
function addNew(name) {
|
|
4640
|
-
const baseDir =
|
|
4741
|
+
const baseDir = path12.join(process.cwd(), name);
|
|
4641
4742
|
const structure = {
|
|
4642
4743
|
files: [
|
|
4643
4744
|
{ name: "package.json", content: genPackageJson(name) },
|
|
@@ -4664,7 +4765,7 @@ function addNew(name) {
|
|
|
4664
4765
|
]
|
|
4665
4766
|
};
|
|
4666
4767
|
createStructure(baseDir, structure);
|
|
4667
|
-
const appDir =
|
|
4768
|
+
const appDir = path12.join(process.cwd(), name, "src", "app");
|
|
4668
4769
|
addModule("app", appDir, true);
|
|
4669
4770
|
process.chdir(baseDir);
|
|
4670
4771
|
addComponent("button");
|
|
@@ -4817,10 +4918,10 @@ bootstrap();
|
|
|
4817
4918
|
}
|
|
4818
4919
|
|
|
4819
4920
|
// src/add/ts/index.ts
|
|
4820
|
-
import
|
|
4921
|
+
import path13 from "path";
|
|
4821
4922
|
import prompts from "prompts";
|
|
4822
4923
|
async function addTs(name) {
|
|
4823
|
-
const baseDir =
|
|
4924
|
+
const baseDir = path13.join(process.cwd(), name);
|
|
4824
4925
|
const response = await prompts({
|
|
4825
4926
|
type: "select",
|
|
4826
4927
|
name: "target",
|
|
@@ -5198,21 +5299,21 @@ console.log('Running in Node.js environment');
|
|
|
5198
5299
|
}
|
|
5199
5300
|
|
|
5200
5301
|
// src/main.ts
|
|
5201
|
-
import
|
|
5202
|
-
import { execSync } from "child_process";
|
|
5302
|
+
import path16 from "path";
|
|
5303
|
+
import { execSync as execSync2 } from "child_process";
|
|
5203
5304
|
|
|
5204
5305
|
// src/docker/docker.ts
|
|
5205
|
-
import
|
|
5206
|
-
import
|
|
5306
|
+
import fs11 from "fs-extra";
|
|
5307
|
+
import path14 from "path";
|
|
5207
5308
|
import prompts2 from "prompts";
|
|
5208
5309
|
import yaml from "js-yaml";
|
|
5209
5310
|
async function dockerize(env = "prod") {
|
|
5210
5311
|
const cwd = process.cwd();
|
|
5211
|
-
const packageJsonPath =
|
|
5212
|
-
if (!
|
|
5312
|
+
const packageJsonPath = path14.join(cwd, "package.json");
|
|
5313
|
+
if (!fs11.existsSync(packageJsonPath)) {
|
|
5213
5314
|
throw new Error("package.json not found. Are you in a Pod project?");
|
|
5214
5315
|
}
|
|
5215
|
-
const packageJson = await
|
|
5316
|
+
const packageJson = await fs11.readJSON(packageJsonPath);
|
|
5216
5317
|
const projectName = packageJson.name;
|
|
5217
5318
|
const detectedServices = detectServices(packageJson);
|
|
5218
5319
|
const selectedServices = await selectServices(detectedServices);
|
|
@@ -5252,31 +5353,31 @@ async function selectServices(detected) {
|
|
|
5252
5353
|
return detected.filter((s) => response.services.includes(s.name));
|
|
5253
5354
|
}
|
|
5254
5355
|
async function restructureProject(cwd, projectName) {
|
|
5255
|
-
const nestedDir =
|
|
5256
|
-
if (
|
|
5356
|
+
const nestedDir = path14.join(cwd, projectName);
|
|
5357
|
+
if (fs11.existsSync(nestedDir)) {
|
|
5257
5358
|
console.log("\u26A0\uFE0F Project already restructured, skipping...");
|
|
5258
5359
|
return;
|
|
5259
5360
|
}
|
|
5260
|
-
await
|
|
5261
|
-
const items = await
|
|
5361
|
+
await fs11.ensureDir(nestedDir);
|
|
5362
|
+
const items = await fs11.readdir(cwd);
|
|
5262
5363
|
const toMove = items.filter((item) => item !== projectName);
|
|
5263
5364
|
for (const item of toMove) {
|
|
5264
|
-
const src =
|
|
5265
|
-
const dest =
|
|
5266
|
-
await
|
|
5365
|
+
const src = path14.join(cwd, item);
|
|
5366
|
+
const dest = path14.join(nestedDir, item);
|
|
5367
|
+
await fs11.move(src, dest, { overwrite: true });
|
|
5267
5368
|
}
|
|
5268
|
-
const envSrc =
|
|
5269
|
-
const envDest =
|
|
5270
|
-
if (
|
|
5271
|
-
await
|
|
5369
|
+
const envSrc = path14.join(nestedDir, ".env");
|
|
5370
|
+
const envDest = path14.join(cwd, ".env");
|
|
5371
|
+
if (fs11.existsSync(envSrc)) {
|
|
5372
|
+
await fs11.move(envSrc, envDest, { overwrite: true });
|
|
5272
5373
|
}
|
|
5273
5374
|
}
|
|
5274
5375
|
async function writeEnvVars(cwd, services, env) {
|
|
5275
|
-
const envPath =
|
|
5376
|
+
const envPath = path14.join(cwd, ".env");
|
|
5276
5377
|
let existingEnv = {};
|
|
5277
5378
|
let existingContent = "";
|
|
5278
|
-
if (
|
|
5279
|
-
existingContent = await
|
|
5379
|
+
if (fs11.existsSync(envPath)) {
|
|
5380
|
+
existingContent = await fs11.readFile(envPath, "utf8");
|
|
5280
5381
|
existingEnv = parseEnvFile(existingContent);
|
|
5281
5382
|
}
|
|
5282
5383
|
const newVars = [];
|
|
@@ -5305,7 +5406,7 @@ async function writeEnvVars(cwd, services, env) {
|
|
|
5305
5406
|
if (newVars.length > 0) {
|
|
5306
5407
|
const separator = existingContent && !existingContent.endsWith("\n") ? "\n" : "";
|
|
5307
5408
|
const newContent = existingContent + separator + (existingContent ? "\n" : "") + newVars.join("\n") + "\n";
|
|
5308
|
-
await
|
|
5409
|
+
await fs11.writeFile(envPath, newContent);
|
|
5309
5410
|
console.log(
|
|
5310
5411
|
`\u2705 Added ${newVars.length} new environment variable(s) to .env`
|
|
5311
5412
|
);
|
|
@@ -5329,8 +5430,8 @@ function parseEnvFile(content) {
|
|
|
5329
5430
|
return env;
|
|
5330
5431
|
}
|
|
5331
5432
|
async function createDockerfile(cwd, projectName) {
|
|
5332
|
-
const dockerfilePath =
|
|
5333
|
-
const dockerignorePath =
|
|
5433
|
+
const dockerfilePath = path14.join(cwd, projectName, "Dockerfile");
|
|
5434
|
+
const dockerignorePath = path14.join(cwd, projectName, ".dockerignore");
|
|
5334
5435
|
const dockerfile = `FROM node:18-alpine
|
|
5335
5436
|
|
|
5336
5437
|
WORKDIR /app
|
|
@@ -5401,8 +5502,8 @@ docker-compose*.yml
|
|
|
5401
5502
|
tmp
|
|
5402
5503
|
temp
|
|
5403
5504
|
`;
|
|
5404
|
-
await
|
|
5405
|
-
await
|
|
5505
|
+
await fs11.writeFile(dockerfilePath, dockerfile);
|
|
5506
|
+
await fs11.writeFile(dockerignorePath, dockerignore);
|
|
5406
5507
|
}
|
|
5407
5508
|
async function createDeployfile(cwd, projectName) {
|
|
5408
5509
|
const deployFile = `name: ${projectName}
|
|
@@ -5520,8 +5621,8 @@ targets:
|
|
|
5520
5621
|
find *backup_path -name "backup-*.tar.gz" -mtime +7 -delete
|
|
5521
5622
|
docker image prune -af --filter "until=24h"
|
|
5522
5623
|
`;
|
|
5523
|
-
const deployFilePath =
|
|
5524
|
-
await
|
|
5624
|
+
const deployFilePath = path14.join(cwd, "pod.deploy.yml");
|
|
5625
|
+
await fs11.writeFile(deployFilePath, deployFile);
|
|
5525
5626
|
}
|
|
5526
5627
|
async function setupProduction(cwd, projectName, services) {
|
|
5527
5628
|
const compose = {
|
|
@@ -5591,17 +5692,17 @@ async function setupProduction(cwd, projectName, services) {
|
|
|
5591
5692
|
}
|
|
5592
5693
|
compose.services[projectName].depends_on.push(service.name);
|
|
5593
5694
|
}
|
|
5594
|
-
const composePath =
|
|
5595
|
-
await
|
|
5695
|
+
const composePath = path14.join(cwd, "docker-compose.yml");
|
|
5696
|
+
await fs11.writeFile(
|
|
5596
5697
|
composePath,
|
|
5597
5698
|
yaml.dump(compose, { indent: 2, lineWidth: -1 })
|
|
5598
5699
|
);
|
|
5599
5700
|
}
|
|
5600
5701
|
async function setupDevelopment(cwd, projectName, services) {
|
|
5601
|
-
const existingCompose =
|
|
5702
|
+
const existingCompose = path14.join(cwd, "docker-compose.yml");
|
|
5602
5703
|
let existingServices = [];
|
|
5603
|
-
if (
|
|
5604
|
-
const content = await
|
|
5704
|
+
if (fs11.existsSync(existingCompose)) {
|
|
5705
|
+
const content = await fs11.readFile(existingCompose, "utf8");
|
|
5605
5706
|
const existing = yaml.load(content);
|
|
5606
5707
|
if (existing.services) {
|
|
5607
5708
|
existingServices = Object.keys(existing.services).filter((s) => ["postgres", "mysql", "redis", "mongodb"].includes(s)).map((name) => ({ name }));
|
|
@@ -5670,15 +5771,15 @@ async function setupDevelopment(cwd, projectName, services) {
|
|
|
5670
5771
|
};
|
|
5671
5772
|
compose.services[projectName].depends_on.push(tunnelName);
|
|
5672
5773
|
}
|
|
5673
|
-
const devComposePath =
|
|
5674
|
-
await
|
|
5774
|
+
const devComposePath = path14.join(cwd, "docker-compose.dev.yml");
|
|
5775
|
+
await fs11.writeFile(
|
|
5675
5776
|
devComposePath,
|
|
5676
5777
|
yaml.dump(compose, { indent: 2, lineWidth: -1 })
|
|
5677
5778
|
);
|
|
5678
5779
|
}
|
|
5679
5780
|
async function createTunnelService(projectDir, serviceName) {
|
|
5680
|
-
const tunnelDir =
|
|
5681
|
-
await
|
|
5781
|
+
const tunnelDir = path14.join(projectDir, `${serviceName}-tunnel`);
|
|
5782
|
+
await fs11.ensureDir(tunnelDir);
|
|
5682
5783
|
const dockerfile = `FROM alpine:latest
|
|
5683
5784
|
|
|
5684
5785
|
RUN apk add --no-cache openssh-client
|
|
@@ -5706,8 +5807,8 @@ ssh -i $SSH_KEY \\
|
|
|
5706
5807
|
-o ServerAliveInterval=60 \\
|
|
5707
5808
|
$REMOTE_HOST
|
|
5708
5809
|
`;
|
|
5709
|
-
await
|
|
5710
|
-
await
|
|
5810
|
+
await fs11.writeFile(path14.join(tunnelDir, "Dockerfile"), dockerfile);
|
|
5811
|
+
await fs11.writeFile(path14.join(tunnelDir, "tunnel.sh"), tunnelScript);
|
|
5711
5812
|
}
|
|
5712
5813
|
function getServiceConfig(serviceName) {
|
|
5713
5814
|
const configs = {
|
|
@@ -5817,9 +5918,9 @@ function printNextSteps(projectName, env, services) {
|
|
|
5817
5918
|
}
|
|
5818
5919
|
|
|
5819
5920
|
// src/deploy/deploy.ts
|
|
5820
|
-
import
|
|
5921
|
+
import fs12 from "fs-extra";
|
|
5821
5922
|
import yaml2 from "js-yaml";
|
|
5822
|
-
import
|
|
5923
|
+
import path15 from "path";
|
|
5823
5924
|
import os from "os";
|
|
5824
5925
|
import { NodeSSH } from "node-ssh";
|
|
5825
5926
|
import chalk from "chalk";
|
|
@@ -5850,7 +5951,7 @@ function deepInterpolate(obj, context2) {
|
|
|
5850
5951
|
}
|
|
5851
5952
|
function expandTilde(fp) {
|
|
5852
5953
|
if (!fp || typeof fp !== "string") return fp;
|
|
5853
|
-
return fp.startsWith("~/") ?
|
|
5954
|
+
return fp.startsWith("~/") ? path15.join(os.homedir(), fp.slice(2)) : fp;
|
|
5854
5955
|
}
|
|
5855
5956
|
function resolveLocalPaths(obj, cwd) {
|
|
5856
5957
|
if (Array.isArray(obj)) {
|
|
@@ -5862,7 +5963,7 @@ function resolveLocalPaths(obj, cwd) {
|
|
|
5862
5963
|
const isLocalPathKey = key === "keyPath" || key === "source";
|
|
5863
5964
|
if (isLocalPathKey && typeof value === "string") {
|
|
5864
5965
|
const expanded = expandTilde(value);
|
|
5865
|
-
result[key] =
|
|
5966
|
+
result[key] = path15.isAbsolute(expanded) ? expanded : path15.resolve(cwd, expanded);
|
|
5866
5967
|
} else {
|
|
5867
5968
|
result[key] = resolveLocalPaths(value, cwd);
|
|
5868
5969
|
}
|
|
@@ -6045,7 +6146,7 @@ var SSHStrategy = class {
|
|
|
6045
6146
|
const trimmed = cmd.trim();
|
|
6046
6147
|
if (trimmed.startsWith("cd ")) {
|
|
6047
6148
|
const newPath = trimmed.replace("cd ", "").trim();
|
|
6048
|
-
this.currentDir =
|
|
6149
|
+
this.currentDir = path15.posix.resolve(this.currentDir, newPath);
|
|
6049
6150
|
if (!silent) console.log(chalk.gray(` [SSH Path: ${this.currentDir}]`));
|
|
6050
6151
|
return { stdout: "", stderr: "", code: 0 };
|
|
6051
6152
|
}
|
|
@@ -6073,13 +6174,13 @@ STDERR: ${result.stderr}`);
|
|
|
6073
6174
|
}
|
|
6074
6175
|
}
|
|
6075
6176
|
async uploadContent(remotePath, content) {
|
|
6076
|
-
const localTmp =
|
|
6077
|
-
|
|
6177
|
+
const localTmp = path15.join(os.tmpdir(), `pod_tmp_${Date.now()}`);
|
|
6178
|
+
fs12.writeFileSync(localTmp, content);
|
|
6078
6179
|
try {
|
|
6079
6180
|
await this.ssh.execCommand(`mkdir -p $(dirname ${remotePath})`);
|
|
6080
6181
|
await this.ssh.putFile(localTmp, remotePath);
|
|
6081
6182
|
} finally {
|
|
6082
|
-
if (
|
|
6183
|
+
if (fs12.existsSync(localTmp)) fs12.unlinkSync(localTmp);
|
|
6083
6184
|
}
|
|
6084
6185
|
}
|
|
6085
6186
|
async readJson(remotePath) {
|
|
@@ -6094,7 +6195,7 @@ STDERR: ${result.stderr}`);
|
|
|
6094
6195
|
const putOptions = { recursive: true, concurrency: 10 };
|
|
6095
6196
|
if (exclude?.length) {
|
|
6096
6197
|
putOptions.validate = (filePath) => {
|
|
6097
|
-
const relative =
|
|
6198
|
+
const relative = path15.relative(source, filePath);
|
|
6098
6199
|
if (relative === "") return true;
|
|
6099
6200
|
return !exclude.some((pattern) => {
|
|
6100
6201
|
if (pattern.endsWith("/")) {
|
|
@@ -6126,7 +6227,7 @@ var LocalStrategy = class {
|
|
|
6126
6227
|
const trimmed = cmd.trim();
|
|
6127
6228
|
if (trimmed.startsWith("cd ")) {
|
|
6128
6229
|
const newPath = trimmed.replace("cd ", "").trim();
|
|
6129
|
-
this.currentDir =
|
|
6230
|
+
this.currentDir = path15.resolve(this.currentDir, newPath);
|
|
6130
6231
|
if (!silent) console.log(chalk.gray(` [Local Path: ${this.currentDir}]`));
|
|
6131
6232
|
return { stdout: "", stderr: "", code: 0 };
|
|
6132
6233
|
}
|
|
@@ -6149,29 +6250,29 @@ STDERR: ${err.stderr || err.message}`
|
|
|
6149
6250
|
}
|
|
6150
6251
|
async runScript(name, content, context2) {
|
|
6151
6252
|
const interpolated = interpolate(content, context2);
|
|
6152
|
-
const scriptPath =
|
|
6253
|
+
const scriptPath = path15.join(
|
|
6153
6254
|
os.tmpdir(),
|
|
6154
6255
|
`pod_script_${name}_${Date.now()}.sh`
|
|
6155
6256
|
);
|
|
6156
|
-
|
|
6157
|
-
|
|
6257
|
+
fs12.writeFileSync(scriptPath, interpolated);
|
|
6258
|
+
fs12.chmodSync(scriptPath, "755");
|
|
6158
6259
|
try {
|
|
6159
6260
|
await this.runCommand(scriptPath);
|
|
6160
6261
|
} finally {
|
|
6161
|
-
if (
|
|
6262
|
+
if (fs12.existsSync(scriptPath)) fs12.unlinkSync(scriptPath);
|
|
6162
6263
|
}
|
|
6163
6264
|
}
|
|
6164
6265
|
async uploadContent(localPath, content) {
|
|
6165
|
-
const dir =
|
|
6166
|
-
if (!
|
|
6167
|
-
|
|
6266
|
+
const dir = path15.dirname(localPath);
|
|
6267
|
+
if (!fs12.existsSync(dir)) {
|
|
6268
|
+
fs12.mkdirSync(dir, { recursive: true });
|
|
6168
6269
|
}
|
|
6169
|
-
|
|
6270
|
+
fs12.writeFileSync(localPath, content);
|
|
6170
6271
|
}
|
|
6171
6272
|
async readJson(localPath) {
|
|
6172
6273
|
try {
|
|
6173
|
-
if (!
|
|
6174
|
-
const content =
|
|
6274
|
+
if (!fs12.existsSync(localPath)) return null;
|
|
6275
|
+
const content = fs12.readFileSync(localPath, "utf8");
|
|
6175
6276
|
return JSON.parse(content);
|
|
6176
6277
|
} catch {
|
|
6177
6278
|
return null;
|
|
@@ -6179,8 +6280,8 @@ STDERR: ${err.stderr || err.message}`
|
|
|
6179
6280
|
}
|
|
6180
6281
|
async syncDirectory(source, destination, exclude) {
|
|
6181
6282
|
console.log(chalk.gray(` Copying ${source} \u2192 ${destination}`));
|
|
6182
|
-
if (!
|
|
6183
|
-
|
|
6283
|
+
if (!fs12.existsSync(destination)) {
|
|
6284
|
+
fs12.mkdirSync(destination, { recursive: true });
|
|
6184
6285
|
}
|
|
6185
6286
|
const shouldExclude = (relativePath) => {
|
|
6186
6287
|
if (!exclude?.length) return false;
|
|
@@ -6197,19 +6298,19 @@ STDERR: ${err.stderr || err.message}`
|
|
|
6197
6298
|
});
|
|
6198
6299
|
};
|
|
6199
6300
|
const copyRecursive = (src, dest) => {
|
|
6200
|
-
const entries =
|
|
6301
|
+
const entries = fs12.readdirSync(src, { withFileTypes: true });
|
|
6201
6302
|
for (const entry of entries) {
|
|
6202
|
-
const srcPath =
|
|
6203
|
-
const destPath =
|
|
6204
|
-
const relativePath =
|
|
6303
|
+
const srcPath = path15.join(src, entry.name);
|
|
6304
|
+
const destPath = path15.join(dest, entry.name);
|
|
6305
|
+
const relativePath = path15.relative(source, srcPath);
|
|
6205
6306
|
if (shouldExclude(relativePath)) continue;
|
|
6206
6307
|
if (entry.isDirectory()) {
|
|
6207
|
-
if (!
|
|
6208
|
-
|
|
6308
|
+
if (!fs12.existsSync(destPath)) {
|
|
6309
|
+
fs12.mkdirSync(destPath, { recursive: true });
|
|
6209
6310
|
}
|
|
6210
6311
|
copyRecursive(srcPath, destPath);
|
|
6211
6312
|
} else {
|
|
6212
|
-
|
|
6313
|
+
fs12.copyFileSync(srcPath, destPath);
|
|
6213
6314
|
}
|
|
6214
6315
|
}
|
|
6215
6316
|
};
|
|
@@ -6372,7 +6473,7 @@ var OperationHandler = class {
|
|
|
6372
6473
|
async function deploy(targetName, options) {
|
|
6373
6474
|
const cwd = process.cwd();
|
|
6374
6475
|
const rawConfig = yaml2.load(
|
|
6375
|
-
|
|
6476
|
+
fs12.readFileSync(path15.join(cwd, "pod.deploy.yml"), "utf8"),
|
|
6376
6477
|
{ schema: yaml2.DEFAULT_SCHEMA }
|
|
6377
6478
|
);
|
|
6378
6479
|
const rawTarget = rawConfig.targets?.[targetName];
|
|
@@ -6392,7 +6493,7 @@ Pod Deploy: ${rawConfig.name} v${rawConfig.version} \u2192 ${targetName}
|
|
|
6392
6493
|
const strategy = StrategyFactory.create(target, cwd);
|
|
6393
6494
|
try {
|
|
6394
6495
|
await strategy.connect();
|
|
6395
|
-
const lockPath = target.deployPath ?
|
|
6496
|
+
const lockPath = target.deployPath ? path15.posix.join(target.deployPath, "pod-lock.json") : path15.join(cwd, "pod-lock.json");
|
|
6396
6497
|
let lock = await strategy.readJson(lockPath) || {
|
|
6397
6498
|
ensures: {},
|
|
6398
6499
|
once_actions: []
|
|
@@ -6433,27 +6534,60 @@ Deployment Failed: ${err.message}`));
|
|
|
6433
6534
|
|
|
6434
6535
|
// src/main.ts
|
|
6435
6536
|
import chalk2 from "chalk";
|
|
6537
|
+
|
|
6538
|
+
// src/compile/compile.ts
|
|
6539
|
+
import * as esbuild3 from "esbuild";
|
|
6540
|
+
import { execSync } from "child_process";
|
|
6541
|
+
async function compileFiles(entryPoints) {
|
|
6542
|
+
const store = Store.getInstance();
|
|
6543
|
+
const userConfig = await loadConfig();
|
|
6544
|
+
const config = mergeConfig(getDefaultConfig(), userConfig);
|
|
6545
|
+
await esbuild3.build({
|
|
6546
|
+
entryPoints,
|
|
6547
|
+
bundle: true,
|
|
6548
|
+
outdir: config.build?.outDir || "dist",
|
|
6549
|
+
platform: "node",
|
|
6550
|
+
format: "esm",
|
|
6551
|
+
packages: "external",
|
|
6552
|
+
sourcemap: config.build?.sourcemap ?? true,
|
|
6553
|
+
minify: config.build?.minify ?? false,
|
|
6554
|
+
plugins: [
|
|
6555
|
+
...config.plugins?.map((cb) => cb(store)) || [],
|
|
6556
|
+
useCompilePlugin({
|
|
6557
|
+
decorators: config.build?.decorators ?? false
|
|
6558
|
+
})
|
|
6559
|
+
],
|
|
6560
|
+
write: true
|
|
6561
|
+
});
|
|
6562
|
+
if (config.build?.types) {
|
|
6563
|
+
execSync("npx tsc", {
|
|
6564
|
+
stdio: "inherit"
|
|
6565
|
+
});
|
|
6566
|
+
}
|
|
6567
|
+
}
|
|
6568
|
+
|
|
6569
|
+
// src/main.ts
|
|
6436
6570
|
var program = new Command();
|
|
6437
|
-
program.name("pod").description("Pod cli tool").version("1.0.
|
|
6571
|
+
program.name("pod").description("Pod cli tool").version("1.0.32");
|
|
6438
6572
|
program.command("new <name> [type]").description("Start a new Orca Project").action(async (name, type) => {
|
|
6439
6573
|
const orca = async () => {
|
|
6440
6574
|
await addNew(name);
|
|
6441
|
-
const appDir =
|
|
6575
|
+
const appDir = path16.resolve(process.cwd());
|
|
6442
6576
|
const shell = process.platform === "win32" ? process.env.ComSpec || "cmd.exe" : "/bin/sh";
|
|
6443
6577
|
console.log("Installing dependencies...");
|
|
6444
|
-
|
|
6578
|
+
execSync2("npm install", { stdio: "inherit", cwd: appDir, shell });
|
|
6445
6579
|
console.log("Starting development server...");
|
|
6446
|
-
|
|
6580
|
+
execSync2("npm run dev", { stdio: "inherit", cwd: appDir, shell });
|
|
6447
6581
|
console.log(
|
|
6448
6582
|
`All done! Your app "${name}" is running in development mode.`
|
|
6449
6583
|
);
|
|
6450
6584
|
};
|
|
6451
6585
|
const ts4 = async () => {
|
|
6452
6586
|
await addTs(name);
|
|
6453
|
-
const appDir =
|
|
6587
|
+
const appDir = path16.resolve(process.cwd());
|
|
6454
6588
|
const shell = process.platform === "win32" ? process.env.ComSpec || "cmd.exe" : "/bin/sh";
|
|
6455
6589
|
console.log("Installing dependencies...");
|
|
6456
|
-
|
|
6590
|
+
execSync2("npm install", { stdio: "inherit", cwd: appDir, shell });
|
|
6457
6591
|
};
|
|
6458
6592
|
switch (type) {
|
|
6459
6593
|
case "orca":
|
|
@@ -6467,6 +6601,9 @@ program.command("new <name> [type]").description("Start a new Orca Project").act
|
|
|
6467
6601
|
program.command("dev").description("Start Pod development server").action(async (opts) => {
|
|
6468
6602
|
await startDevServer();
|
|
6469
6603
|
});
|
|
6604
|
+
program.command("compile <files...>").description("Compile ts files with pod").action(async (files) => {
|
|
6605
|
+
await compileFiles(files);
|
|
6606
|
+
});
|
|
6470
6607
|
program.command("add <type> <name>").description("Add a component (c) or a feature (f)").action(async (type, name) => {
|
|
6471
6608
|
try {
|
|
6472
6609
|
if (type === "c") {
|
|
@@ -6503,6 +6640,7 @@ export {
|
|
|
6503
6640
|
getDefaultConfig,
|
|
6504
6641
|
getGlobalMacroGraph,
|
|
6505
6642
|
loadConfig,
|
|
6643
|
+
macroContext,
|
|
6506
6644
|
macros_exports as macros,
|
|
6507
6645
|
mergeConfig,
|
|
6508
6646
|
plugins_exports as plugins,
|