-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(schematics): Allow users to set prettier config, add relevant mi…
…gration
- Loading branch information
1 parent
b17b186
commit 56a6611
Showing
11 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
{ | ||
"singleQuote": true, | ||
"overrides": [ | ||
{ | ||
"files": "*.ts", | ||
"options": { | ||
"parser": "typescript" | ||
} | ||
} | ||
] | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
packages/schematics/migrations/20180309-create-or-update-prettierrc-file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { writeFileSync, readFileSync, readdirSync, unlinkSync } from 'fs'; | ||
import { join } from 'path'; | ||
|
||
import { updateJsonFile } from '../../shared/fileutils'; | ||
import { ExistingPrettierConfig, resolveUserExistingPrettierConfig } from '../../shared/common'; | ||
|
||
export default { | ||
description: 'Create or update prettier configuration', | ||
run: async () => { | ||
const resolvedExisting = await resolveUserExistingPrettierConfig(); | ||
const existingUserConfig = { | ||
...(resolvedExisting ? resolvedExisting.config : null) | ||
}; | ||
const PREVIOUSLY_HARDCODED_NRWL_CONFIG = { | ||
singleQuote: true, | ||
printWidth: 120 | ||
}; | ||
const finalConfig = { | ||
...existingUserConfig, | ||
...PREVIOUSLY_HARDCODED_NRWL_CONFIG | ||
}; | ||
// cleanup old configuration source, if applicable | ||
if (resolvedExisting) { | ||
cleanUpExistingConfig(resolvedExisting); | ||
} | ||
// create new configuration file | ||
writeFileSync('.prettierrc', JSON.stringify(finalConfig, null, 2)); | ||
} | ||
}; | ||
|
||
function cleanUpExistingConfig(resolvedExisting: ExistingPrettierConfig): void { | ||
switch (resolvedExisting.sourceFilepath) { | ||
case join(process.cwd(), 'package.json'): | ||
return updateJsonFile('package.json', json => { | ||
delete json.prettier; | ||
}); | ||
default: | ||
return unlinkSync(resolvedExisting.sourceFilepath); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/schematics/src/collection/application/files/__directory__/.prettierrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= defaultNrwlPrettierConfig %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters