-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add prettier format task, refactor files
- Loading branch information
Showing
9 changed files
with
162 additions
and
77 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
build/ | ||
build-*/ | ||
coverage/ | ||
node_modules/ | ||
tmp/ | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.npmrc | ||
.yarn/* | ||
!.yarn/releases | ||
!.yarn/plugins | ||
.pnp.* | ||
cc-test-reporter | ||
lerna-debug.log* | ||
npm-debug.log* | ||
tsconfig.*buildinfo | ||
yarn-debug.log* | ||
yarn-error.log* | ||
package-lock.json | ||
.idea | ||
.vscode | ||
yarn.lock | ||
LICENSE |
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,10 @@ | ||
module.exports = { | ||
semi: true, | ||
trailingComma: 'all', | ||
singleQuote: true, | ||
jsxSingleQuote: true, | ||
printWidth: 120, | ||
tabWidth: 2, | ||
bracketSameLine: true, | ||
importOrder: ['.*react.*', '^@polkadot/(.*)$', '^@dedot/(.*)$', '<THIRD_PARTY_MODULES>', '^[./]'], | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as prettier from 'prettier'; | ||
import * as path from 'path'; | ||
import { promises as fs } from 'fs'; | ||
import { Options } from '../types.js'; | ||
import { execa } from 'execa'; | ||
|
||
export async function prettierFormat(rootDir: string, targetDir: string, options: Options) { | ||
if (!options.skipInstall) { | ||
await execa('yarn', ['prettify'], { cwd: targetDir }); | ||
} else { | ||
const prettierConfig = await prettier.resolveConfig(path.resolve(rootDir, './.prettierrc.js')); | ||
|
||
await prettierFormatWithConfig(targetDir, prettierConfig); | ||
} | ||
} | ||
|
||
export async function prettierFormatWithConfig(dir: string, config: prettier.Options | null) { | ||
const files = await fs.readdir(dir, { withFileTypes: true }); | ||
|
||
for (const file of files) { | ||
const filePath = path.join(dir, file.name); | ||
|
||
if (file.isDirectory()) { | ||
await prettierFormatWithConfig(filePath, config); | ||
} else { | ||
const fileInfo = await prettier.getFileInfo(filePath); | ||
|
||
if (fileInfo.ignored || !fileInfo.inferredParser) { | ||
continue; | ||
} | ||
|
||
const content = await fs.readFile(filePath, 'utf-8'); | ||
const formatted = await prettier.format(content, { | ||
filepath: filePath, | ||
...config, | ||
}); | ||
|
||
await fs.writeFile(filePath, formatted, 'utf-8'); | ||
} | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
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