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

V2 #14

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

V2 #14

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
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
node_modules
node_modules
43 changes: 26 additions & 17 deletions generators/donation/saofile.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,57 @@
// @ts-check

const fs = require('fs')
const path = require('path')

/** @type {import('sao').GeneratorConfig} */
module.exports = {
description: 'Add a "postinstall" script to show donation URL',
prepare() {
if (!fs.existsSync(path.join(this.outPath, 'package.json'))) {
throw this.createError(`Cannot find package.json in ${this.outPath}`)
async prepare() {
if (!(await this.hasOutputFile('package.json'))) {
throw this.createError(`Cannot find package.json in ${this.outFolder}`)
}
},
prompts() {
return [
{
type: 'input',
name: 'name',
default: this.pkg.name || this.outFolder,
message: 'Your project name',
required: true
required: true,
},
{
type: 'input',
name: 'url',
message: 'The URL where users can donate to your project',
store: true,
required: true,
validate: v => /^https?:\/\//.test(v)
}
validate: (v) =>
/^https?:\/\//.test(v)
? false
: `Invalid URL, must start with http(s)://`,
},
]
},
actions() {
return [
this.answers.url !== 'none' && {
type: 'modify',
files: 'package.json',
handler: data => {
handler: (data) => {
data.scripts = Object.assign({}, data.scripts, {
postinstall: `node -e \"console.log('\\u001b[35m\\u001b[1mLove ${this.answers.name}? You can now donate to support the author:\\u001b[22m\\u001b[39m\\n> \\u001b[36m${this.answers.url}\\u001b[39m')\"`
postinstall: `node -e \"console.log('\\u001b[35m\\u001b[1mLove ${this.answers.name}? You can now donate to support the author:\\u001b[22m\\u001b[39m\\n> \\u001b[36m${this.answers.url}\\u001b[39m')\"`,
})
return data
}
}
},
},
].filter(Boolean)
},
async completed() {
this.logger.success('Added "postinstall" script in package.json!')
const commands = [process.cwd() !== this.outPath &&`cd ${this.outPath}`, `${this.npmClient} run postinstall`].filter(Boolean)
this.logger.tip(`Run ${this.chalk.cyan(commands.join(' && '))} to see the effect.`)
}
}
const commands = [
process.cwd() !== this.outDir && `cd ${this.outDir}`,
`${this.npmClient} run postinstall`,
].filter(Boolean)
this.logger.tip(
`Run ${this.colors.cyan(commands.join(' && '))} to see the effect.`
)
},
}
39 changes: 18 additions & 21 deletions lib/update-pkg.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const when = (condition, value, fallback) => (condition ? value : fallback)
const commands = cmds => cmds.filter(Boolean).join(' && ') || undefined
const commands = (cmds) => cmds.filter(Boolean).join(' && ') || undefined

module.exports = (
{
Expand All @@ -11,7 +11,7 @@ module.exports = (
coverage,
description,
username,
email
email,
},
data
) => {
Expand All @@ -31,26 +31,23 @@ module.exports = (
when(cli, ['index.js', 'cli.js'], ['index.js'])
),
scripts: {
'test:cov': when(coverage, commands([
when(useLinter, 'npm run lint'),
'jest --coverage'
])),
test: commands([
when(useLinter, 'npm run lint'),
'jest'
]),
'test:cov': when(
coverage,
commands([when(useLinter, 'npm run lint'), 'jest --coverage'])
),
test: commands([when(useLinter, 'npm run lint'), when(unitTest, 'jest')]),
lint: when(useLinter, eslint),
prepublishOnly: when(compile, 'npm run build'),
build: when(compile, 'bili')
build: when(compile, 'bili'),
},
repository: {
url: `${username}/${name}`,
type: 'git'
type: 'git',
},
author: `${username}<${email}>`,
license: 'MIT',
dependencies: {
cac: when(cli, '^6.0.0')
cac: when(cli, '^6.0.0'),
},
devDependencies: {
xo: when(useXo, '^0.23.0'),
Expand All @@ -62,26 +59,26 @@ module.exports = (
jest: when(unitTest, '^23.6.0'),
'lint-staged': '^7.2.0',
husky: '^1.0.0-rc.13',
bili: when(compile, '^3.3.0')
bili: when(compile, '^3.3.0'),
},
jest: when(unitTest, {
testEnvironment: 'node'
testEnvironment: 'node',
}),
xo: when(useXo, {
extends: ['rem', 'plugin:prettier/recommended'],
envs: when(unitTest, ['jest'])
envs: when(unitTest, ['jest']),
}),
husky: {
hooks: {
'pre-commit': 'lint-staged'
}
'pre-commit': 'lint-staged',
},
},
'lint-staged': {
'*.js': when(useLinter, [`${eslint} --fix`, 'git add']),
[when(useLinter, '*.{json,md}', '*.{js,json,md}')]: [
'prettier --write',
'git add'
]
}
'git add',
],
},
}
}
24 changes: 9 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"type": "git"
},
"scripts": {
"test": "jest && npm run lint",
"lint": "xo *.js test/*.js"
"test": "jest",
"postinstall": "node -e \"console.log('\\u001b[35m\\u001b[1mLove undefined? You can now donate to support the author:\\u001b[22m\\u001b[39m\\n> \\u001b[36mundefined\\u001b[39m')\""
},
"jest": {
"modulePathIgnorePatterns": [
Expand All @@ -32,20 +32,14 @@
"npm",
"package"
],
"xo": {
"extends": "rem",
"envs": [
"jest"
]
},
"dependencies": {
"camelcase": "^4.0.0",
"superb": "^1.3.0"
"camelcase": "^6.0.0",
"superb": "^4.0.0"
},
"devDependencies": {
"eslint-config-rem": "^4.0.0",
"jest": "^22.4.3",
"sao": "^1.0.0",
"xo": "^0.20.3"
"@types/jest": "^26.0.5",
"jest": "^26.1.0",
"prettier": "^2.0.5",
"sao": "1.7.2-canary.145.30b2bdb.0"
}
}
}
Loading