@embeddables/cli 0.6.2 → 0.6.4

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 CHANGED
@@ -74,6 +74,10 @@ Authenticate with your Embeddables account.
74
74
 
75
75
  Clear stored authentication.
76
76
 
77
+ ### `embeddables upgrade`
78
+
79
+ Update the CLI to the latest stable version. Fetches the latest release from npm and runs `npm install -g @embeddables/cli@latest`.
80
+
77
81
  ### `embeddables pull`
78
82
 
79
83
  Fetch an embeddable from the cloud and reverse-compile it into local TSX files.
package/dist/cli.js CHANGED
@@ -1,5 +1,11 @@
1
+ import { createRequire } from 'node:module';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
1
4
  import { Command } from 'commander';
2
5
  import pc from 'picocolors';
6
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
7
+ const require = createRequire(import.meta.url);
8
+ const pkg = require(path.join(__dirname, '..', 'package.json'));
3
9
  import { runBranch } from './commands/branch.js';
4
10
  import { runBuild } from './commands/build.js';
5
11
  import { runDev } from './commands/dev.js';
@@ -9,6 +15,7 @@ import { runLogin } from './commands/login.js';
9
15
  import { runLogout } from './commands/logout.js';
10
16
  import { runPull } from './commands/pull.js';
11
17
  import { runSave } from './commands/save.js';
18
+ import { runUpgrade } from './commands/upgrade.js';
12
19
  // Make all console.warn output yellow
13
20
  const originalWarn = console.warn.bind(console);
14
21
  console.warn = (...args) => {
@@ -19,7 +26,10 @@ console.error = (...args) => {
19
26
  originalError(...args.map((arg) => typeof arg === 'string' ? `${pc.bold(pc.bgRed(' ERROR '))} ${pc.red(arg)}` : arg));
20
27
  };
21
28
  const program = new Command();
22
- program.name('embeddables').description('Embeddables CLI').version('0.1.0');
29
+ program
30
+ .name('embeddables')
31
+ .description('Embeddables CLI')
32
+ .version(pkg.version, '-v, --version', 'Show CLI version');
23
33
  program
24
34
  .command('init')
25
35
  .description('Initialize a new Embeddables project')
@@ -95,6 +105,12 @@ program
95
105
  fromVersion: opts.fromVersion,
96
106
  });
97
107
  });
108
+ program
109
+ .command('upgrade')
110
+ .description('Update the CLI to the latest stable version')
111
+ .action(async () => {
112
+ await runUpgrade();
113
+ });
98
114
  program
99
115
  .command('branch')
100
116
  .description('Switch to a different branch of an embeddable')
@@ -0,0 +1,2 @@
1
+ export declare function runUpgrade(): Promise<void>;
2
+ //# sourceMappingURL=upgrade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../../src/commands/upgrade.ts"],"names":[],"mappings":"AAwBA,wBAAsB,UAAU,kBAqC/B"}
@@ -0,0 +1,51 @@
1
+ import { createRequire } from 'node:module';
2
+ import { execSync } from 'node:child_process';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { dirname, join } from 'node:path';
5
+ import pc from 'picocolors';
6
+ const require = createRequire(import.meta.url);
7
+ function getCurrentVersion() {
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+ const pkgPath = join(__dirname, '..', '..', 'package.json');
10
+ const pkg = require(pkgPath);
11
+ return pkg.version;
12
+ }
13
+ async function getLatestVersion() {
14
+ const res = await fetch('https://registry.npmjs.org/@embeddables/cli/latest');
15
+ if (!res.ok) {
16
+ throw new Error(`Failed to fetch latest version: ${res.status}`);
17
+ }
18
+ const data = (await res.json());
19
+ return data.version;
20
+ }
21
+ export async function runUpgrade() {
22
+ try {
23
+ const currentVersion = getCurrentVersion();
24
+ console.log('');
25
+ console.log(pc.cyan('Checking for updates...'));
26
+ const latestVersion = await getLatestVersion();
27
+ if (currentVersion === latestVersion) {
28
+ console.log(pc.green(`✓ Already on the latest version (${latestVersion})`));
29
+ console.log('');
30
+ return;
31
+ }
32
+ console.log(pc.cyan(`Upgrading from ${currentVersion} to ${latestVersion}...`));
33
+ console.log('');
34
+ execSync(`npm install -g @embeddables/cli@latest`, {
35
+ stdio: 'inherit',
36
+ });
37
+ console.log('');
38
+ console.log(pc.green(`✓ Successfully upgraded to @embeddables/cli@${latestVersion}`));
39
+ console.log('');
40
+ }
41
+ catch (error) {
42
+ const message = error instanceof Error ? error.message : String(error);
43
+ if (message.includes('EACCES') || message.includes('permission')) {
44
+ console.error(pc.red('Permission denied. Try running with sudo: sudo npm install -g @embeddables/cli@latest'));
45
+ }
46
+ else {
47
+ console.error(pc.red(`Error during upgrade: ${message}`));
48
+ }
49
+ process.exit(1);
50
+ }
51
+ }
@@ -806,7 +806,10 @@ function generateCustomValidationFunctions(node) {
806
806
  validationFunctionNameMap.set(compId, fnName);
807
807
  const body = extractFunctionBody(code);
808
808
  if (body !== null) {
809
- const indentedBody = body.split('\n').map((l) => ' ' + l.trimStart()).join('\n');
809
+ const indentedBody = body
810
+ .split('\n')
811
+ .map((l) => ' ' + l.trimStart())
812
+ .join('\n');
810
813
  lines.push(` function ${fnName}(value) {\n${indentedBody}\n }`);
811
814
  }
812
815
  else {
@@ -966,9 +969,7 @@ function generateJSX(node, indent = 4, pageKey, componentId, nameMap, validation
966
969
  if (typeof value === 'string') {
967
970
  // custom_validation_function: emit as function reference (validate, validate2, ...)
968
971
  if (key === 'custom_validation_function') {
969
- const fnName = validationFunctionNameMap?.get(comp.id) ??
970
- identifierToGeneratedName?.get(value) ??
971
- value;
972
+ const fnName = validationFunctionNameMap?.get(comp.id) ?? identifierToGeneratedName?.get(value) ?? value;
972
973
  props.push(`custom_validation_function={${fnName}}`);
973
974
  continue;
974
975
  }
@@ -1510,9 +1511,10 @@ function escapeStringForJS(str) {
1510
1511
  // Check if string contains double quotes - if so, use template literals
1511
1512
  const hasDoubleQuotes = str.includes('"');
1512
1513
  if (hasDoubleQuotes) {
1513
- // Use template literals (backticks) - escape backticks and backslashes
1514
+ // Use template literals (backticks) - escape backticks, backslashes, and ${ (template interpolation)
1514
1515
  let escaped = str
1515
1516
  .replace(/\\/g, '\\\\') // Escape backslashes first
1517
+ .replace(/\$\{/g, '\\${') // Escape ${ so literal ${{ ... }} (e.g. product_data) is preserved
1516
1518
  .replace(/`/g, '\\`'); // Escape backticks
1517
1519
  // Escape newlines
1518
1520
  escaped = escaped
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/proxy/server.ts"],"names":[],"mappings":"AAmCA,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;;GAoTA"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/proxy/server.ts"],"names":[],"mappings":"AAmCA,wBAAsB,gBAAgB,CAAC,IAAI,EAAE;IAC3C,IAAI,EAAE,MAAM,CAAA;IACZ,YAAY,EAAE,MAAM,CAAA;IACpB,aAAa,EAAE,MAAM,CAAA;IACrB,iBAAiB,EAAE,MAAM,CAAA;IACzB,YAAY,EAAE,MAAM,CAAA;IACpB,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;;GA0TA"}
@@ -150,10 +150,15 @@ export async function startProxyServer(opts) {
150
150
  const generatedJson = JSON.parse(raw);
151
151
  generatedJson.id = opts.embeddableId;
152
152
  console.log(`[/init] Loaded local JSON, pages: ${generatedJson.pages?.length ?? 0}`);
153
+ // Strip content_sources before sending to engine (keep in embeddable.json/config.json)
154
+ const flowForEngine = { ...generatedJson };
155
+ if ('content_sources' in flowForEngine) {
156
+ delete flowForEngine.content_sources;
157
+ }
153
158
  // Create POST request body with the JSON
154
159
  const postBody = {
155
160
  json: {
156
- flow: generatedJson,
161
+ flow: flowForEngine,
157
162
  flowId: generatedJson.id,
158
163
  groupId: 'group_test',
159
164
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddables/cli",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "embeddables": "./bin/embeddables.mjs"