owosk 0.2.1 → 0.2.2
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 +1 -1
- package/dist/index.js +39 -68
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ npx owo --help
|
|
|
20
20
|
|
|
21
21
|
### `init`
|
|
22
22
|
|
|
23
|
-
Initialize a new Owostack project with a default configuration file (`owo.config.ts` or `owo.config.js`).
|
|
23
|
+
Initialize a new Owostack project with a default configuration file (`owo.config.ts` or `owo.config.js`). JavaScript configs use ESM `import`/`export` syntax.
|
|
24
24
|
|
|
25
25
|
```bash
|
|
26
26
|
npx owo init
|
package/dist/index.js
CHANGED
|
@@ -49,12 +49,15 @@ function getApiKey(cliKey) {
|
|
|
49
49
|
import { resolve, isAbsolute, extname } from "path";
|
|
50
50
|
import { existsSync as existsSync2 } from "fs";
|
|
51
51
|
import { createJiti } from "jiti";
|
|
52
|
-
var jiti = createJiti(import.meta.url
|
|
52
|
+
var jiti = createJiti(import.meta.url, {
|
|
53
|
+
alias: {
|
|
54
|
+
owostack: import.meta.resolve("owostack")
|
|
55
|
+
}
|
|
56
|
+
});
|
|
53
57
|
var DEFAULT_CONFIG_NAMES = [
|
|
54
58
|
"owo.config.ts",
|
|
55
59
|
"owo.config.js",
|
|
56
60
|
"owo.config.mjs",
|
|
57
|
-
"owo.config.cjs",
|
|
58
61
|
"owo.config.mts",
|
|
59
62
|
"owo.config.cts"
|
|
60
63
|
];
|
|
@@ -98,17 +101,17 @@ async function loadOwostackFromConfig(fullPath) {
|
|
|
98
101
|
` import { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } from "owostack";`
|
|
99
102
|
);
|
|
100
103
|
console.error(
|
|
101
|
-
` export
|
|
104
|
+
` export const owo = new Owostack({ secretKey: "...", catalog: [...] });
|
|
102
105
|
`
|
|
103
106
|
);
|
|
104
107
|
} else {
|
|
105
108
|
console.error(` Example owo.config.js:
|
|
106
109
|
`);
|
|
107
110
|
console.error(
|
|
108
|
-
`
|
|
111
|
+
` import { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } from "owostack";`
|
|
109
112
|
);
|
|
110
113
|
console.error(
|
|
111
|
-
`
|
|
114
|
+
` export const owo = new Owostack({ secretKey: "...", catalog: [...] });
|
|
112
115
|
`
|
|
113
116
|
);
|
|
114
117
|
}
|
|
@@ -771,9 +774,9 @@ async function runSync(options) {
|
|
|
771
774
|
// src/commands/pull.ts
|
|
772
775
|
import * as p3 from "@clack/prompts";
|
|
773
776
|
import pc4 from "picocolors";
|
|
774
|
-
import { existsSync as existsSync3
|
|
777
|
+
import { existsSync as existsSync3 } from "fs";
|
|
775
778
|
import { writeFile as writeFile2 } from "fs/promises";
|
|
776
|
-
import {
|
|
779
|
+
import { resolve as resolve2, extname as extname2, isAbsolute as isAbsolute2 } from "path";
|
|
777
780
|
|
|
778
781
|
// src/lib/generate.ts
|
|
779
782
|
function slugToIdentifier(slug, used) {
|
|
@@ -830,7 +833,6 @@ function slugToIdentifier(slug, used) {
|
|
|
830
833
|
}
|
|
831
834
|
function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProvider, format = "ts") {
|
|
832
835
|
const isTs = format === "ts";
|
|
833
|
-
const isCjs = format === "cjs";
|
|
834
836
|
const creditSystemSlugs = new Set(creditSystems.map((cs) => cs.slug));
|
|
835
837
|
const featuresBySlug = /* @__PURE__ */ new Map();
|
|
836
838
|
for (const plan of plans) {
|
|
@@ -876,11 +878,7 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
876
878
|
const isEntity = feature.meterType === "non_consumable";
|
|
877
879
|
const builder = feature.type === "boolean" ? "boolean" : isEntity ? "entity" : "metered";
|
|
878
880
|
const decl = `${builder}(${JSON.stringify(feature.slug)}${nameArg})`;
|
|
879
|
-
|
|
880
|
-
featureLines.push(`const ${varName} = ${decl};`);
|
|
881
|
-
} else {
|
|
882
|
-
featureLines.push(`export const ${varName} = ${decl};`);
|
|
883
|
-
}
|
|
881
|
+
featureLines.push(`export const ${varName} = ${decl};`);
|
|
884
882
|
}
|
|
885
883
|
const creditSystemLines = [];
|
|
886
884
|
const creditSystemVars = /* @__PURE__ */ new Map();
|
|
@@ -899,11 +897,7 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
899
897
|
const decl = `creditSystem(${JSON.stringify(cs.slug)}, {
|
|
900
898
|
${configLines.join(",\n ")}
|
|
901
899
|
})`;
|
|
902
|
-
|
|
903
|
-
creditSystemLines.push(`const ${varName} = ${decl};`);
|
|
904
|
-
} else {
|
|
905
|
-
creditSystemLines.push(`export const ${varName} = ${decl};`);
|
|
906
|
-
}
|
|
900
|
+
creditSystemLines.push(`export const ${varName} = ${decl};`);
|
|
907
901
|
}
|
|
908
902
|
const planLines = [];
|
|
909
903
|
for (const plan of plans) {
|
|
@@ -1024,25 +1018,12 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
1024
1018
|
const importParts = ["Owostack", "metered", "boolean"];
|
|
1025
1019
|
if (hasEntities) importParts.push("entity");
|
|
1026
1020
|
importParts.push("creditSystem", "creditPack", "plan");
|
|
1027
|
-
const imports =
|
|
1021
|
+
const imports = `import { ${importParts.join(", ")} } from "owostack";`;
|
|
1028
1022
|
const tsCheck = !isTs ? `// @ts-check` : "";
|
|
1029
1023
|
const jsDoc = !isTs ? `/** @type {import('owostack').Owostack} */` : "";
|
|
1030
|
-
const owoDecl =
|
|
1024
|
+
const owoDecl = "export const owo =";
|
|
1031
1025
|
const secretKey = isTs ? "process.env.OWOSTACK_SECRET_KEY!" : "process.env.OWOSTACK_SECRET_KEY";
|
|
1032
1026
|
const catalogEntries = [...planLines, ...creditPackLines];
|
|
1033
|
-
const footer = isCjs ? `module.exports = { owo, ${Array.from(usedNames).filter(
|
|
1034
|
-
(n) => ![
|
|
1035
|
-
"Owostack",
|
|
1036
|
-
"metered",
|
|
1037
|
-
"boolean",
|
|
1038
|
-
"entity",
|
|
1039
|
-
"creditSystem",
|
|
1040
|
-
"creditPack",
|
|
1041
|
-
"plan",
|
|
1042
|
-
"owo"
|
|
1043
|
-
].includes(n)
|
|
1044
|
-
).join(", ")} };`.replace(", };", " };") : "";
|
|
1045
|
-
const finalFooter = isCjs && footer.includes("{ owo, }") ? "module.exports = { owo };" : footer;
|
|
1046
1027
|
return [
|
|
1047
1028
|
tsCheck,
|
|
1048
1029
|
imports,
|
|
@@ -1057,30 +1038,21 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
1057
1038
|
` catalog: [`,
|
|
1058
1039
|
` ${catalogEntries.join(",\n ")}`,
|
|
1059
1040
|
` ],`,
|
|
1060
|
-
`})
|
|
1061
|
-
``,
|
|
1062
|
-
finalFooter
|
|
1041
|
+
`});`
|
|
1063
1042
|
].filter(Boolean).join("\n");
|
|
1064
1043
|
}
|
|
1065
1044
|
|
|
1066
1045
|
// src/commands/pull.ts
|
|
1067
|
-
function getProjectInfo() {
|
|
1068
|
-
const cwd = process.cwd();
|
|
1069
|
-
let isEsm = false;
|
|
1070
|
-
try {
|
|
1071
|
-
const pkg2 = JSON.parse(readFileSync2(join2(cwd, "package.json"), "utf8"));
|
|
1072
|
-
isEsm = pkg2.type === "module";
|
|
1073
|
-
} catch {
|
|
1074
|
-
}
|
|
1075
|
-
return { isEsm };
|
|
1076
|
-
}
|
|
1077
1046
|
function determineFormat(fullPath) {
|
|
1078
1047
|
const ext = extname2(fullPath);
|
|
1079
|
-
const { isEsm } = getProjectInfo();
|
|
1080
1048
|
if (ext === ".ts" || ext === ".mts" || ext === ".cts") return "ts";
|
|
1081
1049
|
if (ext === ".mjs") return "esm";
|
|
1082
|
-
if (ext === ".cjs")
|
|
1083
|
-
|
|
1050
|
+
if (ext === ".cjs") {
|
|
1051
|
+
throw new Error(
|
|
1052
|
+
"CommonJS config files are not supported. Use owo.config.js or owo.config.ts."
|
|
1053
|
+
);
|
|
1054
|
+
}
|
|
1055
|
+
if (ext === ".js") return "esm";
|
|
1084
1056
|
return "ts";
|
|
1085
1057
|
}
|
|
1086
1058
|
async function runPull(options) {
|
|
@@ -1103,7 +1075,13 @@ async function runPull(options) {
|
|
|
1103
1075
|
const testUrl = getTestApiUrl(configSettings.environments?.test);
|
|
1104
1076
|
const liveUrl = getApiUrl(configSettings.environments?.live);
|
|
1105
1077
|
const filters = configSettings.filters || {};
|
|
1106
|
-
|
|
1078
|
+
let format;
|
|
1079
|
+
try {
|
|
1080
|
+
format = determineFormat(fullPath);
|
|
1081
|
+
} catch (e) {
|
|
1082
|
+
p3.log.error(pc4.red(e.message));
|
|
1083
|
+
process.exit(1);
|
|
1084
|
+
}
|
|
1107
1085
|
const s = p3.spinner();
|
|
1108
1086
|
if (options.prod) {
|
|
1109
1087
|
p3.log.step(pc4.magenta("Production Mode: Pulling from PROD environment"));
|
|
@@ -1349,9 +1327,9 @@ async function runDiff(options) {
|
|
|
1349
1327
|
// src/commands/init.ts
|
|
1350
1328
|
import * as p6 from "@clack/prompts";
|
|
1351
1329
|
import pc7 from "picocolors";
|
|
1352
|
-
import { existsSync as existsSync4
|
|
1330
|
+
import { existsSync as existsSync4 } from "fs";
|
|
1353
1331
|
import { writeFile as writeFile3 } from "fs/promises";
|
|
1354
|
-
import { join as
|
|
1332
|
+
import { join as join2, resolve as resolve3, isAbsolute as isAbsolute3, extname as extname3 } from "path";
|
|
1355
1333
|
|
|
1356
1334
|
// src/lib/connect.ts
|
|
1357
1335
|
import * as p5 from "@clack/prompts";
|
|
@@ -1451,16 +1429,10 @@ async function executeConnectFlow(options) {
|
|
|
1451
1429
|
}
|
|
1452
1430
|
|
|
1453
1431
|
// src/commands/init.ts
|
|
1454
|
-
function
|
|
1432
|
+
function getProjectInfo() {
|
|
1455
1433
|
const cwd = process.cwd();
|
|
1456
|
-
const isTs = existsSync4(
|
|
1457
|
-
|
|
1458
|
-
try {
|
|
1459
|
-
const pkg2 = JSON.parse(readFileSync3(join3(cwd, "package.json"), "utf8"));
|
|
1460
|
-
isEsm = pkg2.type === "module";
|
|
1461
|
-
} catch {
|
|
1462
|
-
}
|
|
1463
|
-
return { isTs, isEsm };
|
|
1434
|
+
const isTs = existsSync4(join2(cwd, "tsconfig.json"));
|
|
1435
|
+
return { isTs };
|
|
1464
1436
|
}
|
|
1465
1437
|
async function runInit(options) {
|
|
1466
1438
|
p6.intro(pc7.bgYellow(pc7.black(" init ")));
|
|
@@ -1470,7 +1442,7 @@ async function runInit(options) {
|
|
|
1470
1442
|
if (existing) {
|
|
1471
1443
|
targetPath = existing;
|
|
1472
1444
|
} else {
|
|
1473
|
-
const { isTs } =
|
|
1445
|
+
const { isTs } = getProjectInfo();
|
|
1474
1446
|
targetPath = isTs ? "owo.config.ts" : "owo.config.js";
|
|
1475
1447
|
}
|
|
1476
1448
|
}
|
|
@@ -1508,16 +1480,17 @@ async function runInit(options) {
|
|
|
1508
1480
|
const plans = await fetchPlans({ apiKey, apiUrl });
|
|
1509
1481
|
const creditSystems = await fetchCreditSystems(apiKey, apiUrl);
|
|
1510
1482
|
const ext = extname3(fullPath);
|
|
1511
|
-
const { isEsm } = getProjectInfo2();
|
|
1512
1483
|
let format = "ts";
|
|
1513
1484
|
if (ext === ".ts" || ext === ".mts" || ext === ".cts") {
|
|
1514
1485
|
format = "ts";
|
|
1515
1486
|
} else if (ext === ".mjs") {
|
|
1516
1487
|
format = "esm";
|
|
1517
1488
|
} else if (ext === ".cjs") {
|
|
1518
|
-
|
|
1489
|
+
throw new Error(
|
|
1490
|
+
"CommonJS config files are not supported. Use owo.config.js or owo.config.ts."
|
|
1491
|
+
);
|
|
1519
1492
|
} else if (ext === ".js") {
|
|
1520
|
-
format =
|
|
1493
|
+
format = "esm";
|
|
1521
1494
|
}
|
|
1522
1495
|
const configContent = generateConfig(
|
|
1523
1496
|
plans,
|
|
@@ -1536,9 +1509,7 @@ ${pc7.dim("Credit Systems:")} ${creditSystems.length}`,
|
|
|
1536
1509
|
"\u2728 Project Initialized"
|
|
1537
1510
|
);
|
|
1538
1511
|
p6.outro(
|
|
1539
|
-
pc7.cyan(
|
|
1540
|
-
`Next step: Run ${pc7.bold("owosk sync")} to apply your catalog.`
|
|
1541
|
-
)
|
|
1512
|
+
pc7.cyan(`Next step: Run ${pc7.bold("owosk sync")} to apply your catalog.`)
|
|
1542
1513
|
);
|
|
1543
1514
|
} catch (e) {
|
|
1544
1515
|
s.stop(pc7.red("Initialization failed"));
|