UNPKG

a2r

Version:
23 lines (22 loc) 956 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); const fs_1 = require("@a2r/fs"); const colors_1 = require("./colors"); const exec_1 = __importDefault(require("../tools/exec")); /** * Ensures a `package.json` file exists. If not, runs `npm init` with `--force` flag * @param {string} projectPath Project base path */ const ensureNpmInit = async (projectPath) => { const packageJsonPath = path_1.default.resolve(projectPath, 'package.json'); const packageJsonExists = await (0, fs_1.exists)(packageJsonPath); if (!packageJsonExists) { (0, colors_1.log)(`Running ${(0, colors_1.terminalCommand)('npm init')}...`); await (0, exec_1.default)('npm', ['init', '--force']); } }; exports.default = ensureNpmInit;