croct 0.12.13 → 0.12.14

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.
Files changed (2) hide show
  1. package/index.js +1 -1
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1844,4 +1844,4 @@ ${this.getPreferences(e.protocol).join(`
1844
1844
  `);return new d(`${e.message}
1845
1845
 
1846
1846
  \u25B6\uFE0F **Trace**
1847
- ${t}`,e.help)}break;case e instanceof ve:return new d(e.message,{...e.help,suggestions:["Run `init` to create a new configuration."]})}return e}static getSourceLocation(e){return e.url.protocol==="file:"?`${e.url}:${e.start.line}:${e.start.column}`:e.url.hostname==="github.com"?`${e.url}#L${e.start.line}-L${e.end.line}`:`${e.url}#${e.start.line}:${e.start.column}-${e.end.line}:${e.end.column}`}};var rs={version:"0.12.13"};function Cc(a){let e=new Command().name("croct").description("Manage your Croct projects").enablePositionalOptions().option("--cwd <path>","The working directory.",S=>{try{return realpathSync(S)}catch{throw new InvalidOptionArgumentError("The path does not exist.")}}).addOption(new Option("--api-key <key>","The API key to use for authentication.").env("CROCT_API_KEY").argParser(S=>{try{return ApiKey.parse(S)}catch{throw new InvalidOptionArgumentError("The API key is malformed.")}}).conflicts("token")).addOption(new Option("--token <token>","The JWT-formatted token to use for authentication.").env("CROCT_TOKEN").argParser(S=>{let P;try{P=Token.parse(S);}catch{throw new InvalidOptionArgumentError("The token is malformed.")}if(!P.isValidNow())throw new InvalidOptionArgumentError("The token is expired.");return P})).option("--registry <url>","The template registry.",S=>{if(!URL.canParse(S))throw new InvalidOptionArgumentError("Malformed URL.");return S}).option("--no-interaction","Run the CLI in non-interactive mode.").option("--config <path>","Path to the configuration file.").addOption(new Option("--stateless","Run the CLI without saving any state locally.").env("CROCT_STATELESS").default(false)).addOption(new Option("--dnd","Run the CLI with minimal interaction and interruption.").env("CROCT_DND").default(false)).addOption(new Option("-q, --quiet","Disable output messages.").default(false).implies({interaction:false})).option("--debug","Enable debug mode.").version(rs.version,"-v, --version","Display the version number.").helpOption("-h, --help","Display help for a command.").helpCommand("help [command]","Display help for a command.");e.command("open <url>").description("Open a deep link.").action(async S=>{await a.cli?.open({url:S});});let t=e.command("login").description("Authenticate your user."),n=new Option("-u, --username <username>","The email."),i=new Option("-p, --password <password>","The password.");t.command("credentials",{isDefault:true}).description("Authenticate using credentials.").addOption(a.interactive?n:n.makeOptionMandatory()).addOption(a.interactive?i:i.makeOptionMandatory()).action(async S=>{await a.cli?.login({method:"credentials",username:S.username,password:S.password});}),e.command("logout").description("Logout the current user.").action(async()=>{await a.cli?.logout();}),e.command("admin").argument("[page...]","The name of the page or path to open.").description("Log in and open the admin panel.").action(async S=>{await a.cli?.admin({page:S!==void 0?S.join(" "):a.interactive?void 0:"/"});});let o=new Option("--wor <workspace-slug>","The workspace slug."),r=new Option("--org <organization-slug>","The organization slug."),s=new Option("--dev-app <application-slug>","The development application slug."),p=new Option("--prod-app <application-slug>","The production application slug.");e.command("init").description("Configure the project.").option("-o, --override","Override any existing configuration.").addOption(new Option("-n, --new <resource>","The resources to create.").choices(["organization","org","workspace","wor","application","app"])).addOption(new Option("-s, --sdk <platform>","The SDK to use.").choices(["javascript","react","next"])).addOption(new Option("--skip-api-key-setup","Opt-out of API key setup.").default(false).env("CROCT_SKIP_API_KEY_SETUP")).addOption(a.interactive?r:r.makeOptionMandatory()).addOption(a.interactive?o:o.makeOptionMandatory()).addOption(a.interactive?s:s.makeOptionMandatory()).addOption(p).action(async S=>{await a.cli?.init({override:S.override,new:(()=>{switch(S.new){case "organization":case "org":return "organization";case "workspace":case "wor":return "workspace";case "application":case "app":return "application";default:return}})(),sdk:S.sdk,organization:S.org,workspace:S.wor,devApplication:S.devApp,prodApplication:S.prodApp,skipApiKeySetup:S.skipApiKeySetup});}),e.command("install").description("Install content and types.").action(async()=>{await a.cli?.install({});}),e.command("update").description("Update content and types.").action(async()=>{await a.cli?.install({clean:true});}),e.command("upgrade").description("Upgrade components and slots to the latest version.").option("-s, --slots <slots...>","The slots to upgrade.").option("-c, --components <components...>","The components to upgrade.").action(async S=>{await a.cli?.upgrade({slots:S.slots??(S.components!==void 0?[]:void 0),components:S.components??(S.slots!==void 0?[]:void 0)});});let c=e.command("add").description("Add a resource to your project.");c.command("slot").description("Add a slot to your project.").argument(a.interactive?"[slots...]":"<slots...>").option("-e, --example","Generate an implementation example.").action(async(S,P)=>{await a.cli?.addSlot({slots:S,example:P.example});}),c.command("component").description("Add a component to your project.").argument(a.interactive?"[components...]":"<components...>").action(async S=>{await a.cli?.addComponent({components:S});});let l=e.command("remove").description("Remove a resource from your project.");l.command("slot").description("Remove a slot from your project.").argument(a.interactive?"[slots...]":"<slots...>").action(async S=>{await a.cli?.removeSlot({slots:S});}),l.command("component").description("Remove a component from your project.").argument(a.interactive?"[components...]":"<components...>").action(async S=>{await a.cli?.removeComponent({components:S});});let u=e.command("create").description("Create a resource in your project.");u.command("template").description("Create a template from your project.").addArgument(new Argument("<path>","The path to the file.").argOptional()).option("-e, --empty","Create an empty template.").action(async(S,P)=>{await a.cli?.createTemplate({file:S,empty:P.empty});});let g=new Option("--permissions <permissions...>","The permissions of the API key.").argParser(S=>S.split(",").map(P=>{try{return se.fromValue(P)}catch{throw new InvalidOptionArgumentError(`Unknown permission "${P}".`)}})),y=new Option("--env <environment>","The environment of the API key.").choices(["prod","dev"]).argParser(S=>S==="prod"?"PRODUCTION":"DEVELOPMENT");u.command("api-key").description("Create an API key.").option("--name <name>","The name of the API key.").addOption(a.interactive?g:g.makeOptionMandatory()).addOption(a.interactive?y:y.makeOptionMandatory()).option("-c, --copy","Copy the API key to the clipboard.").action(async S=>{await a.cli?.createApiKey({name:S.name,permissions:S.permissions,environment:S.env,copy:S.copy});});let v={},A=e.command("use").description("Use a template.").argument("template","The path to the template.").passThroughOptions(a.cli===void 0).allowUnknownOption(a.cli===void 0||a.template===null).action(async(S,P)=>{await a.cli?.useTemplate({template:S,options:Object.fromEntries(Object.entries(P).map(([H,ue])=>[v[H],ue]))});});for(let[S,P]of Object.entries(a.template??{})){let H=`--${S}${P.type!=="boolean"?" <value>":""}`,ue=new Option(H,P.description).makeOptionMandatory(P.required===true);switch(P.type){case "string":P.choices!==void 0&&P.choices.length>0&&ue.choices(P.choices);break;case "number":ue.argParser(V=>{let re=Number.parseFloat(V);if(Number.isNaN(re))throw new InvalidOptionArgumentError("The value must be a number.");return re});break;case "array":ue.argParser(V=>{let re;try{re=JSON.parse(V);}catch{}if(re===void 0||!Array.isArray(re))throw new InvalidOptionArgumentError("The value must be a JSON array.");return re});break;case "object":ue.argParser(V=>{let re;try{re=JSON.parse(V);}catch{throw new InvalidOptionArgumentError("The JSON is malformed.")}if(typeof re!="object"||re===null)throw new InvalidOptionArgumentError("The value must be a JSON object.")});break}v[ue.attributeName()]=S,A.addOption(ue);}return e.command("enable").description("Enable a feature.").command("deep-link").description("Enable deep link support.").action(async()=>{await a.cli?.deepLink({operation:"enable"});}),e.command("disable").description("Disable a feature.").command("deep-link").description("Disable deep link support.").action(async()=>{await a.cli?.deepLink({operation:"disable"});}),e}function Id(a){let e=["use","help use"];for(let t of e){let n=t.split(" ").length;if(a.length>n&&a.slice(0,n).join(" ")===t&&(a[n]??"")!=="")return a[n]}return null}function vd(a){return a.length>=2&&["enable","disable"].includes(a[0])&&a[1]==="deep-link"}async function as(a=process.argv,e=true){let t=Cc({interactive:true}).parse(a),n=t.opts(),i=Sa.fromDefaults({program:p=>as(t.args.slice(0,2).concat(p)),version:rs.version,quiet:n.quiet,debug:n.debug,interactive:n.interaction?void 0:false,stateless:n.stateless,apiKey:n.apiKey,token:n.token,dnd:n.dnd,templateRegistryUrl:n.registry===void 0?void 0:new URL(n.registry),configurationFile:n.config}),o=Id(t.args),r=o!==null?await i.getTemplateOptions(o).catch(()=>null):void 0,s=Cc({cli:i,interactive:n.interaction,template:r});e&&await i.welcome({skipDeepLinkCheck:vd(t.args)}),await s.parseAsync(a);}as();
1847
+ ${t}`,e.help)}break;case e instanceof ve:return new d(e.message,{...e.help,suggestions:["Run `init` to create a new configuration."]})}return e}static getSourceLocation(e){return e.url.protocol==="file:"?`${e.url}:${e.start.line}:${e.start.column}`:e.url.hostname==="github.com"?`${e.url}#L${e.start.line}-L${e.end.line}`:`${e.url}#${e.start.line}:${e.start.column}-${e.end.line}:${e.end.column}`}};var rs={version:"0.12.14"};function Cc(a){let e=new Command().name("croct").description("Manage your Croct projects").enablePositionalOptions().option("--cwd <path>","The working directory.",S=>{try{return realpathSync(S)}catch{throw new InvalidOptionArgumentError("The path does not exist.")}}).addOption(new Option("--api-key <key>","The API key to use for authentication.").env("CROCT_API_KEY").argParser(S=>{try{return ApiKey.parse(S)}catch{throw new InvalidOptionArgumentError("The API key is malformed.")}}).conflicts("token")).addOption(new Option("--token <token>","The JWT-formatted token to use for authentication.").env("CROCT_TOKEN").argParser(S=>{let P;try{P=Token.parse(S);}catch{throw new InvalidOptionArgumentError("The token is malformed.")}if(!P.isValidNow())throw new InvalidOptionArgumentError("The token is expired.");return P})).option("--registry <url>","The template registry.",S=>{if(!URL.canParse(S))throw new InvalidOptionArgumentError("Malformed URL.");return S}).option("--no-interaction","Run the CLI in non-interactive mode.").option("--config <path>","Path to the configuration file.").addOption(new Option("--stateless","Run the CLI without saving any state locally.").env("CROCT_STATELESS").default(false)).addOption(new Option("--dnd","Run the CLI with minimal interaction and interruption.").env("CROCT_DND").default(false)).addOption(new Option("-q, --quiet","Disable output messages.").default(false).implies({interaction:false})).option("--debug","Enable debug mode.").version(rs.version,"-v, --version","Display the version number.").helpOption("-h, --help","Display help for a command.").helpCommand("help [command]","Display help for a command.");e.command("open <url>").description("Open a deep link.").action(async S=>{await a.cli?.open({url:S});});let t=e.command("login").description("Authenticate your user."),n=new Option("-u, --username <username>","The email."),i=new Option("-p, --password <password>","The password.");t.command("credentials",{isDefault:true}).description("Authenticate using credentials.").addOption(a.interactive?n:n.makeOptionMandatory()).addOption(a.interactive?i:i.makeOptionMandatory()).action(async S=>{await a.cli?.login({method:"credentials",username:S.username,password:S.password});}),e.command("logout").description("Logout the current user.").action(async()=>{await a.cli?.logout();}),e.command("admin").argument("[page...]","The name of the page or path to open.").description("Log in and open the admin panel.").action(async S=>{await a.cli?.admin({page:S!==void 0?S.join(" "):a.interactive?void 0:"/"});});let o=new Option("--wor <workspace-slug>","The workspace slug."),r=new Option("--org <organization-slug>","The organization slug."),s=new Option("--dev-app <application-slug>","The development application slug."),p=new Option("--prod-app <application-slug>","The production application slug.");e.command("init").description("Configure the project.").option("-o, --override","Override any existing configuration.").addOption(new Option("-n, --new <resource>","The resources to create.").choices(["organization","org","workspace","wor","application","app"])).addOption(new Option("-s, --sdk <platform>","The SDK to use.").choices(["javascript","react","next"])).addOption(new Option("--skip-api-key-setup","Opt-out of API key setup.").default(false).env("CROCT_SKIP_API_KEY_SETUP")).addOption(a.interactive?r:r.makeOptionMandatory()).addOption(a.interactive?o:o.makeOptionMandatory()).addOption(a.interactive?s:s.makeOptionMandatory()).addOption(p).action(async S=>{await a.cli?.init({override:S.override,new:(()=>{switch(S.new){case "organization":case "org":return "organization";case "workspace":case "wor":return "workspace";case "application":case "app":return "application";default:return}})(),sdk:S.sdk,organization:S.org,workspace:S.wor,devApplication:S.devApp,prodApplication:S.prodApp,skipApiKeySetup:S.skipApiKeySetup});}),e.command("install").description("Install content and types.").action(async()=>{await a.cli?.install({});}),e.command("update").description("Update content and types.").action(async()=>{await a.cli?.install({clean:true});}),e.command("upgrade").description("Upgrade components and slots to the latest version.").option("-s, --slots <slots...>","The slots to upgrade.").option("-c, --components <components...>","The components to upgrade.").action(async S=>{await a.cli?.upgrade({slots:S.slots??(S.components!==void 0?[]:void 0),components:S.components??(S.slots!==void 0?[]:void 0)});});let c=e.command("add").description("Add a resource to your project.");c.command("slot").description("Add a slot to your project.").argument(a.interactive?"[slots...]":"<slots...>").option("-e, --example","Generate an implementation example.").action(async(S,P)=>{await a.cli?.addSlot({slots:S,example:P.example});}),c.command("component").description("Add a component to your project.").argument(a.interactive?"[components...]":"<components...>").action(async S=>{await a.cli?.addComponent({components:S});});let l=e.command("remove").description("Remove a resource from your project.");l.command("slot").description("Remove a slot from your project.").argument(a.interactive?"[slots...]":"<slots...>").action(async S=>{await a.cli?.removeSlot({slots:S});}),l.command("component").description("Remove a component from your project.").argument(a.interactive?"[components...]":"<components...>").action(async S=>{await a.cli?.removeComponent({components:S});});let u=e.command("create").description("Create a resource in your project.");u.command("template").description("Create a template from your project.").addArgument(new Argument("<path>","The path to the file.").argOptional()).option("-e, --empty","Create an empty template.").action(async(S,P)=>{await a.cli?.createTemplate({file:S,empty:P.empty});});let g=new Option("--permissions <permissions...>","The permissions of the API key.").argParser(S=>S.split(",").map(P=>{try{return se.fromValue(P)}catch{throw new InvalidOptionArgumentError(`Unknown permission "${P}".`)}})),y=new Option("--env <environment>","The environment of the API key.").choices(["prod","dev"]).argParser(S=>S==="prod"?"PRODUCTION":"DEVELOPMENT");u.command("api-key").description("Create an API key.").option("--name <name>","The name of the API key.").addOption(a.interactive?g:g.makeOptionMandatory()).addOption(a.interactive?y:y.makeOptionMandatory()).option("-c, --copy","Copy the API key to the clipboard.").action(async S=>{await a.cli?.createApiKey({name:S.name,permissions:S.permissions,environment:S.env,copy:S.copy});});let v={},A=e.command("use").description("Use a template.").argument("template","The path to the template.").passThroughOptions(a.cli===void 0).allowUnknownOption(a.cli===void 0||a.template===null).action(async(S,P)=>{await a.cli?.useTemplate({template:S,options:Object.fromEntries(Object.entries(P).map(([H,ue])=>[v[H],ue]))});});for(let[S,P]of Object.entries(a.template??{})){let H=`--${S}${P.type!=="boolean"?" <value>":""}`,ue=new Option(H,P.description).makeOptionMandatory(P.required===true);switch(P.type){case "string":P.choices!==void 0&&P.choices.length>0&&ue.choices(P.choices);break;case "number":ue.argParser(V=>{let re=Number.parseFloat(V);if(Number.isNaN(re))throw new InvalidOptionArgumentError("The value must be a number.");return re});break;case "array":ue.argParser(V=>{let re;try{re=JSON.parse(V);}catch{}if(re===void 0||!Array.isArray(re))throw new InvalidOptionArgumentError("The value must be a JSON array.");return re});break;case "object":ue.argParser(V=>{let re;try{re=JSON.parse(V);}catch{throw new InvalidOptionArgumentError("The JSON is malformed.")}if(typeof re!="object"||re===null)throw new InvalidOptionArgumentError("The value must be a JSON object.")});break}v[ue.attributeName()]=S,A.addOption(ue);}return e.command("enable").description("Enable a feature.").command("deep-link").description("Enable deep link support.").action(async()=>{await a.cli?.deepLink({operation:"enable"});}),e.command("disable").description("Disable a feature.").command("deep-link").description("Disable deep link support.").action(async()=>{await a.cli?.deepLink({operation:"disable"});}),e}function Id(a){let e=["use","help use"];for(let t of e){let n=t.split(" ").length;if(a.length>n&&a.slice(0,n).join(" ")===t&&(a[n]??"")!=="")return a[n]}return null}function vd(a){return a.length>=2&&["enable","disable"].includes(a[0])&&a[1]==="deep-link"}async function as(a=process.argv,e=true){let t=Cc({interactive:true}).parse(a),n=t.opts(),i=Sa.fromDefaults({program:p=>as(t.args.slice(0,2).concat(p)),version:rs.version,quiet:n.quiet,debug:n.debug,interactive:n.interaction?void 0:false,stateless:n.stateless,apiKey:n.apiKey,token:n.token,dnd:n.dnd,templateRegistryUrl:n.registry===void 0?void 0:new URL(n.registry),configurationFile:n.config}),o=Id(t.args),r=o!==null?await i.getTemplateOptions(o).catch(()=>null):void 0,s=Cc({cli:i,interactive:n.interaction,template:r});e&&await i.welcome({skipDeepLinkCheck:vd(t.args)}),await s.parseAsync(a);}as();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "croct",
3
- "version": "0.12.13",
3
+ "version": "0.12.14",
4
4
  "description": "A command-line interface (CLI) for managing projects using Croct.",
5
5
  "author": {
6
6
  "name": "Croct",
@@ -47,7 +47,7 @@
47
47
  "@croct/json5-parser": "^0.2.1",
48
48
  "@croct/logging": "^0.2.3",
49
49
  "@croct/md-lite": "^0.3.1",
50
- "@croct/sdk": "^0.20.0",
50
+ "@croct/sdk": "^0.21.0",
51
51
  "@croct/time": "^0.10.2",
52
52
  "@jsep-plugin/object": "^1.2.2",
53
53
  "@jsep-plugin/regex": "^1.0.4",