@embeddables/cli 0.6.2 → 0.6.3
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 +4 -0
- package/dist/cli.js +7 -0
- package/dist/commands/upgrade.d.ts +2 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +51 -0
- package/dist/compiler/reverse.js +7 -5
- package/dist/proxy/server.d.ts.map +1 -1
- package/dist/proxy/server.js +6 -1
- package/package.json +1 -1
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
|
@@ -9,6 +9,7 @@ import { runLogin } from './commands/login.js';
|
|
|
9
9
|
import { runLogout } from './commands/logout.js';
|
|
10
10
|
import { runPull } from './commands/pull.js';
|
|
11
11
|
import { runSave } from './commands/save.js';
|
|
12
|
+
import { runUpgrade } from './commands/upgrade.js';
|
|
12
13
|
// Make all console.warn output yellow
|
|
13
14
|
const originalWarn = console.warn.bind(console);
|
|
14
15
|
console.warn = (...args) => {
|
|
@@ -95,6 +96,12 @@ program
|
|
|
95
96
|
fromVersion: opts.fromVersion,
|
|
96
97
|
});
|
|
97
98
|
});
|
|
99
|
+
program
|
|
100
|
+
.command('upgrade')
|
|
101
|
+
.description('Update the CLI to the latest stable version')
|
|
102
|
+
.action(async () => {
|
|
103
|
+
await runUpgrade();
|
|
104
|
+
});
|
|
98
105
|
program
|
|
99
106
|
.command('branch')
|
|
100
107
|
.description('Switch to a different branch of an embeddable')
|
|
@@ -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
|
+
}
|
package/dist/compiler/reverse.js
CHANGED
|
@@ -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
|
|
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
|
|
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;;
|
|
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"}
|
package/dist/proxy/server.js
CHANGED
|
@@ -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:
|
|
161
|
+
flow: flowForEngine,
|
|
157
162
|
flowId: generatedJson.id,
|
|
158
163
|
groupId: 'group_test',
|
|
159
164
|
},
|