UNPKG

create-toolpad-app

Version:

Create Toolpad apps with one command

1,382 lines (1,351 loc) 363 kB
#!/usr/bin/env node "use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __typeError = (msg) => { throw TypeError(msg); }; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg); var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj)); var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value); var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value); var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method); // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js var require_windows = __commonJS({ "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports2, module2) { "use strict"; module2.exports = isexe; isexe.sync = sync; var fs5 = require("fs"); function checkPathExt(path11, options) { var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT; if (!pathext) { return true; } pathext = pathext.split(";"); if (pathext.indexOf("") !== -1) { return true; } for (var i2 = 0; i2 < pathext.length; i2++) { var p = pathext[i2].toLowerCase(); if (p && path11.substr(-p.length).toLowerCase() === p) { return true; } } return false; } function checkStat(stat, path11, options) { if (!stat.isSymbolicLink() && !stat.isFile()) { return false; } return checkPathExt(path11, options); } function isexe(path11, options, cb) { fs5.stat(path11, function(er, stat) { cb(er, er ? false : checkStat(stat, path11, options)); }); } function sync(path11, options) { return checkStat(fs5.statSync(path11), path11, options); } } }); // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js var require_mode = __commonJS({ "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports2, module2) { "use strict"; module2.exports = isexe; isexe.sync = sync; var fs5 = require("fs"); function isexe(path11, options, cb) { fs5.stat(path11, function(er, stat) { cb(er, er ? false : checkStat(stat, options)); }); } function sync(path11, options) { return checkStat(fs5.statSync(path11), options); } function checkStat(stat, options) { return stat.isFile() && checkMode(stat, options); } function checkMode(stat, options) { var mod = stat.mode; var uid = stat.uid; var gid = stat.gid; var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid(); var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid(); var u2 = parseInt("100", 8); var g = parseInt("010", 8); var o2 = parseInt("001", 8); var ug = u2 | g; var ret = mod & o2 || mod & g && gid === myGid || mod & u2 && uid === myUid || mod & ug && myUid === 0; return ret; } } }); // ../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js var require_isexe = __commonJS({ "../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports2, module2) { "use strict"; var fs5 = require("fs"); var core; if (process.platform === "win32" || global.TESTING_WINDOWS) { core = require_windows(); } else { core = require_mode(); } module2.exports = isexe; isexe.sync = sync; function isexe(path11, options, cb) { if (typeof options === "function") { cb = options; options = {}; } if (!cb) { if (typeof Promise !== "function") { throw new TypeError("callback not provided"); } return new Promise(function(resolve, reject) { isexe(path11, options || {}, function(er, is) { if (er) { reject(er); } else { resolve(is); } }); }); } core(path11, options || {}, function(er, is) { if (er) { if (er.code === "EACCES" || options && options.ignoreErrors) { er = null; is = false; } } cb(er, is); }); } function sync(path11, options) { try { return core.sync(path11, options || {}); } catch (er) { if (options && options.ignoreErrors || er.code === "EACCES") { return false; } else { throw er; } } } } }); // ../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js var require_which = __commonJS({ "../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports2, module2) { "use strict"; var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys"; var path11 = require("path"); var COLON = isWindows ? ";" : ":"; var isexe = require_isexe(); var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" }); var getPathInfo = (cmd, opt) => { const colon = opt.colon || COLON; const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [ // windows always checks the cwd first ...isWindows ? [process.cwd()] : [], ...(opt.path || process.env.PATH || /* istanbul ignore next: very unusual */ "").split(colon) ]; const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : ""; const pathExt = isWindows ? pathExtExe.split(colon) : [""]; if (isWindows) { if (cmd.indexOf(".") !== -1 && pathExt[0] !== "") pathExt.unshift(""); } return { pathEnv, pathExt, pathExtExe }; }; var which = (cmd, opt, cb) => { if (typeof opt === "function") { cb = opt; opt = {}; } if (!opt) opt = {}; const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt); const found = []; const step = (i2) => new Promise((resolve, reject) => { if (i2 === pathEnv.length) return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd)); const ppRaw = pathEnv[i2]; const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw; const pCmd = path11.join(pathPart, cmd); const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd; resolve(subStep(p, i2, 0)); }); const subStep = (p, i2, ii) => new Promise((resolve, reject) => { if (ii === pathExt.length) return resolve(step(i2 + 1)); const ext = pathExt[ii]; isexe(p + ext, { pathExt: pathExtExe }, (er, is) => { if (!er && is) { if (opt.all) found.push(p + ext); else return resolve(p + ext); } return resolve(subStep(p, i2, ii + 1)); }); }); return cb ? step(0).then((res) => cb(null, res), cb) : step(0); }; var whichSync = (cmd, opt) => { opt = opt || {}; const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt); const found = []; for (let i2 = 0; i2 < pathEnv.length; i2++) { const ppRaw = pathEnv[i2]; const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw; const pCmd = path11.join(pathPart, cmd); const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd; for (let j = 0; j < pathExt.length; j++) { const cur = p + pathExt[j]; try { const is = isexe.sync(cur, { pathExt: pathExtExe }); if (is) { if (opt.all) found.push(cur); else return cur; } } catch (ex) { } } } if (opt.all && found.length) return found; if (opt.nothrow) return null; throw getNotFoundError(cmd); }; module2.exports = which; which.sync = whichSync; } }); // ../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js var require_path_key = __commonJS({ "../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js"(exports2, module2) { "use strict"; var pathKey2 = (options = {}) => { const environment = options.env || process.env; const platform2 = options.platform || process.platform; if (platform2 !== "win32") { return "PATH"; } return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path"; }; module2.exports = pathKey2; module2.exports.default = pathKey2; } }); // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js var require_resolveCommand = __commonJS({ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports2, module2) { "use strict"; var path11 = require("path"); var which = require_which(); var getPathKey = require_path_key(); function resolveCommandAttempt(parsed, withoutPathExt) { const env4 = parsed.options.env || process.env; const cwd = process.cwd(); const hasCustomCwd = parsed.options.cwd != null; const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled; if (shouldSwitchCwd) { try { process.chdir(parsed.options.cwd); } catch (err) { } } let resolved; try { resolved = which.sync(parsed.command, { path: env4[getPathKey({ env: env4 })], pathExt: withoutPathExt ? path11.delimiter : void 0 }); } catch (e) { } finally { if (shouldSwitchCwd) { process.chdir(cwd); } } if (resolved) { resolved = path11.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved); } return resolved; } function resolveCommand(parsed) { return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true); } module2.exports = resolveCommand; } }); // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js var require_escape = __commonJS({ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports2, module2) { "use strict"; var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g; function escapeCommand(arg) { arg = arg.replace(metaCharsRegExp, "^$1"); return arg; } function escapeArgument(arg, doubleEscapeMetaChars) { arg = `${arg}`; arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"'); arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1"); arg = `"${arg}"`; arg = arg.replace(metaCharsRegExp, "^$1"); if (doubleEscapeMetaChars) { arg = arg.replace(metaCharsRegExp, "^$1"); } return arg; } module2.exports.command = escapeCommand; module2.exports.argument = escapeArgument; } }); // ../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js var require_shebang_regex = __commonJS({ "../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js"(exports2, module2) { "use strict"; module2.exports = /^#!(.*)/; } }); // ../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js var require_shebang_command = __commonJS({ "../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js"(exports2, module2) { "use strict"; var shebangRegex = require_shebang_regex(); module2.exports = (string = "") => { const match = string.match(shebangRegex); if (!match) { return null; } const [path11, argument] = match[0].replace(/#! ?/, "").split(" "); const binary = path11.split("/").pop(); if (binary === "env") { return argument; } return argument ? `${binary} ${argument}` : binary; }; } }); // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js var require_readShebang = __commonJS({ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports2, module2) { "use strict"; var fs5 = require("fs"); var shebangCommand = require_shebang_command(); function readShebang(command) { const size = 150; const buffer = Buffer.alloc(size); let fd; try { fd = fs5.openSync(command, "r"); fs5.readSync(fd, buffer, 0, size, 0); fs5.closeSync(fd); } catch (e) { } return shebangCommand(buffer.toString()); } module2.exports = readShebang; } }); // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js var require_parse = __commonJS({ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports2, module2) { "use strict"; var path11 = require("path"); var resolveCommand = require_resolveCommand(); var escape = require_escape(); var readShebang = require_readShebang(); var isWin = process.platform === "win32"; var isExecutableRegExp = /\.(?:com|exe)$/i; var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i; function detectShebang(parsed) { parsed.file = resolveCommand(parsed); const shebang = parsed.file && readShebang(parsed.file); if (shebang) { parsed.args.unshift(parsed.file); parsed.command = shebang; return resolveCommand(parsed); } return parsed.file; } function parseNonShell(parsed) { if (!isWin) { return parsed; } const commandFile = detectShebang(parsed); const needsShell = !isExecutableRegExp.test(commandFile); if (parsed.options.forceShell || needsShell) { const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile); parsed.command = path11.normalize(parsed.command); parsed.command = escape.command(parsed.command); parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars)); const shellCommand = [parsed.command].concat(parsed.args).join(" "); parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`]; parsed.command = process.env.comspec || "cmd.exe"; parsed.options.windowsVerbatimArguments = true; } return parsed; } function parse(command, args, options) { if (args && !Array.isArray(args)) { options = args; args = null; } args = args ? args.slice(0) : []; options = Object.assign({}, options); const parsed = { command, args, options, file: void 0, original: { command, args } }; return options.shell ? parsed : parseNonShell(parsed); } module2.exports = parse; } }); // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js var require_enoent = __commonJS({ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js"(exports2, module2) { "use strict"; var isWin = process.platform === "win32"; function notFoundError(original, syscall) { return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), { code: "ENOENT", errno: "ENOENT", syscall: `${syscall} ${original.command}`, path: original.command, spawnargs: original.args }); } function hookChildProcess(cp, parsed) { if (!isWin) { return; } const originalEmit = cp.emit; cp.emit = function(name, arg1) { if (name === "exit") { const err = verifyENOENT(arg1, parsed); if (err) { return originalEmit.call(cp, "error", err); } } return originalEmit.apply(cp, arguments); }; } function verifyENOENT(status, parsed) { if (isWin && status === 1 && !parsed.file) { return notFoundError(parsed.original, "spawn"); } return null; } function verifyENOENTSync(status, parsed) { if (isWin && status === 1 && !parsed.file) { return notFoundError(parsed.original, "spawnSync"); } return null; } module2.exports = { hookChildProcess, verifyENOENT, verifyENOENTSync, notFoundError }; } }); // ../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js var require_cross_spawn = __commonJS({ "../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports2, module2) { "use strict"; var cp = require("child_process"); var parse = require_parse(); var enoent = require_enoent(); function spawn2(command, args, options) { const parsed = parse(command, args, options); const spawned = cp.spawn(parsed.command, parsed.args, parsed.options); enoent.hookChildProcess(spawned, parsed); return spawned; } function spawnSync2(command, args, options) { const parsed = parse(command, args, options); const result = cp.spawnSync(parsed.command, parsed.args, parsed.options); result.error = result.error || enoent.verifyENOENTSync(result.status, parsed); return result; } module2.exports = spawn2; module2.exports.spawn = spawn2; module2.exports.sync = spawnSync2; module2.exports._parse = parse; module2.exports._enoent = enoent; } }); // src/index.ts var import_path4 = __toESM(require("path")); var import_yargs = __toESM(require("yargs")); var import_prompts = require("@inquirer/prompts"); // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/vendor/ansi-styles/index.js var ANSI_BACKGROUND_OFFSET = 10; var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`; var wrapAnsi256 = (offset = 0) => (code) => `\x1B[${38 + offset};5;${code}m`; var wrapAnsi16m = (offset = 0) => (red2, green2, blue2) => `\x1B[${38 + offset};2;${red2};${green2};${blue2}m`; var styles = { modifier: { reset: [0, 0], // 21 isn't widely supported and 22 does the same thing bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], overline: [53, 55], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29] }, color: { black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], // Bright color blackBright: [90, 39], gray: [90, 39], // Alias of `blackBright` grey: [90, 39], // Alias of `blackBright` redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39] }, bgColor: { bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], // Bright color bgBlackBright: [100, 49], bgGray: [100, 49], // Alias of `bgBlackBright` bgGrey: [100, 49], // Alias of `bgBlackBright` bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49] } }; var modifierNames = Object.keys(styles.modifier); var foregroundColorNames = Object.keys(styles.color); var backgroundColorNames = Object.keys(styles.bgColor); var colorNames = [...foregroundColorNames, ...backgroundColorNames]; function assembleStyles() { const codes = /* @__PURE__ */ new Map(); for (const [groupName, group] of Object.entries(styles)) { for (const [styleName, style] of Object.entries(group)) { styles[styleName] = { open: `\x1B[${style[0]}m`, close: `\x1B[${style[1]}m` }; group[styleName] = styles[styleName]; codes.set(style[0], style[1]); } Object.defineProperty(styles, groupName, { value: group, enumerable: false }); } Object.defineProperty(styles, "codes", { value: codes, enumerable: false }); styles.color.close = "\x1B[39m"; styles.bgColor.close = "\x1B[49m"; styles.color.ansi = wrapAnsi16(); styles.color.ansi256 = wrapAnsi256(); styles.color.ansi16m = wrapAnsi16m(); styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET); styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET); Object.defineProperties(styles, { rgbToAnsi256: { value(red2, green2, blue2) { if (red2 === green2 && green2 === blue2) { if (red2 < 8) { return 16; } if (red2 > 248) { return 231; } return Math.round((red2 - 8) / 247 * 24) + 232; } return 16 + 36 * Math.round(red2 / 255 * 5) + 6 * Math.round(green2 / 255 * 5) + Math.round(blue2 / 255 * 5); }, enumerable: false }, hexToRgb: { value(hex) { const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16)); if (!matches) { return [0, 0, 0]; } let [colorString] = matches; if (colorString.length === 3) { colorString = [...colorString].map((character) => character + character).join(""); } const integer = Number.parseInt(colorString, 16); return [ /* eslint-disable no-bitwise */ integer >> 16 & 255, integer >> 8 & 255, integer & 255 /* eslint-enable no-bitwise */ ]; }, enumerable: false }, hexToAnsi256: { value: (hex) => styles.rgbToAnsi256(...styles.hexToRgb(hex)), enumerable: false }, ansi256ToAnsi: { value(code) { if (code < 8) { return 30 + code; } if (code < 16) { return 90 + (code - 8); } let red2; let green2; let blue2; if (code >= 232) { red2 = ((code - 232) * 10 + 8) / 255; green2 = red2; blue2 = red2; } else { code -= 16; const remainder = code % 36; red2 = Math.floor(code / 36) / 5; green2 = Math.floor(remainder / 6) / 5; blue2 = remainder % 6 / 5; } const value = Math.max(red2, green2, blue2) * 2; if (value === 0) { return 30; } let result = 30 + (Math.round(blue2) << 2 | Math.round(green2) << 1 | Math.round(red2)); if (value === 2) { result += 60; } return result; }, enumerable: false }, rgbToAnsi: { value: (red2, green2, blue2) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red2, green2, blue2)), enumerable: false }, hexToAnsi: { value: (hex) => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)), enumerable: false } }); return styles; } var ansiStyles = assembleStyles(); var ansi_styles_default = ansiStyles; // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/vendor/supports-color/index.js var import_node_process = __toESM(require("process"), 1); var import_node_os = __toESM(require("os"), 1); var import_node_tty = __toESM(require("tty"), 1); function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) { const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--"; const position = argv.indexOf(prefix + flag); const terminatorPosition = argv.indexOf("--"); return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition); } var { env } = import_node_process.default; var flagForceColor; if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) { flagForceColor = 0; } else if (hasFlag("color") || hasFlag("colors") || hasFlag("color=true") || hasFlag("color=always")) { flagForceColor = 1; } function envForceColor() { if ("FORCE_COLOR" in env) { if (env.FORCE_COLOR === "true") { return 1; } if (env.FORCE_COLOR === "false") { return 0; } return env.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3); } } function translateLevel(level) { if (level === 0) { return false; } return { level, hasBasic: true, has256: level >= 2, has16m: level >= 3 }; } function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) { const noFlagForceColor = envForceColor(); if (noFlagForceColor !== void 0) { flagForceColor = noFlagForceColor; } const forceColor = sniffFlags ? flagForceColor : noFlagForceColor; if (forceColor === 0) { return 0; } if (sniffFlags) { if (hasFlag("color=16m") || hasFlag("color=full") || hasFlag("color=truecolor")) { return 3; } if (hasFlag("color=256")) { return 2; } } if ("TF_BUILD" in env && "AGENT_NAME" in env) { return 1; } if (haveStream && !streamIsTTY && forceColor === void 0) { return 0; } const min = forceColor || 0; if (env.TERM === "dumb") { return min; } if (import_node_process.default.platform === "win32") { const osRelease = import_node_os.default.release().split("."); if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) { return Number(osRelease[2]) >= 14931 ? 3 : 2; } return 1; } if ("CI" in env) { if (["GITHUB_ACTIONS", "GITEA_ACTIONS", "CIRCLECI"].some((key) => key in env)) { return 3; } if (["TRAVIS", "APPVEYOR", "GITLAB_CI", "BUILDKITE", "DRONE"].some((sign) => sign in env) || env.CI_NAME === "codeship") { return 1; } return min; } if ("TEAMCITY_VERSION" in env) { return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0; } if (env.COLORTERM === "truecolor") { return 3; } if (env.TERM === "xterm-kitty") { return 3; } if ("TERM_PROGRAM" in env) { const version = Number.parseInt((env.TERM_PROGRAM_VERSION || "").split(".")[0], 10); switch (env.TERM_PROGRAM) { case "iTerm.app": { return version >= 3 ? 3 : 2; } case "Apple_Terminal": { return 2; } } } if (/-256(color)?$/i.test(env.TERM)) { return 2; } if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) { return 1; } if ("COLORTERM" in env) { return 1; } return min; } function createSupportsColor(stream, options = {}) { const level = _supportsColor(stream, { streamIsTTY: stream && stream.isTTY, ...options }); return translateLevel(level); } var supportsColor = { stdout: createSupportsColor({ isTTY: import_node_tty.default.isatty(1) }), stderr: createSupportsColor({ isTTY: import_node_tty.default.isatty(2) }) }; var supports_color_default = supportsColor; // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/utilities.js function stringReplaceAll(string, substring, replacer) { let index = string.indexOf(substring); if (index === -1) { return string; } const substringLength = substring.length; let endIndex = 0; let returnValue = ""; do { returnValue += string.slice(endIndex, index) + substring + replacer; endIndex = index + substringLength; index = string.indexOf(substring, endIndex); } while (index !== -1); returnValue += string.slice(endIndex); return returnValue; } function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) { let endIndex = 0; let returnValue = ""; do { const gotCR = string[index - 1] === "\r"; returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? "\r\n" : "\n") + postfix; endIndex = index + 1; index = string.indexOf("\n", endIndex); } while (index !== -1); returnValue += string.slice(endIndex); return returnValue; } // ../../node_modules/.pnpm/chalk@5.4.1/node_modules/chalk/source/index.js var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default; var GENERATOR = Symbol("GENERATOR"); var STYLER = Symbol("STYLER"); var IS_EMPTY = Symbol("IS_EMPTY"); var levelMapping = [ "ansi", "ansi", "ansi256", "ansi16m" ]; var styles2 = /* @__PURE__ */ Object.create(null); var applyOptions = (object, options = {}) => { if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) { throw new Error("The `level` option should be an integer from 0 to 3"); } const colorLevel = stdoutColor ? stdoutColor.level : 0; object.level = options.level === void 0 ? colorLevel : options.level; }; var chalkFactory = (options) => { const chalk2 = (...strings) => strings.join(" "); applyOptions(chalk2, options); Object.setPrototypeOf(chalk2, createChalk.prototype); return chalk2; }; function createChalk(options) { return chalkFactory(options); } Object.setPrototypeOf(createChalk.prototype, Function.prototype); for (const [styleName, style] of Object.entries(ansi_styles_default)) { styles2[styleName] = { get() { const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]); Object.defineProperty(this, styleName, { value: builder }); return builder; } }; } styles2.visible = { get() { const builder = createBuilder(this, this[STYLER], true); Object.defineProperty(this, "visible", { value: builder }); return builder; } }; var getModelAnsi = (model, level, type, ...arguments_) => { if (model === "rgb") { if (level === "ansi16m") { return ansi_styles_default[type].ansi16m(...arguments_); } if (level === "ansi256") { return ansi_styles_default[type].ansi256(ansi_styles_default.rgbToAnsi256(...arguments_)); } return ansi_styles_default[type].ansi(ansi_styles_default.rgbToAnsi(...arguments_)); } if (model === "hex") { return getModelAnsi("rgb", level, type, ...ansi_styles_default.hexToRgb(...arguments_)); } return ansi_styles_default[type][model](...arguments_); }; var usedModels = ["rgb", "hex", "ansi256"]; for (const model of usedModels) { styles2[model] = { get() { const { level } = this; return function(...arguments_) { const styler = createStyler(getModelAnsi(model, levelMapping[level], "color", ...arguments_), ansi_styles_default.color.close, this[STYLER]); return createBuilder(this, styler, this[IS_EMPTY]); }; } }; const bgModel = "bg" + model[0].toUpperCase() + model.slice(1); styles2[bgModel] = { get() { const { level } = this; return function(...arguments_) { const styler = createStyler(getModelAnsi(model, levelMapping[level], "bgColor", ...arguments_), ansi_styles_default.bgColor.close, this[STYLER]); return createBuilder(this, styler, this[IS_EMPTY]); }; } }; } var proto = Object.defineProperties(() => { }, { ...styles2, level: { enumerable: true, get() { return this[GENERATOR].level; }, set(level) { this[GENERATOR].level = level; } } }); var createStyler = (open, close, parent) => { let openAll; let closeAll; if (parent === void 0) { openAll = open; closeAll = close; } else { openAll = parent.openAll + open; closeAll = close + parent.closeAll; } return { open, close, openAll, closeAll, parent }; }; var createBuilder = (self, _styler, _isEmpty) => { const builder = (...arguments_) => applyStyle(builder, arguments_.length === 1 ? "" + arguments_[0] : arguments_.join(" ")); Object.setPrototypeOf(builder, proto); builder[GENERATOR] = self; builder[STYLER] = _styler; builder[IS_EMPTY] = _isEmpty; return builder; }; var applyStyle = (self, string) => { if (self.level <= 0 || !string) { return self[IS_EMPTY] ? "" : string; } let styler = self[STYLER]; if (styler === void 0) { return string; } const { openAll, closeAll } = styler; if (string.includes("\x1B")) { while (styler !== void 0) { string = stringReplaceAll(string, styler.close, styler.open); styler = styler.parent; } } const lfIndex = string.indexOf("\n"); if (lfIndex !== -1) { string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex); } return openAll + string + closeAll; }; Object.defineProperties(createChalk.prototype, styles2); var chalk = createChalk(); var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 }); var source_default = chalk; // src/index.ts var import_semver = require("semver"); var import_invariant2 = __toESM(require("invariant")); var import_cli2 = require("@toolpad/utils/cli"); // src/examples.ts var path = __toESM(require("path")); var os2 = __toESM(require("os")); var fs = __toESM(require("fs/promises")); var import_fs = require("fs"); var tar = __toESM(require("tar")); var import_stream = require("stream"); var import_promises = require("stream/promises"); var import_invariant = __toESM(require("invariant")); async function downloadTar(url) { const tempFile = path.join(os2.tmpdir(), `toolpad-cta-example.temp-${Date.now()}`); const response = await fetch(url); if (!response.ok) { throw new Error(`HTTP ${response.status} - ${response.statusText}`); } (0, import_invariant.default)(response.body, "Missing response body"); let current = 0; const readable2 = import_stream.Readable.fromWeb(response.body); readable2.on("data", (chunk) => { process.stdout.write( `Downloading\u2026 ${new Intl.NumberFormat("en-US", { style: "unit", unit: "megabyte" }).format(current / 1e6)}\r` ); current += chunk.length; }); await (0, import_promises.pipeline)(readable2, (0, import_fs.createWriteStream)(tempFile)); return tempFile; } async function downloadAndExtractExample(root, name) { console.log(); console.log(`${source_default.cyan("info")} - Downloading example "${name}" to ${source_default.cyan(root)}`); console.log(); const tempFile = await downloadTar("https://codeload.github.com/mui/toolpad/tar.gz/master"); await tar.x({ file: tempFile, cwd: root, strip: 2 + name.split("/").length, filter: (p) => p.includes(`toolpad-master/examples/studio/${name}/`) || p.includes(`toolpad-master/examples/core/${name}/`) }); console.log( `${source_default.green("success")} - Downloaded and extracted "${name}" to ${source_default.cyan(root)}` ); console.log(); await fs.unlink(tempFile); } // src/package.ts var import_path = __toESM(require("path")); var fs2 = __toESM(require("fs/promises")); function getPackageManager() { const userAgent = process.env.npm_config_user_agent; if (userAgent) { if (userAgent.startsWith("yarn")) { return "yarn"; } if (userAgent.startsWith("pnpm")) { return "pnpm"; } if (userAgent.startsWith("npm")) { return "npm"; } } return "pnpm"; } async function findCtaPackageJson() { const ctaPackageJsonPath = import_path.default.resolve(__dirname, "../package.json"); const content = await fs2.readFile(ctaPackageJsonPath, "utf8"); const packageJson2 = JSON.parse(content); return packageJson2; } // ../../node_modules/.pnpm/is-plain-obj@4.1.0/node_modules/is-plain-obj/index.js function isPlainObject(value) { if (typeof value !== "object" || value === null) { return false; } const prototype = Object.getPrototypeOf(value); return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in value) && !(Symbol.iterator in value); } // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/arguments/file-url.js var import_node_url = require("url"); var safeNormalizeFileUrl = (file, name) => { const fileString = normalizeFileUrl(normalizeDenoExecPath(file)); if (typeof fileString !== "string") { throw new TypeError(`${name} must be a string or a file URL: ${fileString}.`); } return fileString; }; var normalizeDenoExecPath = (file) => isDenoExecPath(file) ? file.toString() : file; var isDenoExecPath = (file) => typeof file !== "string" && file && Object.getPrototypeOf(file) === String.prototype; var normalizeFileUrl = (file) => file instanceof URL ? (0, import_node_url.fileURLToPath)(file) : file; // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/methods/parameters.js var normalizeParameters = (rawFile, rawArguments = [], rawOptions = {}) => { const filePath = safeNormalizeFileUrl(rawFile, "First argument"); const [commandArguments, options] = isPlainObject(rawArguments) ? [[], rawArguments] : [rawArguments, rawOptions]; if (!Array.isArray(commandArguments)) { throw new TypeError(`Second argument must be either an array of arguments or an options object: ${commandArguments}`); } if (commandArguments.some((commandArgument) => typeof commandArgument === "object" && commandArgument !== null)) { throw new TypeError(`Second argument must be an array of strings: ${commandArguments}`); } const normalizedArguments = commandArguments.map(String); const nullByteArgument = normalizedArguments.find((normalizedArgument) => normalizedArgument.includes("\0")); if (nullByteArgument !== void 0) { throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${nullByteArgument}`); } if (!isPlainObject(options)) { throw new TypeError(`Last argument must be an options object: ${options}`); } return [filePath, normalizedArguments, options]; }; // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/methods/template.js var import_node_child_process = require("child_process"); // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/utils/uint-array.js var import_node_string_decoder = require("string_decoder"); var { toString: objectToString } = Object.prototype; var isArrayBuffer = (value) => objectToString.call(value) === "[object ArrayBuffer]"; var isUint8Array = (value) => objectToString.call(value) === "[object Uint8Array]"; var bufferToUint8Array = (buffer) => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength); var textEncoder = new TextEncoder(); var stringToUint8Array = (string) => textEncoder.encode(string); var textDecoder = new TextDecoder(); var uint8ArrayToString = (uint8Array) => textDecoder.decode(uint8Array); var joinToString = (uint8ArraysOrStrings, encoding) => { const strings = uint8ArraysToStrings(uint8ArraysOrStrings, encoding); return strings.join(""); }; var uint8ArraysToStrings = (uint8ArraysOrStrings, encoding) => { if (encoding === "utf8" && uint8ArraysOrStrings.every((uint8ArrayOrString) => typeof uint8ArrayOrString === "string")) { return uint8ArraysOrStrings; } const decoder = new import_node_string_decoder.StringDecoder(encoding); const strings = uint8ArraysOrStrings.map((uint8ArrayOrString) => typeof uint8ArrayOrString === "string" ? stringToUint8Array(uint8ArrayOrString) : uint8ArrayOrString).map((uint8Array) => decoder.write(uint8Array)); const finalString = decoder.end(); return finalString === "" ? strings : [...strings, finalString]; }; var joinToUint8Array = (uint8ArraysOrStrings) => { if (uint8ArraysOrStrings.length === 1 && isUint8Array(uint8ArraysOrStrings[0])) { return uint8ArraysOrStrings[0]; } return concatUint8Arrays(stringsToUint8Arrays(uint8ArraysOrStrings)); }; var stringsToUint8Arrays = (uint8ArraysOrStrings) => uint8ArraysOrStrings.map((uint8ArrayOrString) => typeof uint8ArrayOrString === "string" ? stringToUint8Array(uint8ArrayOrString) : uint8ArrayOrString); var concatUint8Arrays = (uint8Arrays) => { const result = new Uint8Array(getJoinLength(uint8Arrays)); let index = 0; for (const uint8Array of uint8Arrays) { result.set(uint8Array, index); index += uint8Array.length; } return result; }; var getJoinLength = (uint8Arrays) => { let joinLength = 0; for (const uint8Array of uint8Arrays) { joinLength += uint8Array.length; } return joinLength; }; // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/methods/template.js var isTemplateString = (templates) => Array.isArray(templates) && Array.isArray(templates.raw); var parseTemplates = (templates, expressions) => { let tokens = []; for (const [index, template] of templates.entries()) { tokens = parseTemplate({ templates, expressions, tokens, index, template }); } if (tokens.length === 0) { throw new TypeError("Template script must not be empty"); } const [file, ...commandArguments] = tokens; return [file, commandArguments, {}]; }; var parseTemplate = ({ templates, expressions, tokens, index, template }) => { if (template === void 0) { throw new TypeError(`Invalid backslash sequence: ${templates.raw[index]}`); } const { nextTokens, leadingWhitespaces, trailingWhitespaces } = splitByWhitespaces(template, templates.raw[index]); const newTokens = concatTokens(tokens, nextTokens, leadingWhitespaces); if (index === expressions.length) { return newTokens; } const expression = expressions[index]; const expressionTokens = Array.isArray(expression) ? expression.map((expression2) => parseExpression(expression2)) : [parseExpression(expression)]; return concatTokens(newTokens, expressionTokens, trailingWhitespaces); }; var splitByWhitespaces = (template, rawTemplate) => { if (rawTemplate.length === 0) { return { nextTokens: [], leadingWhitespaces: false, trailingWhitespaces: false }; } const nextTokens = []; let templateStart = 0; const leadingWhitespaces = DELIMITERS.has(rawTemplate[0]); for (let templateIndex = 0, rawIndex = 0; templateIndex < template.length; templateIndex += 1, rawIndex += 1) { const rawCharacter = rawTemplate[rawIndex]; if (DELIMITERS.has(rawCharacter)) { if (templateStart !== templateIndex) { nextTokens.push(template.slice(templateStart, templateIndex)); } templateStart = templateIndex + 1; } else if (rawCharacter === "\\") { const nextRawCharacter = rawTemplate[rawIndex + 1]; if (nextRawCharacter === "\n") { templateIndex -= 1; rawIndex += 1; } else if (nextRawCharacter === "u" && rawTemplate[rawIndex + 2] === "{") { rawIndex = rawTemplate.indexOf("}", rawIndex + 3); } else { rawIndex += ESCAPE_LENGTH[nextRawCharacter] ?? 1; } } } const trailingWhitespaces = templateStart === template.length; if (!trailingWhitespaces) { nextTokens.push(template.slice(templateStart)); } return { nextTokens, leadingWhitespaces, trailingWhitespaces }; }; var DELIMITERS = /* @__PURE__ */ new Set([" ", " ", "\r", "\n"]); var ESCAPE_LENGTH = { x: 3, u: 5 }; var concatTokens = (tokens, nextTokens, isSeparated) => isSeparated || tokens.length === 0 || nextTokens.length === 0 ? [...tokens, ...nextTokens] : [ ...tokens.slice(0, -1), `${tokens.at(-1)}${nextTokens[0]}`, ...nextTokens.slice(1) ]; var parseExpression = (expression) => { const typeOfExpression = typeof expression; if (typeOfExpression === "string") { return expression; } if (typeOfExpression === "number") { return String(expression); } if (isPlainObject(expression) && ("stdout" in expression || "isMaxBuffer" in expression)) { return getSubprocessResult(expression); } if (expression instanceof import_node_child_process.ChildProcess || Object.prototype.toString.call(expression) === "[object Promise]") { throw new TypeError("Unexpected subprocess in template expression. Please use ${await subprocess} instead of ${subprocess}."); } throw new TypeError(`Unexpected "${typeOfExpression}" in template expression`); }; var getSubprocessResult = ({ stdout }) => { if (typeof stdout === "string") { return stdout; } if (isUint8Array(stdout)) { return uint8ArrayToString(stdout); } if (stdout === void 0) { throw new TypeError(`Missing result.stdout in template expression. This is probably due to the previous subprocess' "stdout" option.`); } throw new TypeError(`Unexpected "${typeof stdout}" stdout in template expression`); }; // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/methods/main-sync.js var import_node_child_process3 = require("child_process"); // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/arguments/specific.js var import_node_util = require("util"); // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/utils/standard-stream.js var import_node_process2 = __toESM(require("process"), 1); var isStandardStream = (stream) => STANDARD_STREAMS.includes(stream); var STANDARD_STREAMS = [import_node_process2.default.stdin, import_node_process2.default.stdout, import_node_process2.default.stderr]; var STANDARD_STREAMS_ALIASES = ["stdin", "stdout", "stderr"]; var getStreamName = (fdNumber) => STANDARD_STREAMS_ALIASES[fdNumber] ?? `stdio[${fdNumber}]`; // ../../node_modules/.pnpm/execa@9.6.0/node_modules/execa/lib/arguments/specific.js var normalizeFdSpecificOptions = (options) => { const optionsCopy = { ...options }; for (const optionName of FD_SPECIFIC_OPTIONS) { optionsCopy[optionName] = normalizeFdSpecificOption(options, optionName); } return optionsCopy; }; var normalizeFdSpecificOption = (options, optionName) => { const optionBaseArray = Array.from({ length: getStdioLength(options) + 1 }); const optionArray = normalizeFdSpecificValue(options[optionName], optionBaseArray, optionName); return addDefaultValue(optionArray, optionName); }; var getStdioLength = ({ stdio }) => Array.isArray(stdio) ? Math.max(stdio.length, STANDARD_STREAMS_ALIASES.length) : STANDARD_STREAMS_ALIASES.length; var normalizeFdSpecificValue = (optionValue, optionArray, optionName) => isPlainObject(optionValue) ? normalizeOptionObject(optionValue, optionArray, optionName) : optionArray.fill(optionValue); var normalizeOptionObject = (optionValue, optionArray, optionName) => { for (const fdName of Object.keys(optionValue).sort(compareFdName)) { for (const fdNumber of parseFdName(fdName, optionName, optionArray)) { optionArray[fdNumber] = optionValue[fdName]; } } return optionArray; }; var compareFdName = (fdNameA, fdNameB) => getFdNameOrder(fdNameA) < getFdNameOrder(fdNameB) ? 1 : -1; var getFdNameOrder = (fdName) => { if (fdName === "stdout" || fdName === "stderr") { return 0; } return fdName === "all" ? 2 : 1; }; var parseFdName = (fdName, optionName, optionArray) => { if (fdName === "ipc") { return [optionArray.length - 1]; } const fdNumber = parseFd(fdName); if (fdNumber === void 0 || fdNumber === 0) { throw new TypeError(`"${optionName}.${fdName}" is invalid. It must be "${optionName}.stdout", "${optionName}.stderr", "${optionName}.all", "${optionName}.ipc", or "${optionName}.fd3", "${optionName}.fd4" (and so on).`); } if (fdNumber >= optionArray.length) { throw new TypeError(`"${optionName}.${fdName}" is invalid: that file descriptor does not exist. Please set the "stdio" option to ensure that file descriptor exists.`); } return fdNumber === "all" ? [1, 2] : [fdNumber]; }; var parseFd = (fdName) => { if (fdName === "all") { return fdName; } if (STANDARD_STREAMS_ALIASES.includes(fdName)) { return STANDARD_STREAMS_ALIASES.indexOf(fdName); } const regexpResult = FD_REGEXP.exec(fdName); if (regexpResult !== null) { return Number(regexpResult[1]); } }; var FD_REGEXP = /^fd(\d+)$/; var addDefaultValue = (optionArray, optionName) => optionArray.map((optionValue) => optionValue === void 0 ? DEFAULT_OPTIONS[optionName] : optionValue); var verboseDefault = (0, import_node_util.debuglog)("execa").enabled ? "full" : "none"; var DEFAULT_OPTIONS = { lines: false, buffer: true, maxBuffer: 1e3 * 1e3 * 100, verbose: verboseDefault, stripFinalNewline: true }; var FD_SPECIFIC_OPTIONS = ["lines", "buffer", "maxBuffer", "verbose", "st