Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code formatting config #28

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ Then follow these instructions to see your app:
Builds the app for production to the build folder.<br>
Zip the build folder and your app is ready to be published on Chrome Web Store.

### `npm run format`

Formats all the HTML, CSS, JavaScript, TypeScript and JSON files.

## What's included?

Your environment will have everything you need to build a Chrome Extension:
Expand Down
23 changes: 21 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ function createExtension(name, { overridePage, devtools, language }) {
watch:
'webpack --mode=development --watch --config config/webpack.config.js',
build: 'webpack --mode=production --config config/webpack.config.js',
format:
'prettier --write --ignore-unknown "{config,public,src}/**/*.{html,css,js,ts,json}"',
};

// Create package file in project directory
Expand Down Expand Up @@ -213,7 +215,8 @@ function createExtension(name, { overridePage, devtools, language }) {
'copy-webpack-plugin@^10.2.4',
'mini-css-extract-plugin@^2.6.0',
'css-loader@^6.7.1',
'file-loader@^6.2.0'
'file-loader@^6.2.0',
'prettier@^2.6.2'
);

if (languageName === 'typescript') {
Expand Down Expand Up @@ -270,7 +273,20 @@ function createExtension(name, { overridePage, devtools, language }) {
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
// See: https://github.com/npm/npm/issues/1862
// Source: https://github.com/facebook/create-react-app/blob/47e9e2c7a07bfe60b52011cf71de5ca33bdeb6e3/packages/react-scripts/scripts/init.js#L138
fs.moveSync(path.join(root, 'gitignore'), path.join(root, '.gitignore'), []);
// Also followed same convention for other dotfiles.
const dotFilesSource = path.resolve(
__dirname,
'templates',
'shared',
'dotfiles'
);

fs.readdirSync(dotFilesSource).map(function (fileName) {
return fs.copyFileSync(
path.join(dotFilesSource, fileName),
path.join(root, '.' + fileName)
);
});

// Setup the manifest file
const manifestDetails = Object.assign(
Expand Down Expand Up @@ -354,6 +370,9 @@ function createExtension(name, { overridePage, devtools, language }) {
console.log(chalk.cyan(` ${command} run build`));
console.log(' Bundles the app into static files for Chrome store.');
console.log();
console.log(chalk.cyan(` ${command} run format`));
console.log(' Formats all the files.');
console.log();
console.log('We suggest that you begin by typing:');
console.log();
console.log(` 1. ${chalk.cyan('cd')} ${name}`);
Expand Down
19 changes: 19 additions & 0 deletions templates/shared/dotfiles/editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# See https://editorconfig.org for more about editor config.

# top-most EditorConfig file
root = true

# Match all files
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true

# Markdown files
[*.md]
max_line_length = 0
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions templates/shared/dotfiles/prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# See https://prettier.io/docs/en/ignore.html for more about ignoring files from Prettier.

# Ignore artifacts:
build
10 changes: 10 additions & 0 deletions templates/shared/dotfiles/prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"singleQuote": true,
"trailingComma": "es5",
"bracketSpacing": true,
"bracketSameLine": false,
"arrowParens": "always",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"semi": true
}
12 changes: 0 additions & 12 deletions templates/shared/override-page/gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions templates/shared/popup/gitignore

This file was deleted.