-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
feat: eslint #78
Merged
Merged
feat: eslint #78
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5e8a792
chore: add eslint
vltansky 20a6c16
refactor: eslint
vltansky 9637c31
feat: add eslint
vltansky 3305daf
chore: vscode prettier formating
vltansky 0a67137
ci: lint workflow
vltansky 980b8d4
Merge branch 'master' of https://github.com/h5bp/create-html5-boilerp…
vltansky c15378c
ci(lint): run on node 14
vltansky b7762ae
chore: vscode recommended extensions
vltansky 1999426
chore: add eslint recommended plugin
vltansky 55296f8
Merge branch 'master' of https://github.com/h5bp/create-html5-boilerp…
vltansky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,14 @@ | ||
module.exports = { | ||
env: { | ||
browser: true, | ||
commonjs: true, | ||
es2020: true, | ||
}, | ||
extends: ["eslint:recommended", "airbnb/base", "plugin:prettier/recommended"], | ||
parserOptions: { | ||
ecmaVersion: 12, | ||
}, | ||
rules: { | ||
"no-console": "off", | ||
}, | ||
}; |
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,33 @@ | ||
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions | ||
|
||
name: Eslint | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Get npm cache directory | ||
id: npm-cache | ||
run: | | ||
echo "::set-output name=dir::$(npm config get cache)" | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ${{ steps.npm-cache.outputs.dir }} | ||
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- uses: actions/checkout@v2 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: "14.x" | ||
- run: npm ci | ||
- run: npm run lint |
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,3 @@ | ||
{ | ||
"recommendations": ["dbaeumer.vscode-eslint", "esbenp.prettier-vscode"] | ||
} |
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,6 @@ | ||
{ | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"eslint.enable": true, | ||
"eslint.validate": ["javascript"] | ||
} |
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,74 +1,29 @@ | ||
"use strict"; | ||
const yargs_parser = require("yargs-parser"); | ||
const yargsParser = require("yargs-parser"); | ||
const path = require("path"); | ||
const chalk = require("chalk"); | ||
const langsList = require("./countries.json"); | ||
const inquirer = require("inquirer"); | ||
const fuzzy = require("fuzzy"); | ||
const ora = require("ora"); | ||
const { extract } = require("pacote"); | ||
const glob = require("fast-glob"); | ||
const fs = require("fs-extra"); | ||
const os = require("os"); | ||
|
||
const packageName = "html5-boilerplate"; | ||
const tempDir = os.tmpdir() + `/${packageName}-staging`; | ||
const tempDir = `${os.tmpdir()}/${packageName}-staging`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
const elapsed = require("elapsed-time-logger"); | ||
const compareVersions = require("compare-versions"); | ||
const langsList = require("./countries.json"); | ||
|
||
let spinner; | ||
inquirer.registerPrompt( | ||
"autocomplete", | ||
require("inquirer-autocomplete-prompt") | ||
); | ||
module.exports = async (argvs) => { | ||
const argv = yargs_parser(argvs, { | ||
alias: { release: ["r"], yes: ["y"] }, | ||
}); | ||
const timer = elapsed.start(); | ||
const version = (argv["release"] || "latest").toString(); | ||
const targetDir = path.resolve(argv["_"][0] || "./"); | ||
const override = await checkFolder(targetDir, argv); | ||
if (!override) { | ||
console.log(chalk.red("Aborted")); | ||
return; | ||
} | ||
spinner = ora( | ||
`Downloading ${packageName} version '${version}' to ${targetDir}` | ||
).start(); | ||
await fs.ensureDir(tempDir); | ||
try { | ||
const { from: nameWithVersion } = await extract( | ||
packageName + "@" + version, | ||
tempDir, | ||
{} | ||
); | ||
await fs.copy(tempDir + "/dist", targetDir); | ||
const timerDownloaded = timer.get(); | ||
await onLoad(targetDir, version, argv); | ||
spinner.succeed( | ||
` ${nameWithVersion} copied to ${targetDir} in ${timerDownloaded}. Have fun!` | ||
); | ||
return; | ||
} catch (err) { | ||
if (err.code === "ETARGET") { | ||
const msg = chalk.red( | ||
`version '${err.wanted}' not found in npm registry\navailable versions:\n` | ||
); | ||
spinner.fail(msg + err.versions.reverse().join(" | ")); | ||
throw err.code; | ||
} | ||
spinner.fail("✖ Unexpected error"); | ||
throw new Error(err); | ||
} finally { | ||
await fs.remove(tempDir); | ||
} | ||
}; | ||
|
||
const checkFolder = async (targetDir, argv) => { | ||
const folderExists = await fs.pathExists(targetDir); | ||
if (!folderExists) { | ||
return true; | ||
} | ||
if (argv["yes"] === true) { | ||
if (!folderExists || argv.yes === true) { | ||
return true; | ||
} | ||
const folderFiles = await fs.readdir(targetDir); | ||
|
@@ -81,17 +36,23 @@ const checkFolder = async (targetDir, argv) => { | |
}); | ||
return override; | ||
} | ||
return true; | ||
}; | ||
|
||
const onLoad = async (targetDir, version, argv) => { | ||
// see https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows | ||
const npmIgnoreFiles = await glob( | ||
`${targetDir.replace(/\\/g, "/")}/**/.npmignore` | ||
); | ||
for (const npmIgnore of npmIgnoreFiles) { | ||
await fs.rename(npmIgnore, npmIgnore.replace(/\.npmignore$/, ".gitignore")); | ||
} | ||
const skipPrompts = argv["yes"] === true; | ||
await Promise.all( | ||
npmIgnoreFiles.map((fileName) => { | ||
return fs.rename( | ||
fileName, | ||
fileName.replace(/\.npmignore$/, ".gitignore") | ||
); | ||
}) | ||
); | ||
const skipPrompts = argv.yes === true; | ||
|
||
if (skipPrompts) { | ||
return; | ||
|
@@ -100,11 +61,11 @@ const onLoad = async (targetDir, version, argv) => { | |
const langListOut = []; | ||
/* istanbul ignore if */ | ||
if (!argv.lang) { | ||
for (const { title, value } of langsList) { | ||
langsList.forEach(({ title, value }) => { | ||
const text = `${title} (${value})`; | ||
langListMap[text] = value; | ||
langListOut.push(text); | ||
} | ||
}); | ||
langListOut.splice(1, 0, "Enter custom"); | ||
} | ||
spinner.stop(); | ||
|
@@ -121,6 +82,7 @@ const onLoad = async (targetDir, version, argv) => { | |
type: "input", | ||
name: "customLang", | ||
message: "Enter custom language code", | ||
// eslint-disable-next-line | ||
when: ({ langChoice }) => !argv.lang && langChoice === langListOut[1], | ||
}, | ||
{ | ||
|
@@ -135,10 +97,10 @@ const onLoad = async (targetDir, version, argv) => { | |
const lang = argv.lang || langListMap[langChoice] || customLang || ""; | ||
const removeJqueryFlag = removeJquery !== undefined ? removeJquery : false; | ||
try { | ||
const indexFile = targetDir + "/index.html"; | ||
const indexFile = `${targetDir}/index.html`; | ||
const sourceHTML = await fs.readFile(indexFile, "utf-8"); | ||
let resultHTML = sourceHTML.replace( | ||
/(<html.*lang=)\"([^"]*)\"/gi, | ||
/(<html.*lang=)"([^"]*)"/gi, | ||
`$1"${lang}"` | ||
); | ||
if (removeJqueryFlag) { | ||
|
@@ -154,3 +116,47 @@ const onLoad = async (targetDir, version, argv) => { | |
throw new Error(err); | ||
} | ||
}; | ||
|
||
module.exports = async (argvs) => { | ||
const argv = yargsParser(argvs, { | ||
alias: { release: ["r"], yes: ["y"] }, | ||
}); | ||
const timer = elapsed.start(); | ||
const version = (argv.release || "latest").toString(); | ||
const targetDir = path.resolve(argv._[0] || "./"); | ||
const override = await checkFolder(targetDir, argv); | ||
if (!override) { | ||
console.log(chalk.red("Aborted")); | ||
return; | ||
} | ||
spinner = ora( | ||
`Downloading ${packageName} version '${version}' to ${targetDir}` | ||
).start(); | ||
await fs.ensureDir(tempDir); | ||
try { | ||
const { from: nameWithVersion } = await extract( | ||
`${packageName}@${version}`, | ||
tempDir, | ||
{} | ||
); | ||
await fs.copy(`${tempDir}/dist`, targetDir); | ||
const timerDownloaded = timer.get(); | ||
await onLoad(targetDir, version, argv); | ||
spinner.succeed( | ||
` ${nameWithVersion} copied to ${targetDir} in ${timerDownloaded}. Have fun!` | ||
); | ||
return; | ||
} catch (err) { | ||
if (err.code === "ETARGET") { | ||
const msg = chalk.red( | ||
`version '${err.wanted}' not found in npm registry\navailable versions:\n` | ||
); | ||
spinner.fail(msg + err.versions.reverse().join(" | ")); | ||
throw err.code; | ||
} | ||
spinner.fail("✖ Unexpected error"); | ||
throw new Error(err); | ||
} finally { | ||
await fs.remove(tempDir); | ||
} | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pretty big one for this project