@uniformdev/cli 17.7.1-alpha.140 → 17.7.1-alpha.169

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.mjs CHANGED
@@ -1,3 +1,175 @@
1
1
  #!/usr/bin/env node
2
- import{a as l,b,c as v}from"./chunk-LPA4W6MO.mjs";import R from"yargs";import I from"yargs";import h from"yargs";var r=b(v());import{writeFile as C}from"fs";import _ from"isomorphic-unfetch";import{exit as a}from"process";var u="https://uniform.app";var A={command:"download [output]",describe:"Download intent manifest",builder:e=>{var o;return e.option("apiKey",{alias:"k",demandOption:!0,string:!0,default:process.env.UNIFORM_API_KEY,describe:"Uniform API key to use. Defaults to UNIFORM_API_KEY env if set."}).option("project",{describe:"Uniform project ID. Defaults to UOPT_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:(o=process.env.UOPT_CLI_PROJECT_ID)!=null?o:process.env.UNIFORM_PROJECT_ID,type:"string",alias:["p"]}).option("preview",{describe:"If set, fetches the unpublished preview manifest (assuming your API key has permission)",default:!1,type:"boolean",alias:["d"]}).option("output",{string:!0,alias:"o",default:process.env.UNIFORM_MANIFEST_PATH,describe:"Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set."})},handler:async({apiKey:e,output:o,project:s,preview:m})=>{/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test(e)?console.error(r.default.yellow("WARNING: you appear to be using a deprecated type of API key. Keys like this will stop working soon; please create new keys on uniform.app.")):s||(console.error(r.default.red("You must specify the project ID")),a(1));let U=M(),d=new URLSearchParams;s&&d.set("projectId",s),m&&d.set("preview","true");let i=`${U}api/v1/manifest?${d.toString()}`,t;try{if(t=await _(i,{headers:{"x-api-key":e}}),!t.ok)throw t.status===403?`The API key ${e} had no published data. This means it is either incorrectly entered, or intents have not been published since creating the API key.`:`${t.status} ${t.statusText}, content ${await t.text()}`}catch(n){console.error(r.default.red(`\u26A0 Error fetching intent manifest ${i}`)),console.error(r.default.gray(` \u2757 ${n}`)),a(1)}let p;try{p=await t.json()}catch(n){console.error(r.default.red(r.default.red(`\u26A0 Error parsing intent manifest ${i}`))),console.error(r.default.gray(` \u2757 ${n}`)),console.error(`Response: ${await t.text()}`),a(1)}let f=JSON.stringify(p,null,2);o?C(o,f,n=>{n&&(console.error(`Error writing file to ${o}
3
- `,n),a(1)),console.log(r.default.green(`\u2705 ${o} has been updated from ${i}`))}):console.log(f)}},M=()=>{let e=process.env.UNIFORM_CLI_BASE_URL||u;return e.endsWith("/")||(e+="/"),e},y=A;var O={command:"manifest <command>",describe:"Intent manifest commands",builder:()=>h.command(y),handler:()=>h.showHelp()},g=O;var P={command:"optimize <command>",aliases:["opt"],describe:"Uniform Optimize commands",builder:()=>I.command(g),handler:()=>I.showHelp()},w=P;l("dotenv").config();var T=["@uniformdev/canvas/cli","@uniformdev/context/cli","@uniformdev/project-map/cli"],c=R.scriptName("uniform");T.flatMap(e=>{try{let o=l(e).uniformCLI.commands;(Array.isArray(o)?o:[]).forEach(m=>{c=c.command(m)})}catch{}});c.command(w).demandCommand(1,"").strict().help().argv;
2
+ import {
3
+ __require,
4
+ __toESM,
5
+ require_source
6
+ } from "./chunk-IRPO3X2Q.mjs";
7
+
8
+ // src/index.ts
9
+ import yargs3 from "yargs";
10
+
11
+ // src/commands/optimize.ts
12
+ import yargs2 from "yargs";
13
+
14
+ // src/commands/optimize/manifest.ts
15
+ import yargs from "yargs";
16
+
17
+ // src/commands/optimize/manifest/download.ts
18
+ var import_chalk = __toESM(require_source());
19
+ import { writeFile } from "fs";
20
+ import fetch from "isomorphic-unfetch";
21
+ import { exit } from "process";
22
+
23
+ // src/constants.ts
24
+ var UniformBaseUrl = "https://uniform.app";
25
+
26
+ // src/commands/optimize/manifest/download.ts
27
+ var module = {
28
+ command: "download [output]",
29
+ describe: "Download intent manifest",
30
+ builder: (yargs4) => {
31
+ var _a;
32
+ return yargs4.option("apiKey", {
33
+ alias: "k",
34
+ demandOption: true,
35
+ string: true,
36
+ default: process.env.UNIFORM_API_KEY,
37
+ describe: "Uniform API key to use. Defaults to UNIFORM_API_KEY env if set."
38
+ }).option("project", {
39
+ describe: "Uniform project ID. Defaults to UOPT_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",
40
+ default: (_a = process.env.UOPT_CLI_PROJECT_ID) != null ? _a : process.env.UNIFORM_PROJECT_ID,
41
+ type: "string",
42
+ alias: ["p"]
43
+ }).option("preview", {
44
+ describe: "If set, fetches the unpublished preview manifest (assuming your API key has permission)",
45
+ default: false,
46
+ type: "boolean",
47
+ alias: ["d"]
48
+ }).option("output", {
49
+ string: true,
50
+ alias: "o",
51
+ default: process.env.UNIFORM_MANIFEST_PATH,
52
+ describe: "Path to write manifest to. Defaults to UNIFORM_MANIFEST_PATH env if set."
53
+ });
54
+ },
55
+ handler: async ({ apiKey, output, project, preview }) => {
56
+ const isLegacyApiKey = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test(
57
+ apiKey
58
+ );
59
+ if (isLegacyApiKey) {
60
+ console.error(
61
+ import_chalk.default.yellow(
62
+ "WARNING: you appear to be using a deprecated type of API key. Keys like this will stop working soon; please create new keys on uniform.app."
63
+ )
64
+ );
65
+ } else if (!project) {
66
+ console.error(import_chalk.default.red("You must specify the project ID"));
67
+ exit(1);
68
+ }
69
+ const baseUrl = resolveBaseUrl();
70
+ const qs = new URLSearchParams();
71
+ if (project) {
72
+ qs.set("projectId", project);
73
+ }
74
+ if (preview) {
75
+ qs.set("preview", "true");
76
+ }
77
+ const manifestUrl = `${baseUrl}api/v1/manifest?${qs.toString()}`;
78
+ let fetchResponse = void 0;
79
+ try {
80
+ fetchResponse = await fetch(manifestUrl, {
81
+ headers: {
82
+ "x-api-key": apiKey
83
+ }
84
+ });
85
+ if (!fetchResponse.ok) {
86
+ if (fetchResponse.status === 403) {
87
+ throw `The API key ${apiKey} had no published data. This means it is either incorrectly entered, or intents have not been published since creating the API key.`;
88
+ }
89
+ throw `${fetchResponse.status} ${fetchResponse.statusText}, content ${await fetchResponse.text()}`;
90
+ }
91
+ } catch (e) {
92
+ console.error(import_chalk.default.red(`\u26A0 Error fetching intent manifest ${manifestUrl}`));
93
+ console.error(import_chalk.default.gray(` \u2757 ${e}`));
94
+ exit(1);
95
+ }
96
+ let json;
97
+ try {
98
+ json = await fetchResponse.json();
99
+ } catch (e) {
100
+ console.error(import_chalk.default.red(import_chalk.default.red(`\u26A0 Error parsing intent manifest ${manifestUrl}`)));
101
+ console.error(import_chalk.default.gray(` \u2757 ${e}`));
102
+ console.error(`Response: ${await fetchResponse.text()}`);
103
+ exit(1);
104
+ }
105
+ const text = JSON.stringify(json, null, 2);
106
+ if (output) {
107
+ writeFile(output, text, (error) => {
108
+ if (error) {
109
+ console.error(`Error writing file to ${output}
110
+ `, error);
111
+ exit(1);
112
+ }
113
+ console.log(import_chalk.default.green(`\u2705 ${output} has been updated from ${manifestUrl}`));
114
+ });
115
+ } else {
116
+ console.log(text);
117
+ }
118
+ }
119
+ };
120
+ var resolveBaseUrl = () => {
121
+ let baseUrl = process.env.UNIFORM_CLI_BASE_URL || UniformBaseUrl;
122
+ if (!baseUrl.endsWith("/")) {
123
+ baseUrl += "/";
124
+ }
125
+ return baseUrl;
126
+ };
127
+ var download_default = module;
128
+
129
+ // src/commands/optimize/manifest.ts
130
+ var module2 = {
131
+ command: "manifest <command>",
132
+ describe: "Intent manifest commands",
133
+ builder: () => {
134
+ return yargs.command(download_default);
135
+ },
136
+ handler: () => {
137
+ return yargs.showHelp();
138
+ }
139
+ };
140
+ var manifest_default = module2;
141
+
142
+ // src/commands/optimize.ts
143
+ var command = {
144
+ command: "optimize <command>",
145
+ aliases: ["opt"],
146
+ describe: "Uniform Optimize commands",
147
+ builder: () => {
148
+ return yargs2.command(manifest_default);
149
+ },
150
+ handler: () => {
151
+ return yargs2.showHelp();
152
+ }
153
+ };
154
+ var optimize_default = command;
155
+
156
+ // src/index.ts
157
+ __require("dotenv").config();
158
+ var plugins = [
159
+ "@uniformdev/canvas/cli",
160
+ "@uniformdev/context/cli",
161
+ "@uniformdev/project-map/cli",
162
+ "@uniformdev/uniform-new"
163
+ ];
164
+ var yarggery = yargs3.scriptName("uniform");
165
+ plugins.flatMap((plugin) => {
166
+ try {
167
+ const commands = __require(plugin).uniformCLI.commands;
168
+ const commandsToAdd = Array.isArray(commands) ? commands : [];
169
+ commandsToAdd.forEach((command2) => {
170
+ yarggery = yarggery.command(command2);
171
+ });
172
+ } catch (e) {
173
+ }
174
+ });
175
+ yarggery.command(optimize_default).demandCommand(1, "").strict().help().argv;