UNPKG

create-ext-app

Version:

## Installation This is a [Node.js](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/).

102 lines 3.92 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.modifyTsConfig = exports.modifyManifest = exports.loadJavascriptTemplate = exports.loadTypeScriptTemplate = void 0; const { execSync } = require("child_process"); const fs = require("fs-extra"); const chalk_1 = __importDefault(require("chalk")); function setAppName(path, projectName) { try { const packageJson = JSON.parse(fs.readFileSync(`${path}/package.json`, "utf8")); packageJson.name = projectName; fs.writeFileSync(`${path}/package.json`, JSON.stringify(packageJson, null, 2), "utf8"); } catch (err) { console.error("Error:", err); process.exit(1); } } function loadTypeScriptTemplate(repo, projectPath, modules, projectName) { try { execSync(`git clone --depth 1 --quiet ${repo} ${projectPath}`); process.chdir(projectPath); setAppName(projectPath, projectName); console.log(chalk_1.default.cyan("\nInstalling dependencies. This might take a couple of minutes.")); execSync("npm install"); modules.forEach((module) => { execSync(`npm install @extpkg/types-${module} --save-dev`); }); execSync("npx rimraf ./.git"); console.log(`\nSuccess! Created testing at ${projectPath}`); console.log(`\nInside that directory, you can run:`); console.log(`\n ${chalk_1.default.cyan("npm run build:")}`); console.log(` To buldle the project into static files for production`); } catch (error) { console.log(error); process.exit(1); } } exports.loadTypeScriptTemplate = loadTypeScriptTemplate; function loadJavascriptTemplate(repo, projectPath) { try { execSync(`git clone --depth 1 --quiet ${repo} ${projectPath}`); process.chdir(projectPath); execSync("npx rimraf ./.git"); console.log(`\nSuccess! Created testing at ${projectPath}`); } catch (error) { console.log(error); process.exit(1); } } exports.loadJavascriptTemplate = loadJavascriptTemplate; function modifyManifest(path, modules, projectName, templateName) { const manifestFilePath = templateName == "javascript" ? `${path}/manifest.json` : `${path}/src/manifest.json`; try { const manifestJson = JSON.parse(fs.readFileSync(manifestFilePath, "utf8")); if (!manifestJson.modules) { manifestJson.modules = {}; } modules.forEach((moduleName) => { manifestJson.modules[moduleName] = {}; }); manifestJson.name = projectName; manifestJson.short_name = projectName; fs.writeFileSync(manifestFilePath, JSON.stringify(manifestJson, null, 2), "utf8"); } catch (err) { console.error("Error:", err); process.exit(1); } } exports.modifyManifest = modifyManifest; function modifyTsConfig(path, modules) { try { const tsconfigJson = JSON.parse(fs.readFileSync(`${path}/tsconfig.json`, "utf8")); if (!tsconfigJson.compilerOptions) { tsconfigJson.compilerOptions = {}; } if (!tsconfigJson.compilerOptions.types) { tsconfigJson.compilerOptions.types = []; } let newTypes = []; modules.forEach((module) => { newTypes.push(`@extpkg/types-${module}`); }); tsconfigJson.compilerOptions.types = [ ...new Set([...tsconfigJson.compilerOptions.types, ...newTypes]), ]; fs.writeFileSync(`${path}/tsconfig.json`, JSON.stringify(tsconfigJson, null, 2), "utf8"); } catch (err) { console.error("Error:", err); process.exit(1); } } exports.modifyTsConfig = modifyTsConfig; //# sourceMappingURL=utils.js.map