owosk 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +40 -20
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -95,7 +95,7 @@ async function loadOwostackFromConfig(fullPath) {
|
|
|
95
95
|
console.error(` Example owo.config.ts:
|
|
96
96
|
`);
|
|
97
97
|
console.error(
|
|
98
|
-
` import { Owostack, metered, boolean, plan } from "owostack";`
|
|
98
|
+
` import { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } from "owostack";`
|
|
99
99
|
);
|
|
100
100
|
console.error(
|
|
101
101
|
` export default new Owostack({ secretKey: "...", catalog: [...] });
|
|
@@ -105,7 +105,7 @@ async function loadOwostackFromConfig(fullPath) {
|
|
|
105
105
|
console.error(` Example owo.config.js:
|
|
106
106
|
`);
|
|
107
107
|
console.error(
|
|
108
|
-
` const { Owostack, metered, boolean, plan } = require("owostack");`
|
|
108
|
+
` const { Owostack, metered, boolean, entity, creditSystem, creditPack, plan } = require("owostack");`
|
|
109
109
|
);
|
|
110
110
|
console.error(
|
|
111
111
|
` module.exports = new Owostack({ secretKey: "...", catalog: [...] });
|
|
@@ -832,7 +832,6 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
832
832
|
const isTs = format === "ts";
|
|
833
833
|
const isCjs = format === "cjs";
|
|
834
834
|
const creditSystemSlugs = new Set(creditSystems.map((cs) => cs.slug));
|
|
835
|
-
const creditSystemBySlug = new Map(creditSystems.map((cs) => [cs.slug, cs]));
|
|
836
835
|
const featuresBySlug = /* @__PURE__ */ new Map();
|
|
837
836
|
for (const plan of plans) {
|
|
838
837
|
for (const f of plan.features || []) {
|
|
@@ -858,7 +857,16 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
858
857
|
}
|
|
859
858
|
}
|
|
860
859
|
}
|
|
861
|
-
const usedNames = /* @__PURE__ */ new Set(
|
|
860
|
+
const usedNames = /* @__PURE__ */ new Set([
|
|
861
|
+
"Owostack",
|
|
862
|
+
"metered",
|
|
863
|
+
"boolean",
|
|
864
|
+
"entity",
|
|
865
|
+
"creditSystem",
|
|
866
|
+
"creditPack",
|
|
867
|
+
"plan",
|
|
868
|
+
"owo"
|
|
869
|
+
]);
|
|
862
870
|
const featureVars = /* @__PURE__ */ new Map();
|
|
863
871
|
const featureLines = [];
|
|
864
872
|
for (const feature of featuresBySlug.values()) {
|
|
@@ -870,7 +878,6 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
870
878
|
const decl = `${builder}(${JSON.stringify(feature.slug)}${nameArg})`;
|
|
871
879
|
if (isCjs) {
|
|
872
880
|
featureLines.push(`const ${varName} = ${decl};`);
|
|
873
|
-
featureLines.push(`exports.${varName} = ${varName};`);
|
|
874
881
|
} else {
|
|
875
882
|
featureLines.push(`export const ${varName} = ${decl};`);
|
|
876
883
|
}
|
|
@@ -880,21 +887,20 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
880
887
|
for (const cs of creditSystems) {
|
|
881
888
|
const varName = slugToIdentifier(cs.slug, usedNames);
|
|
882
889
|
creditSystemVars.set(cs.slug, varName);
|
|
883
|
-
const
|
|
884
|
-
|
|
890
|
+
const configLines = [];
|
|
891
|
+
if (cs.name) configLines.push(`name: ${JSON.stringify(cs.name)}`);
|
|
892
|
+
if (cs.description)
|
|
893
|
+
configLines.push(`description: ${JSON.stringify(cs.description)}`);
|
|
885
894
|
const featureEntries = (cs.features || []).map((f) => {
|
|
886
895
|
const childVar = featureVars.get(f.feature) || f.feature;
|
|
887
896
|
return `${childVar}(${f.creditCost})`;
|
|
888
897
|
});
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
].filter(Boolean);
|
|
894
|
-
const decl = `creditSystem(${JSON.stringify(cs.slug)}, { ${optsParts.join(", ")} })`;
|
|
898
|
+
configLines.push(`features: [${featureEntries.join(", ")}]`);
|
|
899
|
+
const decl = `creditSystem(${JSON.stringify(cs.slug)}, {
|
|
900
|
+
${configLines.join(",\n ")}
|
|
901
|
+
})`;
|
|
895
902
|
if (isCjs) {
|
|
896
903
|
creditSystemLines.push(`const ${varName} = ${decl};`);
|
|
897
|
-
creditSystemLines.push(`exports.${varName} = ${varName};`);
|
|
898
904
|
} else {
|
|
899
905
|
creditSystemLines.push(`export const ${varName} = ${decl};`);
|
|
900
906
|
}
|
|
@@ -1021,26 +1027,39 @@ function generateConfig(plans, creditSystems = [], creditPacks = [], defaultProv
|
|
|
1021
1027
|
const imports = isCjs ? `const { ${importParts.join(", ")} } = require("owostack");` : `import { ${importParts.join(", ")} } from "owostack";`;
|
|
1022
1028
|
const tsCheck = !isTs ? `// @ts-check` : "";
|
|
1023
1029
|
const jsDoc = !isTs ? `/** @type {import('owostack').Owostack} */` : "";
|
|
1024
|
-
const owoDecl = isCjs ? "
|
|
1030
|
+
const owoDecl = isCjs ? "const owo =" : "export const owo =";
|
|
1025
1031
|
const secretKey = isTs ? "process.env.OWOSTACK_SECRET_KEY!" : "process.env.OWOSTACK_SECRET_KEY";
|
|
1032
|
+
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;
|
|
1026
1046
|
return [
|
|
1027
1047
|
tsCheck,
|
|
1028
1048
|
imports,
|
|
1029
1049
|
``,
|
|
1030
1050
|
...featureLines,
|
|
1031
1051
|
...hasCreditSystems ? ["", ...creditSystemLines] : [],
|
|
1032
|
-
...hasCreditPacks ? ["", ...creditPackLines] : [],
|
|
1033
1052
|
``,
|
|
1034
1053
|
jsDoc,
|
|
1035
1054
|
`${owoDecl} new Owostack({`,
|
|
1036
1055
|
` secretKey: ${secretKey},`,
|
|
1037
1056
|
providerLine,
|
|
1038
1057
|
` catalog: [`,
|
|
1039
|
-
` ${
|
|
1040
|
-
...hasCreditPacks ? [` ${creditPackLines.join(",\n ")}`] : [],
|
|
1058
|
+
` ${catalogEntries.join(",\n ")}`,
|
|
1041
1059
|
` ],`,
|
|
1042
1060
|
`});`,
|
|
1043
|
-
|
|
1061
|
+
``,
|
|
1062
|
+
finalFooter
|
|
1044
1063
|
].filter(Boolean).join("\n");
|
|
1045
1064
|
}
|
|
1046
1065
|
|
|
@@ -1503,6 +1522,7 @@ async function runInit(options) {
|
|
|
1503
1522
|
const configContent = generateConfig(
|
|
1504
1523
|
plans,
|
|
1505
1524
|
creditSystems,
|
|
1525
|
+
[],
|
|
1506
1526
|
void 0,
|
|
1507
1527
|
format
|
|
1508
1528
|
);
|
|
@@ -1517,7 +1537,7 @@ ${pc7.dim("Credit Systems:")} ${creditSystems.length}`,
|
|
|
1517
1537
|
);
|
|
1518
1538
|
p6.outro(
|
|
1519
1539
|
pc7.cyan(
|
|
1520
|
-
`Next step: Run ${pc7.bold("
|
|
1540
|
+
`Next step: Run ${pc7.bold("owosk sync")} to apply your catalog.`
|
|
1521
1541
|
)
|
|
1522
1542
|
);
|
|
1523
1543
|
} catch (e) {
|