atmn 0.0.18 → 0.0.19

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/cli.cjs CHANGED
@@ -83,8 +83,18 @@ export const pro = product({
83
83
  `;
84
84
  var notNullish = (value) => value !== null && value !== void 0;
85
85
  var nullish = (value) => value === null || value === void 0;
86
- function idToVar(id) {
87
- return id.replace(/[-_](.)/g, (_, letter) => letter.toUpperCase()).replace(/^[^a-zA-Z_$]/, "_").replace(/[^a-zA-Z0-9_$]/g, "");
86
+ function idToVar({
87
+ id,
88
+ prefix = "product"
89
+ }) {
90
+ const processed = id.replace(/[-_](.)/g, (_, letter) => letter.toUpperCase()).replace(/[^a-zA-Z0-9_$]/g, "");
91
+ if (/^[0-9]/.test(processed)) {
92
+ return `${prefix}${processed}`;
93
+ }
94
+ if (/^[^a-zA-Z_$]/.test(processed)) {
95
+ return `${prefix}${processed}`;
96
+ }
97
+ return processed;
88
98
  }
89
99
  async function upsertEnvVar(filePath, varName, newValue) {
90
100
  const content = fs__default.default.readFileSync(filePath, "utf-8");
@@ -295,7 +305,7 @@ function productBuilder({
295
305
  features
296
306
  }) {
297
307
  const snippet = `
298
- export const ${idToVar(product.id)} = product({
308
+ export const ${idToVar({ id: product.id, prefix: "product" })} = product({
299
309
  id: '${product.id}',
300
310
  name: '${product.name}',
301
311
  items: [${product.items.map(
@@ -331,9 +341,10 @@ var getIntervalStr = ({ item }) => {
331
341
  };
332
342
  var getEntityFeatureIdStr = ({ item }) => {
333
343
  if (nullish(item.entity_feature_id)) return "";
334
- return `${getItemFieldPrefix()}entity_feature_id: ${idToVar(
335
- item.entity_feature_id
336
- )}.id,`;
344
+ return `${getItemFieldPrefix()}entity_feature_id: ${idToVar({
345
+ id: item.entity_feature_id,
346
+ prefix: "feature"
347
+ })}.id,`;
337
348
  };
338
349
  var getPriceStr = ({ item }) => {
339
350
  if (item.tiers) {
@@ -357,7 +368,7 @@ function pricedFeatureItemBuilder({
357
368
  const priceStr = getPriceStr({ item });
358
369
  const snippet = `
359
370
  pricedFeatureItem({
360
- feature_id: ${idToVar(item.feature_id)}.id,
371
+ feature_id: ${idToVar({ id: item.feature_id, prefix: "feature" })}.id,
361
372
  ${priceStr}${intervalStr}
362
373
  included_usage: ${item.included_usage == "inf" ? `"inf"` : item.included_usage},
363
374
  billing_units: ${item.billing_units},
@@ -375,7 +386,7 @@ function featureItemBuilder({
375
386
  const resetUsageStr = getResetUsageStr({ item, features });
376
387
  const snippet = `
377
388
  featureItem({
378
- feature_id: ${idToVar(item.feature_id)}.id,
389
+ feature_id: ${idToVar({ id: item.feature_id, prefix: "feature" })}.id,
379
390
  included_usage: ${item.included_usage == "inf" ? `"inf"` : item.included_usage},${intervalStr}${resetUsageStr}${entityFeatureIdStr}
380
391
  }),
381
392
  `;
@@ -409,7 +420,7 @@ var creditSchemaBuilder = (feature) => {
409
420
  };
410
421
  function featureBuilder(feature) {
411
422
  const snippet = `
412
- export const ${idToVar(feature.id)} = feature({
423
+ export const ${idToVar({ id: feature.id, prefix: "feature" })} = feature({
413
424
  id: '${feature.id}',
414
425
  name: '${feature.name}',
415
426
  type: '${feature.type}',${creditSchemaBuilder(feature)}
package/dist/cli.js CHANGED
@@ -65,8 +65,18 @@ export const pro = product({
65
65
  `;
66
66
  var notNullish = (value) => value !== null && value !== void 0;
67
67
  var nullish = (value) => value === null || value === void 0;
68
- function idToVar(id) {
69
- return id.replace(/[-_](.)/g, (_, letter) => letter.toUpperCase()).replace(/^[^a-zA-Z_$]/, "_").replace(/[^a-zA-Z0-9_$]/g, "");
68
+ function idToVar({
69
+ id,
70
+ prefix = "product"
71
+ }) {
72
+ const processed = id.replace(/[-_](.)/g, (_, letter) => letter.toUpperCase()).replace(/[^a-zA-Z0-9_$]/g, "");
73
+ if (/^[0-9]/.test(processed)) {
74
+ return `${prefix}${processed}`;
75
+ }
76
+ if (/^[^a-zA-Z_$]/.test(processed)) {
77
+ return `${prefix}${processed}`;
78
+ }
79
+ return processed;
70
80
  }
71
81
  async function upsertEnvVar(filePath, varName, newValue) {
72
82
  const content = fs.readFileSync(filePath, "utf-8");
@@ -277,7 +287,7 @@ function productBuilder({
277
287
  features
278
288
  }) {
279
289
  const snippet = `
280
- export const ${idToVar(product.id)} = product({
290
+ export const ${idToVar({ id: product.id, prefix: "product" })} = product({
281
291
  id: '${product.id}',
282
292
  name: '${product.name}',
283
293
  items: [${product.items.map(
@@ -313,9 +323,10 @@ var getIntervalStr = ({ item }) => {
313
323
  };
314
324
  var getEntityFeatureIdStr = ({ item }) => {
315
325
  if (nullish(item.entity_feature_id)) return "";
316
- return `${getItemFieldPrefix()}entity_feature_id: ${idToVar(
317
- item.entity_feature_id
318
- )}.id,`;
326
+ return `${getItemFieldPrefix()}entity_feature_id: ${idToVar({
327
+ id: item.entity_feature_id,
328
+ prefix: "feature"
329
+ })}.id,`;
319
330
  };
320
331
  var getPriceStr = ({ item }) => {
321
332
  if (item.tiers) {
@@ -339,7 +350,7 @@ function pricedFeatureItemBuilder({
339
350
  const priceStr = getPriceStr({ item });
340
351
  const snippet = `
341
352
  pricedFeatureItem({
342
- feature_id: ${idToVar(item.feature_id)}.id,
353
+ feature_id: ${idToVar({ id: item.feature_id, prefix: "feature" })}.id,
343
354
  ${priceStr}${intervalStr}
344
355
  included_usage: ${item.included_usage == "inf" ? `"inf"` : item.included_usage},
345
356
  billing_units: ${item.billing_units},
@@ -357,7 +368,7 @@ function featureItemBuilder({
357
368
  const resetUsageStr = getResetUsageStr({ item, features });
358
369
  const snippet = `
359
370
  featureItem({
360
- feature_id: ${idToVar(item.feature_id)}.id,
371
+ feature_id: ${idToVar({ id: item.feature_id, prefix: "feature" })}.id,
361
372
  included_usage: ${item.included_usage == "inf" ? `"inf"` : item.included_usage},${intervalStr}${resetUsageStr}${entityFeatureIdStr}
362
373
  }),
363
374
  `;
@@ -391,7 +402,7 @@ var creditSchemaBuilder = (feature) => {
391
402
  };
392
403
  function featureBuilder(feature) {
393
404
  const snippet = `
394
- export const ${idToVar(feature.id)} = feature({
405
+ export const ${idToVar({ id: feature.id, prefix: "feature" })} = feature({
395
406
  id: '${feature.id}',
396
407
  name: '${feature.name}',
397
408
  type: '${feature.type}',${creditSchemaBuilder(feature)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "atmn",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "license": "MIT",
5
5
  "bin": "dist/cli.js",
6
6
  "main": "dist/index.js",