@nrwl/schematics
Version:
43 lines (42 loc) • 2.05 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const fs_1 = require("fs");
const path_1 = require("path");
const workspace_1 = require("@nrwl/workspace");
const workspace_2 = require("@nrwl/workspace");
exports.default = {
description: 'Create or update prettier configuration',
run: () => __awaiter(this, void 0, void 0, function* () {
const resolvedExisting = yield workspace_2.resolveUserExistingPrettierConfig();
const existingUserConfig = Object.assign({}, (resolvedExisting ? resolvedExisting.config : null));
const PREVIOUSLY_HARDCODED_NRWL_CONFIG = {
singleQuote: true,
printWidth: 120
};
const finalConfig = Object.assign({}, existingUserConfig, PREVIOUSLY_HARDCODED_NRWL_CONFIG);
// cleanup old configuration source, if applicable
if (resolvedExisting) {
cleanUpExistingConfig(resolvedExisting);
}
// create new configuration file
fs_1.writeFileSync('.prettierrc', JSON.stringify(finalConfig, null, 2));
})
};
function cleanUpExistingConfig(resolvedExisting) {
switch (resolvedExisting.sourceFilepath) {
case path_1.join(process.cwd(), 'package.json'):
return workspace_1.updateJsonFile('package.json', json => {
delete json.prettier;
});
default:
return fs_1.unlinkSync(resolvedExisting.sourceFilepath);
}
}