diff --git a/README.md b/README.md index 7836eae..245b360 100644 --- a/README.md +++ b/README.md @@ -108,6 +108,10 @@ Then follow these instructions to see your app: Builds the app for production to the build folder.
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: diff --git a/index.js b/index.js index f83c308..c1c4d36 100755 --- a/index.js +++ b/index.js @@ -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 @@ -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') { @@ -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( @@ -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}`); diff --git a/templates/shared/dotfiles/editorconfig b/templates/shared/dotfiles/editorconfig new file mode 100644 index 0000000..35dd4ea --- /dev/null +++ b/templates/shared/dotfiles/editorconfig @@ -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 diff --git a/templates/shared/devtools/gitignore b/templates/shared/dotfiles/gitignore similarity index 100% rename from templates/shared/devtools/gitignore rename to templates/shared/dotfiles/gitignore diff --git a/templates/shared/dotfiles/prettierignore b/templates/shared/dotfiles/prettierignore new file mode 100644 index 0000000..94f8c8d --- /dev/null +++ b/templates/shared/dotfiles/prettierignore @@ -0,0 +1,4 @@ +# See https://prettier.io/docs/en/ignore.html for more about ignoring files from Prettier. + +# Ignore artifacts: +build diff --git a/templates/shared/dotfiles/prettierrc b/templates/shared/dotfiles/prettierrc new file mode 100644 index 0000000..bfee3cd --- /dev/null +++ b/templates/shared/dotfiles/prettierrc @@ -0,0 +1,10 @@ +{ + "singleQuote": true, + "trailingComma": "es5", + "bracketSpacing": true, + "bracketSameLine": false, + "arrowParens": "always", + "htmlWhitespaceSensitivity": "css", + "insertPragma": false, + "semi": true +} diff --git a/templates/shared/override-page/gitignore b/templates/shared/override-page/gitignore deleted file mode 100644 index 9f9ca76..0000000 --- a/templates/shared/override-page/gitignore +++ /dev/null @@ -1,12 +0,0 @@ -# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. - -# dependencies -/node_modules - -# production -/build - -# misc -.DS_Store - -npm-debug.log* diff --git a/templates/shared/popup/gitignore b/templates/shared/popup/gitignore deleted file mode 100644 index b7dfc99..0000000 --- a/templates/shared/popup/gitignore +++ /dev/null @@ -1,10 +0,0 @@ -# dependencies -/node_modules - -# production -/build - -# misc -.DS_Store - -npm-debug.log*