Skip to content

Commit

Permalink
Fixed default prettier options for project without prettier #17
Browse files Browse the repository at this point in the history
  • Loading branch information
victortotem committed Dec 16, 2020
1 parent abd2f48 commit d5cdebb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion lib/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@ const prettier = __importStar(require("prettier"));
const path_1 = __importDefault(require("path"));
const log_symbols_1 = __importDefault(require("log-symbols"));
const chalk_1 = __importDefault(require("chalk"));
const defaultPrettierOptions = {
printWidth: 100,
tabWidth: 2,
trailingComma: 'es5',
singleQuote: true,
semi: true,
bracketSpacing: true,
htmlWhitespaceSensitivity: 'strict',
};
async function saveRoutesFiles(filePath, templateRoutes) {
try {
let prettierFoundOptions = await prettier.resolveConfig(process.cwd());
if (!prettierFoundOptions) {
prettierFoundOptions = require('../.prettierrc');
prettierFoundOptions = defaultPrettierOptions;
}
const formatedModelsFile = prettier.format(templateRoutes, {
...prettierFoundOptions,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-typed-router",
"version": "0.2.13",
"version": "0.2.14",
"description": "Provide autocompletion for pages route names generated by Nuxt router",
"main": "lib/module.js",
"keywords": [
Expand Down
12 changes: 11 additions & 1 deletion src/save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@ import path from 'path';
import logSymbols from 'log-symbols';
import chalk from 'chalk';

const defaultPrettierOptions = {
printWidth: 100,
tabWidth: 2,
trailingComma: 'es5',
singleQuote: true,
semi: true,
bracketSpacing: true,
htmlWhitespaceSensitivity: 'strict',
} as const;

export async function saveRoutesFiles(filePath: string, templateRoutes: string) {
try {
let prettierFoundOptions = await prettier.resolveConfig(process.cwd());

if (!prettierFoundOptions) {
prettierFoundOptions = require('../.prettierrc');
prettierFoundOptions = defaultPrettierOptions;
}

const formatedModelsFile = prettier.format(templateRoutes, {
Expand Down

0 comments on commit d5cdebb

Please sign in to comment.