@uniformdev/cli 12.2.1-alpha.141 → 12.2.1-alpha.171

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.
@@ -0,0 +1 @@
1
+ var d=(a=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(a,{get:(b,c)=>(typeof require!="undefined"?require:b)[c]}):a)(function(a){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+a+'" is not supported')});export{d as a};
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- var p=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(o,n)=>(typeof require!="undefined"?require:o)[n]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+e+'" is not supported')});import R from"yargs";import U from"yargs";import I from"yargs";import t from"chalk";import{writeFile as C}from"fs";import _ from"node-fetch";import{exit as d}from"process";var h="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:n,preview:l})=>{/^(?:[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(t.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.")):n||(console.error(t.red("You must specify the project ID")),d(1));let v=M(),c=new URLSearchParams;n&&c.set("projectId",n),l&&c.set("preview","true");let i=`${v}api/v1/manifest?${c.toString()}`,r;try{if(r=await _(i,{headers:{"x-api-key":e}}),!r.ok)throw r.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.`:`${r.status} ${r.statusText}, content ${await r.text()}`}catch(s){console.error(t.red(`\u26A0 Error fetching intent manifest ${i}`)),console.error(t.gray(` \u2757 ${s}`)),d(1)}let u;try{u=await r.json()}catch(s){console.error(t.red(t.red(`\u26A0 Error parsing intent manifest ${i}`))),console.error(t.gray(` \u2757 ${s}`)),console.error(`Response: ${await r.text()}`),d(1)}let y=JSON.stringify(u,null,2);o?C(o,y,s=>{s&&(console.error(`Error writing file to ${o}
3
- `,s),d(1)),console.log(t.green(`\u2705 ${o} has been updated from ${i}`))}):console.log(y)}},M=()=>{let e=process.env.UNIFORM_CLI_BASE_URL||h;return e.endsWith("/")||(e+="/"),e},g=A;var O={command:"manifest <command>",describe:"Intent manifest commands",builder:()=>I.command(g),handler:()=>I.showHelp()},w=O;var P={command:"optimize <command>",aliases:["opt"],describe:"Uniform Optimize commands",builder:()=>U.command(w),handler:()=>U.showHelp()},b=P;p("dotenv").config();var T=["@uniformdev/canvas/cli","@uniformdev/context/cli"],f=R.scriptName("uniform");T.flatMap(e=>{try{let o=p(e).uniformCLI.commands;(Array.isArray(o)?o:[]).forEach(l=>{f=f.command(l)})}catch{}});f.command(b).demandCommand(1,"").strict().help().argv;
2
+ import{a as p}from"./chunk-74EM6MWN.mjs";import R from"yargs";import U from"yargs";import I from"yargs";import t from"chalk";import{writeFile as C}from"fs";import _ from"node-fetch";import{exit as d}from"process";var h="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:l})=>{/^(?:[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(t.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(t.red("You must specify the project ID")),d(1));let v=M(),c=new URLSearchParams;s&&c.set("projectId",s),l&&c.set("preview","true");let i=`${v}api/v1/manifest?${c.toString()}`,r;try{if(r=await _(i,{headers:{"x-api-key":e}}),!r.ok)throw r.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.`:`${r.status} ${r.statusText}, content ${await r.text()}`}catch(n){console.error(t.red(`\u26A0 Error fetching intent manifest ${i}`)),console.error(t.gray(` \u2757 ${n}`)),d(1)}let u;try{u=await r.json()}catch(n){console.error(t.red(t.red(`\u26A0 Error parsing intent manifest ${i}`))),console.error(t.gray(` \u2757 ${n}`)),console.error(`Response: ${await r.text()}`),d(1)}let y=JSON.stringify(u,null,2);o?C(o,y,n=>{n&&(console.error(`Error writing file to ${o}
3
+ `,n),d(1)),console.log(t.green(`\u2705 ${o} has been updated from ${i}`))}):console.log(y)}},M=()=>{let e=process.env.UNIFORM_CLI_BASE_URL||h;return e.endsWith("/")||(e+="/"),e},g=A;var O={command:"manifest <command>",describe:"Intent manifest commands",builder:()=>I.command(g),handler:()=>I.showHelp()},w=O;var P={command:"optimize <command>",aliases:["opt"],describe:"Uniform Optimize commands",builder:()=>U.command(w),handler:()=>U.showHelp()},b=P;p("dotenv").config();var T=["@uniformdev/canvas/cli","@uniformdev/context/cli"],f=R.scriptName("uniform");T.flatMap(e=>{try{let o=p(e).uniformCLI.commands;(Array.isArray(o)?o:[]).forEach(l=>{f=f.command(l)})}catch{}});f.command(b).demandCommand(1,"").strict().help().argv;
@@ -0,0 +1,112 @@
1
+ import { Change } from 'diff';
2
+ import { Argv } from 'yargs';
3
+
4
+ declare type SyncEngineLogOptions = {
5
+ id: string;
6
+ providerId: string;
7
+ displayName: string;
8
+ action: 'create' | 'update' | 'delete';
9
+ whatIf: boolean;
10
+ diff: Change[];
11
+ };
12
+ declare type SyncEngineObject<TObject> = {
13
+ /** Unique ID that is identical across all providers */
14
+ id: string;
15
+ /** Provider specific ID. Value is provided to deleteObject() function (always the provider ID from the same provider that issued it). */
16
+ providerId: string;
17
+ /** Optional display name of the object for log messages. The providerId will be used if this is not set. */
18
+ displayName?: string;
19
+ /** The object being synced. */
20
+ object: TObject;
21
+ };
22
+ declare type SyncEngineDataSource<TObject> = {
23
+ /** The objects to sync. */
24
+ objects: AsyncIterable<SyncEngineObject<TObject>>;
25
+ /**
26
+ * Called when the sync engine detects a need to update a synced object.
27
+ * Only called if this source is the target of a sync operation.
28
+ * @param obj The object to write to the data source
29
+ * @param existingObj The existing object that matches this one in the data source (if any)
30
+ */
31
+ writeObject: (obj: SyncEngineObject<TObject>, existingObj?: SyncEngineObject<TObject>) => Promise<void>;
32
+ /**
33
+ * Called when the sync engine detects a need to delete an object in this data source.
34
+ * Only called if this source is the target of a sync operation.
35
+ */
36
+ deleteObject: (providerId: string) => Promise<void>;
37
+ /**
38
+ * Called when the sync engine finishes synchronization.
39
+ */
40
+ onSyncComplete?: (isTarget: boolean) => Promise<void>;
41
+ };
42
+ declare type SyncEngineOptions<TObject> = {
43
+ source: SyncEngineDataSource<TObject>;
44
+ target: SyncEngineDataSource<TObject>;
45
+ compareContents?: (source: SyncEngineObject<TObject>, target: SyncEngineObject<TObject>) => boolean;
46
+ mode: 'mirror' | 'createOrUpdate' | 'create';
47
+ /** Compare sources, but do not execute actions */
48
+ whatIf?: boolean;
49
+ /** An exception will normally br thrown if the sync source has nothing in it; this option allows the sync to continue (potentially deleting everything in the target) */
50
+ allowEmptySource?: boolean;
51
+ log?: (options: SyncEngineLogOptions) => void;
52
+ };
53
+ declare function syncEngine<TObject>({ source, target, compareContents, mode, allowEmptySource, whatIf, log, }: SyncEngineOptions<TObject>): Promise<void>;
54
+
55
+ declare type CreateArraySyncEngineDataSourceOptions<TObject> = {
56
+ objects: Array<TObject>;
57
+ selectIdentifier: (object: TObject) => string;
58
+ selectDisplayName?: (object: TObject) => string;
59
+ onSyncComplete?: (isTarget: boolean, result: Array<TObject>) => Promise<void>;
60
+ };
61
+ declare function createArraySyncEngineDataSource<TObject>({ objects, selectIdentifier, selectDisplayName, onSyncComplete, }: CreateArraySyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject> & {
62
+ extractCurrent: () => Array<TObject>;
63
+ }>;
64
+
65
+ declare type CreateFileSyncEngineDataSourceOptions<TObject> = {
66
+ directory: string;
67
+ selectIdentifier: (object: TObject) => string;
68
+ selectDisplayName?: (object: TObject) => string;
69
+ selectFilename?: (object: TObject) => string;
70
+ format?: 'json' | 'yaml';
71
+ };
72
+ declare function createFileSyncEngineDataSource<TObject>({ directory, format, selectIdentifier, selectDisplayName, }: CreateFileSyncEngineDataSourceOptions<TObject>): Promise<SyncEngineDataSource<TObject>>;
73
+
74
+ declare type UniformPackage = {
75
+ [key: string]: unknown;
76
+ };
77
+ declare function readUniformPackage(filename: string, assertExists: boolean): UniformPackage;
78
+ declare function writeUniformPackage(filename: string, packageContents: UniformPackage): void;
79
+
80
+ declare type DiffMode = 'off' | 'on' | 'update';
81
+ declare function createSyncEngineConsoleLogger(options?: {
82
+ diffMode?: DiffMode;
83
+ indent?: string;
84
+ prefix?: string;
85
+ }): ({ action, displayName, whatIf, diff }: SyncEngineLogOptions) => void;
86
+
87
+ declare type ApiArgs = {
88
+ apiKey: string;
89
+ apiHost: string;
90
+ };
91
+ declare function withApiOptions<T>(yargs: Argv<T>): Argv<T>;
92
+ declare type ProjectArgs = {
93
+ project: string;
94
+ };
95
+ declare function withProjectOptions<T>(yargs: Argv<T>): Argv<T>;
96
+ declare type FormatArgs = {
97
+ format: 'json' | 'yaml';
98
+ filename?: string;
99
+ };
100
+ declare function withFormatOptions<T>(yargs: Argv<T>): Argv<T>;
101
+ declare type DiffArgs = {
102
+ diff: DiffMode;
103
+ };
104
+ declare function withDiffOptions<T>(yargs: Argv<T>): Argv<T>;
105
+ declare function isPathAPackageFile(path: string): boolean;
106
+ declare function emitWithFormat(object: any, format?: string, filename?: string): void;
107
+ declare function readFileToObject<T = unknown>(filename: string): T;
108
+ declare function paginateAsync<TResult>(fetchPage: (offset: number, limit: number) => Promise<TResult[]>, options: {
109
+ pageSize: number;
110
+ }): AsyncIterableIterator<TResult>;
111
+
112
+ export { ApiArgs, CreateArraySyncEngineDataSourceOptions, CreateFileSyncEngineDataSourceOptions, DiffArgs, DiffMode, FormatArgs, ProjectArgs, SyncEngineDataSource, SyncEngineLogOptions, SyncEngineObject, SyncEngineOptions, UniformPackage, createArraySyncEngineDataSource, createFileSyncEngineDataSource, createSyncEngineConsoleLogger, emitWithFormat, isPathAPackageFile, paginateAsync, readFileToObject, readUniformPackage, syncEngine, withApiOptions, withDiffOptions, withFormatOptions, withProjectOptions, writeUniformPackage };
@@ -0,0 +1,3 @@
1
+ var M=Object.create;var w=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,K=Object.prototype.hasOwnProperty;var D=e=>w(e,"__esModule",{value:!0});var W=(e,t)=>{for(var n in t)w(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of $(t))!K.call(e,s)&&(n||s!=="default")&&w(e,s,{get:()=>t[s],enumerable:!(r=L(t,s))||r.enumerable});return e},x=(e,t)=>F(D(w(e!=null?M(J(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),Y=(e=>(t,n)=>e&&e.get(t)||(n=F(D({}),t,1),e&&e.set(t,n),n))(typeof WeakMap!="undefined"?new WeakMap:0);var oe={};W(oe,{createArraySyncEngineDataSource:()=>H,createFileSyncEngineDataSource:()=>X,createSyncEngineConsoleLogger:()=>ne,emitWithFormat:()=>T,isPathAPackageFile:()=>G,paginateAsync:()=>Q,readFileToObject:()=>E,readUniformPackage:()=>Z,syncEngine:()=>te,withApiOptions:()=>V,withDiffOptions:()=>B,withFormatOptions:()=>z,withProjectOptions:()=>q,writeUniformPackage:()=>ee});async function H({objects:e,selectIdentifier:t,selectDisplayName:n=t,onSyncComplete:r}){let s=e.reduce((o,c)=>{let i=t(c);if(o[i])throw new Error(`Identifier ${i} was not unique.`);return o[i]={id:i,object:c,providerId:i,displayName:n(c)},o},{});async function*p(){for(let o of Object.values(s))yield o}function m(){return Object.entries(s).sort((o,c)=>o[0].localeCompare(c[0])).map(o=>o[1].object)}return{objects:p(),deleteObject:async o=>{delete s[o]},writeObject:async o=>{let c=t(o.object);s[c]=o},extractCurrent:m,onSyncComplete:r?o=>r(o,m()):void 0}}var U=x(require("chalk")),A=require("fs"),C=require("fs/promises"),v=require("path");var _=require("js-yaml"),h=require("fs"),P=require("path"),N=require("fs");function V(e){var t,n;return e.option("apiKey",{describe:"Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",default:(n=(t=process.env.CANVAS_CLI_API_KEY)!=null?t:process.env.UPM_CLI_API_KEY)!=null?n:process.env.UNIFORM_API_KEY,demandOption:!0,type:"string"}).option("apiHost",{describe:"Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or https://uniform.app. Supports dotenv.",default:process.env.UNIFORM_CLI_BASE_URL||"https://uniform.app",demandOption:!0,type:"string"})}function q(e){var t,n,r;return e.option("project",{describe:"Uniform project ID. Defaults to UNIFORM_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:(r=(n=(t=process.env.UNIFORM_CLI_PROJECT_ID)!=null?t:process.env.CANVAS_CLI_PROJECT_ID)!=null?n:process.env.UPM_CLI_PROJECT_ID)!=null?r:process.env.UNIFORM_PROJECT_ID,demandOption:!0,type:"string",alias:["p"]})}function z(e){return e.option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("filename",{alias:["o"],describe:"Output filename. If not specified, write to stdout.",type:"string"})}function B(e){var t;return e.option("diff",{describe:"Whether to show diffs in stdout. off = no diffs; update = on for updates; on = updates, creates, deletes. Can be set by UNIFORM_CLI_DIFF_MODE environment variable.",default:(t=process.env.UNIFORM_CLI_DIFF_MODE)!=null?t:"off",type:"string",choices:["off","update","on"],alias:["d"]})}function G(e){let t=(0,P.extname)(e);return t===".yaml"||t===".yml"||t===".json"}function T(e,t,n){let r;if(n&&!t){let s=(0,P.extname)(n);s===".yaml"||s===".yml"?t="yaml":s===".json"&&(t="json")}else if(!t)throw new Error("Format must be specified when no filename is passed");switch(t){case"json":r=JSON.stringify(e,null,2);break;case"yaml":r=(0,_.dump)(e);break;default:throw new Error(`Unsupported format: ${t}`)}n?(0,h.writeFileSync)(n,r,"utf8"):console.log(r)}function E(e){let t=(0,N.readFileSync)(e,"utf8");return(0,_.load)(t,{filename:e,json:!0})}async function*Q(e,t){let n=t.pageSize||100,r=0,s=[];do{s=await e(r,n);for(let p of s)yield p;r+=n}while(s.length===n)}async function X({directory:e,format:t="yaml",selectIdentifier:n,selectDisplayName:r=n}){(0,A.existsSync)(e)||(0,A.mkdirSync)(e,{recursive:!0});let p=await(0,C.readdir)(e,"utf-8"),m=new Set(p.filter(i=>{let d=(0,v.extname)(i);return d===".json"||d===".yaml"||d===".yml"})),o=i=>(0,v.join)(e,`${i}.${t}`);async function*c(){for(let i of m){let d=(0,v.join)(e,i);try{let a=await E(d);yield{id:n(a),displayName:r(a),providerId:d,object:a}}catch(a){throw console.error(U.default.red(`Failed to read ${d}, data is likely invalid.
2
+ ${a==null?void 0:a.message}`)),a}}}return{objects:c(),deleteObject:async i=>{await(0,C.unlink)(i)},writeObject:async i=>{T(i.object,t,o(i.id))}}}var k=x(require("fs"));function Z(e,t){if(!t&&!k.default.existsSync(e))return{};let n=E(e);if(typeof n!="object")throw new Error(`Package ${e} does not appear valid.`);return n}function ee(e,t){T(t,void 0,e)}var I=require("diff"),R=x(require("lodash.isequalwith"));async function te({source:e,target:t,compareContents:n=(o,c)=>(0,R.default)(o.object,c.object,(i,d,a)=>a==="created"||a==="modified"?!0:void 0),mode:r,allowEmptySource:s=!1,whatIf:p=!1,log:m=()=>{}}){var d,a;let o=new Map;for await(let l of t.objects)o.set(l.id,l);let c=[],i=!1;for await(let l of e.objects){i=!0;let u=l.id,O=o.get(u);if(O){if(!n(l,O)&&(r==="createOrUpdate"||r==="mirror")){let y=async(f,j)=>{var S;p||await t.writeObject(f,j),m({action:"update",id:u,providerId:f.providerId,displayName:(S=f.displayName)!=null?S:f.providerId,whatIf:p,diff:(0,I.diffJson)(j.object,f.object)})};c.push(y(l,O))}o.delete(u)}else{let y=async(f,j)=>{var S;p||await t.writeObject(f),m({action:"create",id:j,providerId:j,displayName:(S=f.displayName)!=null?S:f.providerId,whatIf:p,diff:(0,I.diffLines)("",JSON.stringify(f.object,null,2))})};c.push(y(l,u))}}if(await Promise.all(c),r==="mirror"){if(!i&&!s)throw new Error("Source is empty and mode is mirror. This would cause deletion of everything in the target, and most likely indicates an error in source definition.");let l=[];o.forEach(async u=>{let O=async y=>{var f;p||await t.deleteObject(y.providerId),m({action:"delete",id:y.id,providerId:y.providerId,displayName:(f=y.displayName)!=null?f:y.providerId,whatIf:p,diff:(0,I.diffLines)(JSON.stringify(y.object,null,2),"")})};l.push(O(u))}),await Promise.all(l)}await Promise.all([(d=e.onSyncComplete)==null?void 0:d.call(e,!1),(a=t.onSyncComplete)==null?void 0:a.call(t,!0)])}var g=x(require("chalk"));function ne(e){let{diffMode:t="off",indent:n,prefix:r}=e!=null?e:{};return function({action:p,displayName:m,whatIf:o,diff:c}){let i="";switch(p){case"create":i=g.default.green("[A]");break;case"update":i=g.default.white("[U]");break;case"delete":i=g.default.yellow("[D]");break}let d="";(t==="on"||t==="update"&&p==="update")&&(d=`
3
+ `+c.map(a=>a.added?g.default.green(a.value):a.removed?g.default.red(a.value):a.value).join("")),console.log(`${n!=null?n:""}${o?g.default.gray("[WHATIF]"):""}${i}${r!=null?r:""} ${m}${d}`)}}module.exports=Y(oe);0&&(module.exports={createArraySyncEngineDataSource,createFileSyncEngineDataSource,createSyncEngineConsoleLogger,emitWithFormat,isPathAPackageFile,paginateAsync,readFileToObject,readUniformPackage,syncEngine,withApiOptions,withDiffOptions,withFormatOptions,withProjectOptions,writeUniformPackage});
@@ -0,0 +1,3 @@
1
+ import"../chunk-74EM6MWN.mjs";async function $({objects:t,selectIdentifier:e,selectDisplayName:n=e,onSyncComplete:i}){let c=t.reduce((o,a)=>{let r=e(a);if(o[r])throw new Error(`Identifier ${r} was not unique.`);return o[r]={id:r,object:a,providerId:r,displayName:n(a)},o},{});async function*p(){for(let o of Object.values(c))yield o}function m(){return Object.entries(c).sort((o,a)=>o[0].localeCompare(a[0])).map(o=>o[1].object)}return{objects:p(),deleteObject:async o=>{delete c[o]},writeObject:async o=>{let a=e(o.object);c[a]=o},extractCurrent:m,onSyncComplete:i?o=>i(o,m()):void 0}}import D from"chalk";import{existsSync as F,mkdirSync as h}from"fs";import{readdir as N,unlink as U}from"fs/promises";import{extname as k,join as w}from"path";import{dump as _,load as A}from"js-yaml";import{writeFileSync as C}from"fs";import{extname as I}from"path";import{readFileSync as P}from"fs";function V(t){var e,n;return t.option("apiKey",{describe:"Uniform API key. Defaults to CANVAS_CLI_API_KEY or UNIFORM_API_KEY env. Supports dotenv.",default:(n=(e=process.env.CANVAS_CLI_API_KEY)!=null?e:process.env.UPM_CLI_API_KEY)!=null?n:process.env.UNIFORM_API_KEY,demandOption:!0,type:"string"}).option("apiHost",{describe:"Uniform host. Defaults to UNIFORM_CLI_BASE_URL env or https://uniform.app. Supports dotenv.",default:process.env.UNIFORM_CLI_BASE_URL||"https://uniform.app",demandOption:!0,type:"string"})}function q(t){var e,n,i;return t.option("project",{describe:"Uniform project ID. Defaults to UNIFORM_CLI_PROJECT_ID or UNIFORM_PROJECT_ID env. Supports dotenv.",default:(i=(n=(e=process.env.UNIFORM_CLI_PROJECT_ID)!=null?e:process.env.CANVAS_CLI_PROJECT_ID)!=null?n:process.env.UPM_CLI_PROJECT_ID)!=null?i:process.env.UNIFORM_PROJECT_ID,demandOption:!0,type:"string",alias:["p"]})}function z(t){return t.option("format",{alias:["f"],describe:"Output format",default:"yaml",choices:["yaml","json"],type:"string"}).option("filename",{alias:["o"],describe:"Output filename. If not specified, write to stdout.",type:"string"})}function B(t){var e;return t.option("diff",{describe:"Whether to show diffs in stdout. off = no diffs; update = on for updates; on = updates, creates, deletes. Can be set by UNIFORM_CLI_DIFF_MODE environment variable.",default:(e=process.env.UNIFORM_CLI_DIFF_MODE)!=null?e:"off",type:"string",choices:["off","update","on"],alias:["d"]})}function G(t){let e=I(t);return e===".yaml"||e===".yml"||e===".json"}function E(t,e,n){let i;if(n&&!e){let c=I(n);c===".yaml"||c===".yml"?e="yaml":c===".json"&&(e="json")}else if(!e)throw new Error("Format must be specified when no filename is passed");switch(e){case"json":i=JSON.stringify(t,null,2);break;case"yaml":i=_(t);break;default:throw new Error(`Unsupported format: ${e}`)}n?C(n,i,"utf8"):console.log(i)}function v(t){let e=P(t,"utf8");return A(e,{filename:t,json:!0})}async function*Q(t,e){let n=e.pageSize||100,i=0,c=[];do{c=await t(i,n);for(let p of c)yield p;i+=n}while(c.length===n)}async function re({directory:t,format:e="yaml",selectIdentifier:n,selectDisplayName:i=n}){F(t)||h(t,{recursive:!0});let p=await N(t,"utf-8"),m=new Set(p.filter(r=>{let d=k(r);return d===".json"||d===".yaml"||d===".yml"})),o=r=>w(t,`${r}.${e}`);async function*a(){for(let r of m){let d=w(t,r);try{let s=await v(d);yield{id:n(s),displayName:i(s),providerId:d,object:s}}catch(s){throw console.error(D.red(`Failed to read ${d}, data is likely invalid.
2
+ ${s==null?void 0:s.message}`)),s}}}return{objects:a(),deleteObject:async r=>{await U(r)},writeObject:async r=>{E(r.object,e,o(r.id))}}}import R from"fs";function ce(t,e){if(!e&&!R.existsSync(t))return{};let n=v(t);if(typeof n!="object")throw new Error(`Package ${t} does not appear valid.`);return n}function pe(t,e){E(e,void 0,t)}import{diffJson as M,diffLines as x}from"diff";import L from"lodash.isequalwith";async function ye({source:t,target:e,compareContents:n=(o,a)=>L(o.object,a.object,(r,d,s)=>s==="created"||s==="modified"?!0:void 0),mode:i,allowEmptySource:c=!1,whatIf:p=!1,log:m=()=>{}}){var d,s;let o=new Map;for await(let l of e.objects)o.set(l.id,l);let a=[],r=!1;for await(let l of t.objects){r=!0;let g=l.id,j=o.get(g);if(j){if(!n(l,j)&&(i==="createOrUpdate"||i==="mirror")){let y=async(f,S)=>{var T;p||await e.writeObject(f,S),m({action:"update",id:g,providerId:f.providerId,displayName:(T=f.displayName)!=null?T:f.providerId,whatIf:p,diff:M(S.object,f.object)})};a.push(y(l,j))}o.delete(g)}else{let y=async(f,S)=>{var T;p||await e.writeObject(f),m({action:"create",id:S,providerId:S,displayName:(T=f.displayName)!=null?T:f.providerId,whatIf:p,diff:x("",JSON.stringify(f.object,null,2))})};a.push(y(l,g))}}if(await Promise.all(a),i==="mirror"){if(!r&&!c)throw new Error("Source is empty and mode is mirror. This would cause deletion of everything in the target, and most likely indicates an error in source definition.");let l=[];o.forEach(async g=>{let j=async y=>{var f;p||await e.deleteObject(y.providerId),m({action:"delete",id:y.id,providerId:y.providerId,displayName:(f=y.displayName)!=null?f:y.providerId,whatIf:p,diff:x(JSON.stringify(y.object,null,2),"")})};l.push(j(g))}),await Promise.all(l)}await Promise.all([(d=t.onSyncComplete)==null?void 0:d.call(t,!1),(s=e.onSyncComplete)==null?void 0:s.call(e,!0)])}import O from"chalk";function be(t){let{diffMode:e="off",indent:n,prefix:i}=t!=null?t:{};return function({action:p,displayName:m,whatIf:o,diff:a}){let r="";switch(p){case"create":r=O.green("[A]");break;case"update":r=O.white("[U]");break;case"delete":r=O.yellow("[D]");break}let d="";(e==="on"||e==="update"&&p==="update")&&(d=`
3
+ `+a.map(s=>s.added?O.green(s.value):s.removed?O.red(s.value):s.value).join("")),console.log(`${n!=null?n:""}${o?O.gray("[WHATIF]"):""}${r}${i!=null?i:""} ${m}${d}`)}}export{$ as createArraySyncEngineDataSource,re as createFileSyncEngineDataSource,be as createSyncEngineConsoleLogger,E as emitWithFormat,G as isPathAPackageFile,Q as paginateAsync,v as readFileToObject,ce as readUniformPackage,ye as syncEngine,V as withApiOptions,B as withDiffOptions,z as withFormatOptions,q as withProjectOptions,pe as writeUniformPackage};
package/package.json CHANGED
@@ -1,13 +1,30 @@
1
1
  {
2
2
  "name": "@uniformdev/cli",
3
- "version": "12.2.1-alpha.141+f7de3b59",
3
+ "version": "12.2.1-alpha.171+b2055e2a",
4
4
  "description": "Uniform command line interface tool",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./cli.js",
7
+ "exports": {
8
+ ".": "./cli.js",
9
+ "./sync": {
10
+ "import": "./dist/sync/index.mjs",
11
+ "require": "./dist/sync/index.js"
12
+ }
13
+ },
7
14
  "types": "./dist/index.d.ts",
15
+ "typesVersions": {
16
+ "*": {
17
+ ".": [
18
+ "./dist/index.d.ts"
19
+ ],
20
+ "sync": [
21
+ "./dist/sync/index.d.ts"
22
+ ]
23
+ }
24
+ },
8
25
  "sideEffects": false,
9
26
  "scripts": {
10
- "uniform": "uniform",
27
+ "uniform": "node ./cli.js",
11
28
  "build": "tsup",
12
29
  "dev": "tsup --watch",
13
30
  "clean": "rimraf dist",
@@ -19,23 +36,29 @@
19
36
  },
20
37
  "dependencies": {
21
38
  "chalk": "^4.1.2",
22
- "dotenv": "^14.2.0",
39
+ "diff": "^5.0.0",
40
+ "dotenv": "^16.0.0",
41
+ "js-yaml": "^4.1.0",
42
+ "lodash.isequalwith": "^4.4.0",
23
43
  "node-fetch": "^2.6.7",
24
44
  "yargs": "^17.3.1"
25
45
  },
26
46
  "devDependencies": {
47
+ "@types/diff": "^5.0.2",
27
48
  "@types/jest": "27.4.0",
28
- "@types/node": "16.11.21",
49
+ "@types/js-yaml": "^4.0.5",
50
+ "@types/lodash.isequalwith": "^4.4.6",
51
+ "@types/node": "16.11.24",
29
52
  "@types/node-fetch": "2.5.12",
30
53
  "@types/yargs": "17.0.8",
31
- "eslint": "8.7.0",
54
+ "eslint": "8.8.0",
32
55
  "eslint-plugin-react": "7.28.0",
33
56
  "eslint-plugin-react-hooks": "4.3.0",
34
- "jest": "27.4.7",
57
+ "jest": "27.5.1",
35
58
  "npm-run-all": "4.1.5",
36
59
  "rimraf": "3.0.2",
37
60
  "ts-jest": "27.1.3",
38
- "tsup": "5.11.11"
61
+ "tsup": "5.11.13"
39
62
  },
40
63
  "bin": {
41
64
  "uniform": "./cli.js"
@@ -46,5 +69,5 @@
46
69
  "publishConfig": {
47
70
  "access": "public"
48
71
  },
49
- "gitHead": "f7de3b595650c7b8b09c8cde7e840682c1499e0e"
72
+ "gitHead": "b2055e2a1db9288562eb59768708f2f385d61c10"
50
73
  }