UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

1 lines 4.42 kB
{"version":3,"sources":["../../src/commands/init/install/utilities.ts"],"names":["installPackage","context","packageName","dev","isInstalled","isPackageListed","options","projectRoot","skipInstalls","log","LogLevelLabel","WARN","result","install","cwd","isNumber","exitCode","ERROR","stderr","Error","installPackages","packages","Promise","all","map","pkg","name"],"mappings":";;;;;;;;AA+BA,eAAsBA,cAAAA,CACpBC,OAAAA,EACAC,WAAAA,EACAC,GAAAA,GAAM,KAAA,EAAK;AAEX,EAAA,MAAMC,cAAc,MAAMC,0BAAAA,CACxBH,WAAAA,EACAD,OAAAA,CAAQK,QAAQC,WAAW,CAAA;AAE7B,EAAA,IAAI,CAACH,WAAAA,EAAa;AAChB,IAAA,IAAIH,OAAAA,CAAQK,OAAAA,CAAQE,YAAAA,KAAiB,IAAA,EAAM;AACzCP,MAAAA,OAAAA,CAAQQ,GAAAA,CACNC,mBAAAA,CAAcC,IAAAA,EACd,CAAA,aAAA,EAAgBT,WAAAA,CAAAA,uDAAAA,CAAoE,CAAA;AAGtF,MAAA,MAAMU,MAAAA,GAAS,MAAMC,eAAAA,CAAQX,WAAAA,EAAa;AACxCY,QAAAA,GAAAA,EAAKb,QAAQK,OAAAA,CAAQC,WAAAA;AACrBJ,QAAAA;OACF,CAAA;AACA,MAAA,IAAIY,kBAASH,MAAAA,CAAOI,QAAQ,CAAA,IAAKJ,MAAAA,CAAOI,WAAW,CAAA,EAAG;AACpDf,QAAAA,OAAAA,CAAQQ,GAAAA,CAAIC,mBAAAA,CAAcO,KAAAA,EAAOL,MAAAA,CAAOM,MAAM,CAAA;AAC9C,QAAA,MAAM,IAAIC,KAAAA,CACR,CAAA,gDAAA,EAAmDjB,WAAAA,CAAAA,CAAAA,CAAc,CAAA;AAErE,MAAA;IACF,CAAA,MAAO;AACLD,MAAAA,OAAAA,CAAQQ,GAAAA,CACNC,mBAAAA,CAAcC,IAAAA,EACd,CAAA,aAAA,EAAgBT,WAAAA,CAAAA,2GAAAA,CAAwH,CAAA;AAE5I,IAAA;AACF,EAAA;AACF;AAjCsBF,wBAAAA,CAAAA,cAAAA,EAAAA,gBAAAA,CAAAA;AAyCtB,eAAsBoB,eAAAA,CACpBnB,SACAoB,QAAAA,EAAgD;AAEhD,EAAA,OAAOC,OAAAA,CAAQC,GAAAA,CACbF,QAAAA,CAASG,GAAAA,CAAI,OAAMC,GAAAA,KAAOzB,cAAAA,CAAeC,OAAAA,EAASwB,GAAAA,CAAIC,IAAAA,EAAMD,GAAAA,CAAItB,GAAG,CAAA,CAAA,CAAA;AAEvE;AAPsBiB,wBAAAA,CAAAA,eAAAA,EAAAA,iBAAAA,CAAAA","file":"chunk-RWO2P75L.cjs","sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Storm Stack\n\n This code was released as part of the Storm Stack project. Storm Stack\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/storm-stack.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/storm-stack\n Documentation: https://docs.stormsoftware.com/projects/storm-stack\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { install } from \"@stryke/fs/install\";\nimport { isPackageListed } from \"@stryke/fs/package-fns\";\nimport { isNumber } from \"@stryke/type-checks/is-number\";\nimport type { Context } from \"../../../types/context\";\n\n/**\n * Installs a package if it is not already installed.\n *\n * @param context - The resolved options\n * @param packageName - The name of the package to install\n * @param dev - Whether to install the package as a dev dependency\n */\nexport async function installPackage(\n context: Context,\n packageName: string,\n dev = false\n) {\n const isInstalled = await isPackageListed(\n packageName,\n context.options.projectRoot\n );\n if (!isInstalled) {\n if (context.options.skipInstalls !== true) {\n context.log(\n LogLevelLabel.WARN,\n `The package \"${packageName}\" is not installed. It will be installed automatically.`\n );\n\n const result = await install(packageName, {\n cwd: context.options.projectRoot,\n dev\n });\n if (isNumber(result.exitCode) && result.exitCode > 0) {\n context.log(LogLevelLabel.ERROR, result.stderr);\n throw new Error(\n `An error occurred while installing the package \"${packageName}\"`\n );\n }\n } else {\n context.log(\n LogLevelLabel.WARN,\n `The package \"${packageName}\" is not installed. Since the \"skipInstalls\" option is set to true, it will not be installed automatically.`\n );\n }\n }\n}\n\n/**\n * Installs a package if it is not already installed.\n *\n * @param context - The resolved options\n * @param packages - The list of packages to install\n */\nexport async function installPackages(\n context: Context,\n packages: Array<{ name: string; dev?: boolean }>\n) {\n return Promise.all(\n packages.map(async pkg => installPackage(context, pkg.name, pkg.dev))\n );\n}\n"]}