create-app-setup
Version:
A CLI tool to quickly set up frontend & backend projects with various frameworks.
46 lines (45 loc) • 1.81 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.prettierConfig = void 0;
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const Chalk_1 = require("../helper/Chalk");
const prettierConfig = (props) => {
const { destinationPath, pkgJson } = props;
const prettierrc = {
semi: true,
singleQuote: true,
tabWidth: 2,
trailingComma: "es5",
};
const prettierIgnore = `node_modules
dist
build
package-lock.json`;
const prettierFilePath = path_1.default.join(destinationPath, ".prettierrc");
const prettierIgnoreFilePath = path_1.default.join(destinationPath, ".prettierignore");
const pkgJsonPath = path_1.default.resolve(pkgJson);
const pkgJsonFileContent = JSON.parse(fs_1.default.readFileSync(pkgJsonPath, "utf-8"));
const prettierDevDependencies = {
prettier: "3.0.0",
};
pkgJsonFileContent.devDependencies = {
...pkgJsonFileContent.devDependencies,
...prettierDevDependencies,
};
if (!fs_1.default.existsSync(destinationPath)) {
console.log(Chalk_1.chalk.red.bold(`❌ Error: Something went wrong `));
process.exit(1);
}
if (!fs_1.default.existsSync(prettierFilePath)) {
fs_1.default.writeFileSync(prettierFilePath, JSON.stringify(prettierrc, null, 2));
}
if (!fs_1.default.existsSync(prettierIgnoreFilePath)) {
fs_1.default.writeFileSync(prettierIgnoreFilePath, prettierIgnore);
}
fs_1.default.writeFileSync(pkgJsonPath, JSON.stringify(pkgJsonFileContent, null, 2));
};
exports.prettierConfig = prettierConfig;
;