-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(eslint): update settings and fix source code
- Loading branch information
1 parent
46e8086
commit a236089
Showing
12 changed files
with
227 additions
and
222 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,26 +1,26 @@ | ||
module.exports = { | ||
extends: ['@commitlint/config-conventional'], | ||
extends: ["@commitlint/config-conventional"], | ||
|
||
rules: { | ||
'scope-enum': [ | ||
"scope-enum": [ | ||
2, | ||
'always', | ||
"always", | ||
[ | ||
'', | ||
'deps', | ||
'package', | ||
'readme', | ||
'eslint', | ||
'editorconfig', | ||
'commitlint', | ||
'coverage', | ||
'release', | ||
'init', | ||
'api', | ||
'markdownlint', | ||
'travis', | ||
'prettier', | ||
"", | ||
"deps", | ||
"package", | ||
"readme", | ||
"eslint", | ||
"editorconfig", | ||
"commitlint", | ||
"coverage", | ||
"release", | ||
"init", | ||
"api", | ||
"markdownlint", | ||
"travis", | ||
"prettier", | ||
], | ||
], | ||
}, | ||
} | ||
}; |
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,14 +1,15 @@ | ||
module.exports = { | ||
root: true, | ||
|
||
extends: ['ybiquitous'], | ||
extends: ["ybiquitous/node"], | ||
|
||
overrides: [ | ||
{ | ||
files: ['**/test/**/*.js'], | ||
files: ["**/test/**/*.js"], | ||
rules: { | ||
'no-shadow': ['error', { allow: ['t'] }], | ||
"no-shadow": ["error", { allow: ["t"] }], | ||
"import/no-internal-modules": "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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env node | ||
const cli = require(`../lib/cli`) | ||
const cli = require(`../lib/cli`); | ||
|
||
cli() | ||
cli(); |
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,3 +1,3 @@ | ||
const init = require(`./lib/init`) | ||
const init = require(`./lib/init`); | ||
|
||
module.exports = { init } | ||
module.exports = { init }; |
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,13 +1,13 @@ | ||
const yargs = require('yargs') | ||
const init = require('./init') | ||
const yargs = require("yargs"); | ||
const init = require("./init"); | ||
|
||
module.exports = function cli() { | ||
// eslint-disable-next-line no-unused-expressions | ||
yargs | ||
.usage('$0 <command>') | ||
.command('init', init.desc, {}, init) | ||
.usage("$0 <command>") | ||
.command("init", init.desc, {}, init) | ||
.demandCommand(1) | ||
.strict() | ||
.alias('help', 'h') | ||
.alias('version', 'v').argv | ||
} | ||
.alias("help", "h") | ||
.alias("version", "v").argv; | ||
}; |
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,95 +1,96 @@ | ||
const path = require('path') | ||
const { EOL } = require('os') | ||
const fs = require('fs-extra') | ||
const originalPackage = require('../package.json') | ||
const path = require("path"); | ||
const { EOL } = require("os"); | ||
const fs = require("fs-extra"); | ||
const originalPackage = require("../package.json"); | ||
|
||
const packagePath = (...pathElements) => | ||
path.join(...[__dirname, '..', ...pathElements]) | ||
path.join(...[__dirname, "..", ...pathElements]); | ||
|
||
const template = name => path.join(__dirname, '..', 'templates', name) | ||
const template = name => path.join(__dirname, "..", "templates", name); | ||
|
||
class Init { | ||
constructor(baseDir, logger) { | ||
this.baseDir = baseDir | ||
this.logger = logger | ||
this.baseDir = baseDir; | ||
this.logger = logger; | ||
} | ||
|
||
async copyFile(src, dest) { | ||
await fs.copy(src, dest) | ||
this.logger(`${dest} was updated.`) | ||
await fs.copy(src, dest); | ||
this.logger(`${dest} was updated.`); | ||
} | ||
|
||
currentPath(...pathElements) { | ||
return path.join(...[this.baseDir, ...pathElements]) | ||
return path.join(...[this.baseDir, ...pathElements]); | ||
} | ||
|
||
async writeFile(fileName, fileContent) { | ||
const file = this.currentPath(fileName) | ||
await fs.writeFile(file, `${fileContent}\n`) | ||
this.logger(`${file} was updated.`) | ||
const file = this.currentPath(fileName); | ||
await fs.writeFile(file, `${fileContent}\n`); | ||
this.logger(`${file} was updated.`); | ||
} | ||
|
||
async readFile(fileName) { | ||
return fs.readFile(this.currentPath(fileName), 'utf8') | ||
readFile(fileName) { | ||
return fs.readFile(this.currentPath(fileName), "utf8"); | ||
} | ||
|
||
// eslint-disable-next-line max-statements | ||
async updatePackageFile() { | ||
const packageInfo = JSON.parse(await this.readFile('package.json')) | ||
const packageInfo = JSON.parse(await this.readFile("package.json")); | ||
|
||
// update 'scripts' | ||
if (!('scripts' in packageInfo)) { | ||
packageInfo.scripts = {} | ||
if (!("scripts" in packageInfo)) { | ||
packageInfo.scripts = {}; | ||
} | ||
const { scripts } = packageInfo | ||
if (!('test' in scripts)) { | ||
scripts.test = 'test' | ||
const { scripts } = packageInfo; | ||
if (!("test" in scripts)) { | ||
scripts.test = "test"; | ||
} | ||
scripts['test:watch'] = `${scripts.test} --watch` | ||
scripts['test:coverage'] = 'echo "unsupported." && exit 1' | ||
scripts["test:watch"] = `${scripts.test} --watch`; | ||
scripts["test:coverage"] = 'echo "unsupported." && exit 1'; | ||
Object.keys(originalPackage.scripts) | ||
.filter(key => !(key === 'test' || key.startsWith('test:'))) | ||
.filter(key => !(key === "test" || key.startsWith("test:"))) | ||
.forEach(key => { | ||
scripts[key] = originalPackage.scripts[key] | ||
}) | ||
scripts[key] = originalPackage.scripts[key]; | ||
}); | ||
|
||
// update other keys | ||
const keys = ['lint-staged'] | ||
const keys = ["lint-staged"]; | ||
keys.forEach(key => { | ||
if (!(key in packageInfo)) { | ||
packageInfo[key] = {} | ||
packageInfo[key] = {}; | ||
} | ||
Object.assign(packageInfo[key], originalPackage[key]) | ||
}) | ||
Object.assign(packageInfo[key], originalPackage[key]); | ||
}); | ||
|
||
await this.writeFile('package.json', JSON.stringify(packageInfo, null, 2)) | ||
await this.writeFile("package.json", JSON.stringify(packageInfo, null, 2)); | ||
} | ||
|
||
async writeTemplateFile(name) { | ||
await this.copyFile(template(name), this.currentPath(name)) | ||
await this.copyFile(template(name), this.currentPath(name)); | ||
} | ||
|
||
async writePackageFile(name) { | ||
await this.copyFile(packagePath(name), this.currentPath(name)) | ||
await this.copyFile(packagePath(name), this.currentPath(name)); | ||
} | ||
} | ||
|
||
const defaultLogger = msg => process.stdout.write(`${msg}${EOL}`) | ||
const defaultLogger = msg => process.stdout.write(`${msg}${EOL}`); | ||
|
||
module.exports = async function init({ | ||
cwd = process.cwd(), | ||
logger = defaultLogger, | ||
} = {}) { | ||
const cmd = new Init(cwd, logger) | ||
await cmd.updatePackageFile() | ||
await cmd.writePackageFile('.editorconfig') | ||
await cmd.writePackageFile('.prettierignore') | ||
await cmd.writePackageFile('.markdownlint.json') | ||
await cmd.writeTemplateFile('.eslintrc.js') | ||
await cmd.writeTemplateFile('.commitlintrc.js') | ||
} | ||
const cmd = new Init(cwd, logger); | ||
await cmd.updatePackageFile(); | ||
await cmd.writePackageFile(".editorconfig"); | ||
await cmd.writePackageFile(".prettierignore"); | ||
await cmd.writePackageFile(".markdownlint.json"); | ||
await cmd.writeTemplateFile(".eslintrc.js"); | ||
await cmd.writeTemplateFile(".commitlintrc.js"); | ||
}; | ||
|
||
module.exports.desc = `Setup npm project: | ||
- Update 'package.json' | ||
- Create '.commitlintrc.js' | ||
- Create '.editorconfig' | ||
- Create '.eslintrc.js'` | ||
- Create '.eslintrc.js'`; |
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 |
---|---|---|
@@ -1,27 +1,27 @@ | ||
const path = require('path') | ||
const cp = require('child_process') | ||
const path = require("path"); | ||
const cp = require("child_process"); | ||
|
||
const tested = path.join(process.cwd(), 'bin', 'cli.js') | ||
const tested = path.join(process.cwd(), "bin", "cli.js"); | ||
|
||
module.exports = function exec(...args) { | ||
const options = { | ||
env: { ...process.env, LANG: 'C' }, | ||
} | ||
const lastArg = args[args.length - 1] | ||
if (lastArg && typeof lastArg === 'object') { | ||
options.cwd = lastArg.cwd | ||
env: { ...process.env, LANG: "C" }, | ||
}; | ||
const lastArg = args[args.length - 1]; | ||
if (lastArg && typeof lastArg === "object") { | ||
options.cwd = lastArg.cwd; | ||
} | ||
return new Promise((resolve, reject) => { | ||
cp.execFile(tested, args, options, (error, stdout, stderr) => { | ||
if (error) { | ||
/* eslint-disable no-param-reassign */ | ||
error.stdout = stdout | ||
error.stderr = stderr | ||
error.stdout = stdout; | ||
error.stderr = stderr; | ||
/* eslint-enable no-param-reassign */ | ||
reject(error) | ||
reject(error); | ||
} else { | ||
resolve({ stdout, stderr }) | ||
resolve({ stdout, stderr }); | ||
} | ||
}) | ||
}) | ||
} | ||
}); | ||
}); | ||
}; |
Oops, something went wrong.