create-caspian-app 0.2.0-beta.24 → 0.2.0-beta.25
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/caspian.js +1 -1
- package/package.json +1 -1
package/dist/caspian.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import chalk from"chalk";import{spawn}from"child_process";import fs from"fs";import path from"path";import prompts from"prompts";const args=process.argv.slice(2),isNonInteractive=args.includes("-y"),
|
|
2
|
+
import chalk from"chalk";import{spawn}from"child_process";import fs from"fs";import path from"path";import prompts from"prompts";const args=process.argv.slice(2),isNonInteractive=args.includes("-y"),resolveNpxInvocation=e=>"win32"===process.platform?{command:process.env.ComSpec||process.env.COMSPEC||"cmd.exe",args:["/d","/s","/c","npx.cmd",...e]}:{command:"npx",args:e},readJsonFile=e=>{const o=fs.readFileSync(e,"utf8");return JSON.parse(o)},executeCommand=(e,o=[],n={})=>new Promise((a,r)=>{const t=spawn(e,o,{stdio:"inherit",shell:!1,...n});t.on("error",e=>{console.error(`Execution error: ${e.message}`),r(e)}),t.on("close",e=>{0===e?a():r(new Error(`Process exited with code ${e}`))})});async function getAnswer(e){const o=[{type:"toggle",name:"shouldProceed",message:`This command will update the ${chalk.blue("create-caspian-app")} package and overwrite all default files. ${chalk.blue("Do you want to proceed")}?`,initial:!1,active:"Yes",inactive:"No"}];e||o.push({type:e=>e?"text":null,name:"versionTag",message:`Enter version tag (e.g., ${chalk.cyan("latest")}, ${chalk.cyan("v4-alpha")}, ${chalk.cyan("1.2.3")}), or press Enter for ${chalk.green("latest")}:`,initial:"latest",validate:e=>!(!e||""===e.trim())||"Version tag cannot be empty"});const n=await prompts(o,{onCancel:()=>{console.warn(chalk.red("Operation cancelled by the user.")),process.exit(0)}});if(0===Object.keys(n).length)return null;let a="latest";return e?a=e:n.versionTag&&(a=n.versionTag),{shouldProceed:n.shouldProceed,versionTag:a}}const commandsToExecute={update:"npx casp update project"},normalizeVersionTag=e=>{const o=e.startsWith("@")?e.slice(1):e;if(!o.trim())throw new Error("Version tag cannot be empty.");return o},addVersionTag=(e,o)=>{if(e&&e!==o)throw new Error(`Conflicting version tags provided: ${e} and ${o}`);return o},parseCliArgs=e=>{const o=[];let n;for(let a=0;a<e.length;a+=1){const r=e[a];if("-y"!==r){if("--tag"===r||"--version"===r){const o=e[a+1];if(!o||o.startsWith("-"))throw new Error(`Missing value for ${r}.`);n=addVersionTag(n,normalizeVersionTag(o)),a+=1;continue}r.startsWith("--tag=")?n=addVersionTag(n,normalizeVersionTag(r.slice(6))):r.startsWith("--version=")?n=addVersionTag(n,normalizeVersionTag(r.slice(10))):o.push(r)}}if("update"===o[0]&&"project"===o[1]){const e=o.slice(2);if(e.length>1)throw new Error(`Too many arguments for update project: ${e.join(" ")}`);return 1===e.length&&(n=addVersionTag(n,normalizeVersionTag(e[0]))),{formattedCommand:commandsToExecute.update,versionTag:n}}return{formattedCommand:`npx casp ${o.join(" ")}`,versionTag:n}},main=async()=>{if(0===args.length)return console.log("No command provided."),console.log("\nUsage:"),console.log(` ${chalk.cyan("npx casp update project")} - Update to latest version`),console.log(` ${chalk.cyan("npx casp update project beta")} - Update to specific tag`),console.log(` ${chalk.cyan("npx casp update project --tag beta")} - Update to a specific tag via named option`),console.log(` ${chalk.cyan("npx casp update project 1.2.3")} - Update to specific version`),void console.log(` ${chalk.cyan("npx casp update project -y")} - Update without prompts (non-interactive)`);let e;try{e=parseCliArgs(args)}catch(e){return void(e instanceof Error?console.error(chalk.red(e.message)):console.error(chalk.red("Failed to parse command arguments.")))}const{formattedCommand:o,versionTag:n}=e;if(!Object.values(commandsToExecute).includes(o))return console.log("Command not recognized or not allowed."),console.log("\nAvailable commands:"),console.log(` ${chalk.cyan("update project")} - Update project files`),console.log(` ${chalk.cyan("update project beta")} - Update to a specific tag`),console.log(` ${chalk.cyan("update project --tag beta")} - PowerShell-safe tagged update`),void console.log(` ${chalk.cyan("-y")} - Non-interactive mode (skip prompts)`);if(o===commandsToExecute.update)try{let e;if(isNonInteractive)e={shouldProceed:!0,versionTag:n||"latest"},console.log(chalk.blue("Running in non-interactive mode..."));else if(e=await getAnswer(n),!e?.shouldProceed)return void console.log(chalk.red("Operation cancelled by the user."));const o=process.cwd(),a=path.join(o,"caspian.config.json");if(!fs.existsSync(a))return void console.error(chalk.red("The configuration file 'caspian.config.json' was not found in the current directory."));const r=readJsonFile(a),t=e.versionTag||"latest",s=`create-caspian-app@${t}`;console.log(chalk.blue(`\nUpdating to: ${chalk.green(s)}\n`));const c=[r.projectName];r.backendOnly&&c.push("--backend-only"),r.tailwindcss&&c.push("--tailwindcss"),r.prisma&&c.push("--prisma"),r.mcp&&c.push("--mcp"),r.typescript&&c.push("--typescript"),isNonInteractive&&c.push("-y"),console.log("Executing command...\n");const i=resolveNpxInvocation([s,...c]);await executeCommand(i.command,i.args),console.log(chalk.green(`\n✓ Project updated successfully to version ${t}!`)),console.log(chalk.blue("Updated configuration saved to caspian.config.json"))}catch(e){e instanceof Error?e.message.includes("no such file or directory")?console.error(chalk.red("The configuration file 'caspian.config.json' was not found in the current directory.")):console.error(chalk.red(`Error during update: ${e.message}`)):console.error("Error in script execution:",e)}};main().catch(e=>{console.error("Unhandled error in main function:",e)});
|