@verentis/cli 0.2.14 → 0.2.15
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 +19 -0
- package/dist/index.js +108 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -164,7 +164,26 @@ At runtime this is still an iframe launch: the SDK receives
|
|
|
164
164
|
|
|
165
165
|
## Marketplace publishing
|
|
166
166
|
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Create projects from npm templates
|
|
170
|
+
|
|
171
|
+
Create commands use published npm template packages rather than GitHub template
|
|
172
|
+
repositories:
|
|
173
|
+
|
|
167
174
|
```bash
|
|
175
|
+
verentis create application my-app
|
|
176
|
+
verentis create engine my-python-engine
|
|
177
|
+
verentis create bundle sample-data
|
|
178
|
+
verentis create canvas-component starter-widgets
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
The initial mappings are `@verentis/template-application`,
|
|
182
|
+
`@verentis/template-engine`, `@verentis/template-bundle`, and
|
|
183
|
+
`@verentis/template-canvas-component`. Use `--package` for a compatible
|
|
184
|
+
third-party template, `--version` to pin it, and `--registry` for a private
|
|
185
|
+
npm registry. Templates are installed with `npm pack --ignore-scripts` and
|
|
186
|
+
support `{{name}}` and `{{type}}` substitutions.bash
|
|
168
187
|
verentis publisher create --name acme --display-name "Acme Inc."
|
|
169
188
|
verentis publisher create --name acme --display-name "Acme Inc." --logo ./brand/logo.png
|
|
170
189
|
verentis publisher update --description "Tools for data teams" --website https://acme.example
|
package/dist/index.js
CHANGED
|
@@ -3,13 +3,15 @@ import { Command, Option } from 'commander';
|
|
|
3
3
|
import { mkdir, stat, writeFile, readFile, readdir, realpath, mkdtemp, rm, glob } from 'fs/promises';
|
|
4
4
|
import { tmpdir, homedir } from 'os';
|
|
5
5
|
import { resolve, basename, dirname, posix, join, isAbsolute, extname, relative, sep } from 'path';
|
|
6
|
-
import { spawn, spawnSync } from 'child_process';
|
|
6
|
+
import { execFile, spawn, spawnSync } from 'child_process';
|
|
7
|
+
import { promisify } from 'util';
|
|
8
|
+
import * as tar from 'tar';
|
|
9
|
+
import { extract } from 'tar';
|
|
7
10
|
import { generateKeyPairSync, createHash, randomUUID, randomBytes, createCipheriv, createPublicKey, verify, diffieHellman, hkdfSync, sign, createPrivateKey } from 'crypto';
|
|
8
11
|
import { parse, stringify, parseDocument } from 'yaml';
|
|
9
12
|
import { createWriteStream, readFileSync, createReadStream } from 'fs';
|
|
10
13
|
import { Readable } from 'stream';
|
|
11
14
|
import { pipeline } from 'stream/promises';
|
|
12
|
-
import * as tar from 'tar';
|
|
13
15
|
import { fileURLToPath } from 'url';
|
|
14
16
|
|
|
15
17
|
function insecureFetchOptions(insecure) {
|
|
@@ -137,7 +139,7 @@ async function refreshIdentityToken(apiUrl, refreshToken, insecure) {
|
|
|
137
139
|
`Session could not be renewed${payload?.error ? ` (${payload.error})` : ` (${res.status})`}. Run \`verentis login\` again.`
|
|
138
140
|
);
|
|
139
141
|
}
|
|
140
|
-
var sleep = (ms) => new Promise((
|
|
142
|
+
var sleep = (ms) => new Promise((resolve12) => setTimeout(resolve12, ms));
|
|
141
143
|
|
|
142
144
|
// src/http.ts
|
|
143
145
|
var ApiError = class extends Error {
|
|
@@ -810,6 +812,105 @@ function registerApiKey(program2) {
|
|
|
810
812
|
console.log(`Removed ${scopeName} from API key ${apiKeyId}.`);
|
|
811
813
|
});
|
|
812
814
|
}
|
|
815
|
+
var execFileAsync = promisify(execFile);
|
|
816
|
+
var TEMPLATE_PACKAGES = {
|
|
817
|
+
application: "@verentis/template-application",
|
|
818
|
+
engine: "@verentis/template-engine",
|
|
819
|
+
bundle: "@verentis/template-bundle",
|
|
820
|
+
"canvas-component": "@verentis/template-canvas-component"
|
|
821
|
+
};
|
|
822
|
+
function normalizeTemplateType(value) {
|
|
823
|
+
const normalized = value.trim().toLowerCase().replace(/[_\s]+/g, "-");
|
|
824
|
+
if (normalized === "canvas" || normalized === "component" || normalized === "canvas-pack") {
|
|
825
|
+
return "canvas-component";
|
|
826
|
+
}
|
|
827
|
+
if (normalized === "app") return "application";
|
|
828
|
+
if (normalized === "execution-engine") return "engine";
|
|
829
|
+
if (normalized === "bundle") return "bundle";
|
|
830
|
+
if (normalized === "application" || normalized === "engine" || normalized === "canvas-component") {
|
|
831
|
+
return normalized;
|
|
832
|
+
}
|
|
833
|
+
throw new Error(`Unknown template type '${value}' \u2014 use application, engine, bundle or canvas-component.`);
|
|
834
|
+
}
|
|
835
|
+
async function createFromTemplate(typeValue, name, destination, options = {}) {
|
|
836
|
+
const type = normalizeTemplateType(typeValue);
|
|
837
|
+
validateProjectName(name);
|
|
838
|
+
const target = resolve(destination ?? name);
|
|
839
|
+
if (await exists(target)) {
|
|
840
|
+
if (!options.force) throw new Error(`${target} already exists. Choose another directory or pass --force.`);
|
|
841
|
+
if (!(await stat(target)).isDirectory()) throw new Error(`${target} exists and is not a directory.`);
|
|
842
|
+
if ((await readdir(target)).length > 0) throw new Error(`${target} is not empty. --force only allows an existing empty directory.`);
|
|
843
|
+
} else {
|
|
844
|
+
await mkdir(target, { recursive: true });
|
|
845
|
+
}
|
|
846
|
+
const packageName = options.packageName ?? TEMPLATE_PACKAGES[type];
|
|
847
|
+
const spec = options.version ? `${packageName}@${options.version}` : packageName;
|
|
848
|
+
const tempDir = await mkdtemp(join(tmpdir(), "verentis-template-"));
|
|
849
|
+
try {
|
|
850
|
+
const { stdout } = await execFileAsync("npm", [
|
|
851
|
+
"pack",
|
|
852
|
+
spec,
|
|
853
|
+
"--json",
|
|
854
|
+
"--ignore-scripts",
|
|
855
|
+
...options.registry ? ["--registry", options.registry] : []
|
|
856
|
+
], { cwd: tempDir, maxBuffer: 1024 * 1024 });
|
|
857
|
+
const result = JSON.parse(stdout);
|
|
858
|
+
const archive = result[0]?.filename;
|
|
859
|
+
if (!archive) throw new Error(`npm pack did not return an archive for ${spec}.`);
|
|
860
|
+
await extractTemplateArchive(join(tempDir, archive), target);
|
|
861
|
+
await substituteTemplateValues(target, { name, type });
|
|
862
|
+
} finally {
|
|
863
|
+
await rm(tempDir, { recursive: true, force: true });
|
|
864
|
+
}
|
|
865
|
+
return { type, packageName, directory: target };
|
|
866
|
+
}
|
|
867
|
+
async function extractTemplateArchive(archive, target) {
|
|
868
|
+
await extract({ file: archive, cwd: target, strip: 1 });
|
|
869
|
+
}
|
|
870
|
+
async function substituteTemplateValues(root, values) {
|
|
871
|
+
const entries = await readdir(root, { withFileTypes: true });
|
|
872
|
+
for (const entry of entries) {
|
|
873
|
+
const path = join(root, entry.name);
|
|
874
|
+
if (entry.isDirectory()) {
|
|
875
|
+
await substituteTemplateValues(path, values);
|
|
876
|
+
continue;
|
|
877
|
+
}
|
|
878
|
+
if (!entry.isFile() || entry.name === "node_modules") continue;
|
|
879
|
+
const content = await readFile(path);
|
|
880
|
+
if (content.includes(0)) continue;
|
|
881
|
+
const text = content.toString("utf8");
|
|
882
|
+
const substituted = text.replace(/\{\{(name|type)\}\}/g, (_, key) => values[key] ?? "");
|
|
883
|
+
if (substituted !== text) await writeFile(path, substituted);
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
function validateProjectName(name) {
|
|
887
|
+
if (!/^[a-z0-9][a-z0-9-]*$/.test(name)) {
|
|
888
|
+
throw new Error(`Invalid project name '${name}' \u2014 use lowercase letters, digits and hyphens.`);
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
async function exists(path) {
|
|
892
|
+
try {
|
|
893
|
+
await stat(path);
|
|
894
|
+
return true;
|
|
895
|
+
} catch {
|
|
896
|
+
return false;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// src/commands/create.ts
|
|
901
|
+
function registerCreate(program2) {
|
|
902
|
+
program2.command("create <type> <name> [directory]").description("Create a project from an npm-backed Verentis template").option("--package <name>", "override the npm template package").option("--version <version>", "use a specific template package version").option("--registry <url>", "use an npm registry other than the default").option("--force", "create in an existing empty directory").action(async (type, name, directory, options) => {
|
|
903
|
+
const result = await createFromTemplate(type, name, directory, {
|
|
904
|
+
packageName: options.package,
|
|
905
|
+
version: options.version,
|
|
906
|
+
registry: options.registry,
|
|
907
|
+
force: options.force
|
|
908
|
+
});
|
|
909
|
+
console.log(`Created ${result.type} project in ${result.directory}`);
|
|
910
|
+
console.log(` template: ${result.packageName}`);
|
|
911
|
+
console.log("Next steps: install dependencies, then run `verentis validate` and `verentis pack`.");
|
|
912
|
+
});
|
|
913
|
+
}
|
|
813
914
|
function buildLocalContext(input) {
|
|
814
915
|
const payload = decodeJwtPayload(input.accessToken);
|
|
815
916
|
const expiresAt = payload?.exp ? new Date(payload.exp * 1e3).toISOString() : void 0;
|
|
@@ -1606,7 +1707,7 @@ async function followExecution(api, workspaceId, executionId, json) {
|
|
|
1606
1707
|
if (exec.status !== "Completed") process.exitCode = 1;
|
|
1607
1708
|
return;
|
|
1608
1709
|
}
|
|
1609
|
-
await new Promise((
|
|
1710
|
+
await new Promise((resolve12) => setTimeout(resolve12, 1e3));
|
|
1610
1711
|
}
|
|
1611
1712
|
console.error("Timed out waiting for a terminal status \u2014 check `verentis exec get`.");
|
|
1612
1713
|
process.exitCode = 1;
|
|
@@ -1876,13 +1977,13 @@ function registerInit(program2) {
|
|
|
1876
1977
|
await mkdir(targetDir, { recursive: true });
|
|
1877
1978
|
const name = (options.name ?? targetDir.split("/").pop() ?? "my-package").toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
|
1878
1979
|
const manifestPath = join(targetDir, "manifest.yaml");
|
|
1879
|
-
if (await
|
|
1980
|
+
if (await exists2(manifestPath)) throw new Error(`${manifestPath} already exists.`);
|
|
1880
1981
|
await writeFile(manifestPath, template(name));
|
|
1881
1982
|
console.log(`Created ${manifestPath} (kind: ${options.kind}).`);
|
|
1882
1983
|
console.log("Fill in packaging.publisher and packaging.files, then run `verentis pack`.");
|
|
1883
1984
|
});
|
|
1884
1985
|
}
|
|
1885
|
-
async function
|
|
1986
|
+
async function exists2(path) {
|
|
1886
1987
|
try {
|
|
1887
1988
|
await stat(path);
|
|
1888
1989
|
return true;
|
|
@@ -3690,6 +3791,7 @@ registerFiles(program);
|
|
|
3690
3791
|
registerExec(program);
|
|
3691
3792
|
registerDev(program);
|
|
3692
3793
|
registerValidate(program);
|
|
3794
|
+
registerCreate(program);
|
|
3693
3795
|
registerPublisher(program);
|
|
3694
3796
|
registerKeygen(program);
|
|
3695
3797
|
registerInit(program);
|