{"version":3,"sources":["jsdelivr-header.js","/npm/create-narrat@4.1.11/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;OCHO,OAAQ,iBACR,SAAU,mBACR,kBAAqB,kBACvB,aAAc,kBACd,YAAa,iBACX,MAAO,IAAK,MAAO,WAAc,WAI1C,MAAM,KAAO,SAAS,QAAQ,KAAK,MAAM,GAAI,CAAE,OAAQ,CAAC,OAClD,IAAM,QAAQ,MAEd,UAAY,CAChB,CACE,KAAM,QACN,KAAM,aACN,YAAa,2CACb,MAAO,QAET,CACE,KAAM,OACN,KAAM,YACN,YACE,4EACF,MAAO,QAUL,YAAc,CAClB,WAAY,cAGd,eAAe,OACb,IAAI,EAAY,gBAAgB,KAAK,EAAE,IACnC,EAAiB,KAAK,UAAY,KAAK,EAE3C,MAAM,EAAmB,cACnB,EAAiB,IACP,MAAd,EAAoB,KAAK,SAAS,KAAK,WAAa,EAEtD,IAAI,EAAS,CAAC,EAEd,IACE,QAAe,QACb,CACE,CACE,KAAM,EAAY,KAAO,OACzB,KAAM,cACN,QAAS,MAAM,iBACf,QAAS,EACT,QAAU,IACR,EAAY,gBAAgB,EAAM,QAAU,CAAgB,GAGhE,CACE,KAAM,KACH,GAAG,WAAW,IAAc,QAAQ,GAAa,KAAO,UAC3D,KAAM,YACN,QAAS,KACQ,MAAd,EACG,oBACA,qBAAqB,MACzB,sDAEJ,CACE,KAAM,CAAC,GAAK,aAAc,CAAC,KACzB,IAAkB,IAAd,EACF,MAAM,IAAI,MAAM,IAAI,KAAO,wBAE7B,OAAO,IAAI,EAEb,KAAM,oBAER,CACE,KAAM,IAAO,mBAAmB,KAAoB,KAAO,OAC3D,KAAM,cACN,QAAS,MACP,2DAEF,QAAS,IAAM,mBAAmB,KAClC,SAAW,GACT,mBAAmB,IAAQ,6BAE/B,CACE,KACE,GAAkB,UAAU,SAAS,GACjC,KACA,SACN,KAAM,WACN,QAC4B,iBAAnB,GACN,UAAU,SAAS,GAIhB,MAA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ADC,EAEJ,QAAQ,IAAI,UACZ,QAAQ,IAAI,mBAGZ,QAAQ,IAAI,KAAK,aACjB,QAAQ,IAAI,KAAK,WAGrB,QAAQ,KACV,CAKA,SAAS,gBAAgB,GACvB,OAAO,GAAW,OAAO,QAAQ,QAAS,GAC5C,CAEA,SAAS,KAAK,EAAK,GACJ,GAAG,SAAS,GAChB,cACP,QAAQ,EAAK,GAEb,GAAG,aAAa,EAAK,EAEzB,CAKA,SAAS,mBAAmB,GAC1B,MAAO,6DAA6D,KAClE,EAEJ,CAKA,SAAS,mBAAmB,GAC1B,OAAO,EACJ,OACA,cACA,QAAQ,OAAQ,KAChB,QAAQ,QAAS,IACjB,QAAQ,gBAAiB,IAC9B,CAMA,SAAS,QAAQ,EAAQ,GACvB,GAAG,UAAU,EAAS,CAAE,WAAW,IACnC,IAAK,MAAM,KAAQ,GAAG,YAAY,GAAS,CAGzC,KAFgB,KAAK,QAAQ,EAAQ,GACpB,KAAK,QAAQ,EAAS,GAEzC,CACF,CAKA,SAAS,QAAQ,GACf,MAAM,EAAQ,GAAG,YAAY,GAC7B,OAAwB,IAAjB,EAAM,QAAkC,IAAjB,EAAM,QAA6B,SAAb,EAAM,EAC5D,CAKA,SAAS,SAAS,GAChB,GAAK,GAAG,WAAW,GAGnB,IAAK,MAAM,KAAQ,GAAG,YAAY,GAChC,GAAG,OAAO,KAAK,QAAQ,EAAK,GAAO,CAAE,WAAW,EAAM,OAAO,GAEjE,CAMA,SAAS,iBAAiB,GACxB,IAAK,EAAW,OAChB,MACM,EADU,EAAU,MAAM,KAAK,GACV,MAAM,KACjC,MAAO,CACL,KAAM,EAAW,GACjB,QAAS,EAAW,GAExB,CAEA,OAAO,OAAO,IACZ,QAAQ,MAAM,EAAE","file":"/npm/create-narrat@4.1.11/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/create-narrat@4.1.11/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","#!/usr/bin/env node\n\n// @ts-check\nimport fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport minimist from 'minimist';\nimport prompts from 'prompts';\nimport { green, red, reset, yellow } from 'kolorist';\n\n// Avoids autoconversion to number of the project name by defining that the args\n// non associated with an option ( _ ) needs to be parsed as a string. See #4606\nconst argv = minimist(process.argv.slice(2), { string: ['_'] });\nconst cwd = process.cwd();\n\nconst TEMPLATES = [\n  {\n    path: 'empty',\n    name: 'Empty Game',\n    description: 'Game with an empty script to get started',\n    color: yellow,\n  },\n  {\n    path: 'demo',\n    name: 'Demo Game',\n    description:\n      'Game with a demo script and config/assets to have an example to work with',\n    color: green,\n  },\n  // {\n  //   path: 'rpg',\n  //   name: 'RPG Game',\n  //   description: 'RPG Game Demo',\n  //   color: green,\n  // },\n];\n\nconst renameFiles = {\n  _gitignore: '.gitignore',\n};\n\nasync function init() {\n  let targetDir = formatTargetDir(argv._[0]);\n  let templateChoice = argv.template || argv.t;\n\n  const defaultTargetDir = 'narrat-game';\n  const getProjectName = () =>\n    targetDir === '.' ? path.basename(path.resolve()) : targetDir;\n\n  let result = {};\n\n  try {\n    result = await prompts(\n      [\n        {\n          type: targetDir ? null : 'text',\n          name: 'projectName',\n          message: reset('Project name:'),\n          initial: defaultTargetDir,\n          onState: (state) => {\n            targetDir = formatTargetDir(state.value) || defaultTargetDir;\n          },\n        },\n        {\n          type: () =>\n            !fs.existsSync(targetDir) || isEmpty(targetDir) ? null : 'confirm',\n          name: 'overwrite',\n          message: () =>\n            (targetDir === '.'\n              ? 'Current directory'\n              : `Target directory \"${targetDir}\"`) +\n            ` is not empty. Remove existing files and continue?`,\n        },\n        {\n          type: (_, { overwrite } = {}) => {\n            if (overwrite === false) {\n              throw new Error(red('✖') + ' Operation cancelled');\n            }\n            return null;\n          },\n          name: 'overwriteChecker',\n        },\n        {\n          type: () => (isValidPackageName(getProjectName()) ? null : 'text'),\n          name: 'packageName',\n          message: reset(\n            'Package name (game name with dashes, like narrat-game):',\n          ),\n          initial: () => toValidPackageName(getProjectName()),\n          validate: (dir) =>\n            isValidPackageName(dir) || 'Invalid package.json name',\n        },\n        {\n          type:\n            templateChoice && TEMPLATES.includes(templateChoice)\n              ? null\n              : 'select',\n          name: 'template',\n          message:\n            typeof templateChoice === 'string' &&\n            !TEMPLATES.includes(templateChoice)\n              ? reset(\n                  `\"${templateChoice}\" isn't a valid template. Please choose from below: `,\n                )\n              : reset('Select a template:'),\n          initial: 0,\n          choices: TEMPLATES.map((template) => {\n            const templateColor = template.color;\n            return {\n              title: templateColor(template.name),\n              value: template,\n            };\n          }),\n        },\n      ],\n      {\n        onCancel: () => {\n          throw new Error(red('✖') + ' Operation cancelled');\n        },\n      },\n    );\n  } catch (cancelled) {\n    console.log(cancelled.message);\n    return;\n  }\n\n  // user choice associated with prompts\n  const { template, overwrite, packageName } = result;\n\n  const root = path.join(cwd, targetDir);\n\n  if (overwrite) {\n    emptyDir(root);\n  } else if (!fs.existsSync(root)) {\n    fs.mkdirSync(root, { recursive: true });\n  }\n\n  // determine template\n  templateChoice = template.path;\n\n  console.log(`\\nCreating a narrat game in ${root}...`);\n\n  const baseTemplateDir = path.resolve(\n    fileURLToPath(import.meta.url),\n    '..',\n    'template',\n  );\n  const gameTemplateDir = path.resolve(\n    fileURLToPath(import.meta.url),\n    '..',\n    `template-games`,\n    `${templateChoice}`,\n  );\n\n  const write = (root, dir, file, content) => {\n    const targetPath = renameFiles[file]\n      ? path.join(root, renameFiles[file])\n      : path.join(root, file);\n    if (content) {\n      fs.writeFileSync(targetPath, content);\n    } else {\n      copy(path.join(dir, file), targetPath);\n    }\n  };\n\n  // 1. Copy base template\n\n  const baseFiles = fs.readdirSync(baseTemplateDir);\n  for (const file of baseFiles.filter((f) => f !== 'package.json')) {\n    write(root, baseTemplateDir, file);\n  }\n\n  // 2. Rename and copy package.json\n  const pkg = JSON.parse(\n    fs.readFileSync(path.join(baseTemplateDir, `package.json`), 'utf-8'),\n  );\n\n  pkg.name = packageName || getProjectName();\n\n  write(root, baseTemplateDir, 'package.json', JSON.stringify(pkg, null, 2));\n\n  // 3. Copy game template\n\n  const gameFiles = fs.readdirSync(gameTemplateDir);\n  for (const file of gameFiles) {\n    write(root, gameTemplateDir, file);\n  }\n\n  // 4. Finish and show run instructions\n  const pkgInfo = pkgFromUserAgent(process.env.npm_config_user_agent);\n  const pkgManager = pkgInfo ? pkgInfo.name : 'npm';\n\n  console.log(`\\nDone. Now run:\\n`);\n  if (root !== cwd) {\n    console.log(`  cd ${path.relative(cwd, root)}`);\n  }\n  switch (pkgManager) {\n    case 'yarn':\n      console.log('  yarn');\n      console.log('  yarn dev');\n      break;\n    default:\n      console.log(`  ${pkgManager} install`);\n      console.log(`  ${pkgManager} start`);\n      break;\n  }\n  console.log();\n}\n\n/**\n * @param {string | undefined} targetDir\n */\nfunction formatTargetDir(targetDir) {\n  return targetDir?.trim().replace(/\\/+$/g, '');\n}\n\nfunction copy(src, dest) {\n  const stat = fs.statSync(src);\n  if (stat.isDirectory()) {\n    copyDir(src, dest);\n  } else {\n    fs.copyFileSync(src, dest);\n  }\n}\n\n/**\n * @param {string} projectName\n */\nfunction isValidPackageName(projectName) {\n  return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(\n    projectName,\n  );\n}\n\n/**\n * @param {string} projectName\n */\nfunction toValidPackageName(projectName) {\n  return projectName\n    .trim()\n    .toLowerCase()\n    .replace(/\\s+/g, '-')\n    .replace(/^[._]/, '')\n    .replace(/[^a-z0-9-~]+/g, '-');\n}\n\n/**\n * @param {string} srcDir\n * @param {string} destDir\n */\nfunction copyDir(srcDir, destDir) {\n  fs.mkdirSync(destDir, { recursive: true });\n  for (const file of fs.readdirSync(srcDir)) {\n    const srcFile = path.resolve(srcDir, file);\n    const destFile = path.resolve(destDir, file);\n    copy(srcFile, destFile);\n  }\n}\n\n/**\n * @param {string} path\n */\nfunction isEmpty(path) {\n  const files = fs.readdirSync(path);\n  return files.length === 0 || (files.length === 1 && files[0] === '.git');\n}\n\n/**\n * @param {string} dir\n */\nfunction emptyDir(dir) {\n  if (!fs.existsSync(dir)) {\n    return;\n  }\n  for (const file of fs.readdirSync(dir)) {\n    fs.rmSync(path.resolve(dir, file), { recursive: true, force: true });\n  }\n}\n\n/**\n * @param {string | undefined} userAgent process.env.npm_config_user_agent\n * @returns object | undefined\n */\nfunction pkgFromUserAgent(userAgent) {\n  if (!userAgent) return undefined;\n  const pkgSpec = userAgent.split(' ')[0];\n  const pkgSpecArr = pkgSpec.split('/');\n  return {\n    name: pkgSpecArr[0],\n    version: pkgSpecArr[1],\n  };\n}\n\ninit().catch((e) => {\n  console.error(e);\n});\n"]}