1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-23 22:51:42 +00:00

fixed eslint error & integrated with prettier as well as formatted the whole codebase (#3450)

This commit is contained in:
Nguyen Viet Hung
2020-02-05 13:28:27 +13:00
committed by GitHub
parent 051ce9e208
commit 592aca1539
186 changed files with 9233 additions and 5565 deletions

View File

@@ -5,13 +5,15 @@ const packager = require('electron-packager')
const WIN = process.platform === 'win32'
module.exports = function (grunt) {
module.exports = function(grunt) {
var authCode
try {
authCode = grunt.file.readJSON('secret/auth_code.json')
} catch (e) {
if (e.origError.code === 'ENOENT') {
console.warn('secret/auth_code.json is not found. CodeSigning is not available.')
console.warn(
'secret/auth_code.json is not found. CodeSigning is not available.'
)
}
}
const OSX_COMMON_NAME = authCode != null ? authCode.OSX_COMMON_NAME : ''
@@ -41,10 +43,7 @@ module.exports = function (grunt) {
genericName: 'Boostnote',
productDescription: 'The opensource note app for developers.',
arch: 'amd64',
categories: [
'Development',
'Utility'
],
categories: ['Development', 'Utility'],
icon: path.join(__dirname, 'resources/app.png'),
bin: 'Boostnote'
},
@@ -60,10 +59,7 @@ module.exports = function (grunt) {
genericName: 'Boostnote',
productDescription: 'The opensource note app for developers.',
arch: 'x86_64',
categories: [
'Development',
'Utility'
],
categories: ['Development', 'Utility'],
icon: path.join(__dirname, 'resources/app.png'),
bin: 'Boostnote'
},
@@ -80,18 +76,21 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-electron-installer-redhat')
}
grunt.registerTask('compile', function () {
grunt.registerTask('compile', function() {
var done = this.async()
var execPath = path.join('node_modules', '.bin', 'webpack') + ' --config webpack-production.config.js'
var execPath =
path.join('node_modules', '.bin', 'webpack') +
' --config webpack-production.config.js'
grunt.log.writeln(execPath)
ChildProcess.exec(execPath,
ChildProcess.exec(
execPath,
{
env: Object.assign({}, process.env, {
BABEL_ENV: 'production',
NODE_ENV: 'production'
})
},
function (err, stdout, stderr) {
function(err, stdout, stderr) {
grunt.log.writeln(stdout)
if (err) {
@@ -105,7 +104,7 @@ module.exports = function (grunt) {
)
})
grunt.registerTask('pack', function (platform) {
grunt.registerTask('pack', function(platform) {
grunt.log.writeln(path.join(__dirname, 'dist'))
var done = this.async()
var opts = {
@@ -137,7 +136,7 @@ module.exports = function (grunt) {
InternalName: 'Boostnote'
}
})
packager(opts, function (err, appPath) {
packager(opts, function(err, appPath) {
if (err) {
grunt.log.writeln(err)
done(err)
@@ -153,7 +152,7 @@ module.exports = function (grunt) {
icon: path.join(__dirname, 'resources/app.icns'),
'app-category-type': 'public.app-category.developer-tools'
})
packager(opts, function (err, appPath) {
packager(opts, function(err, appPath) {
if (err) {
grunt.log.writeln(err)
done(err)
@@ -168,7 +167,7 @@ module.exports = function (grunt) {
icon: path.join(__dirname, 'resources/app.icns'),
'app-category-type': 'public.app-category.developer-tools'
})
packager(opts, function (err, appPath) {
packager(opts, function(err, appPath) {
if (err) {
grunt.log.writeln(err)
done(err)
@@ -180,15 +179,16 @@ module.exports = function (grunt) {
}
})
grunt.registerTask('codesign', function (platform) {
grunt.registerTask('codesign', function(platform) {
var done = this.async()
if (process.platform !== 'darwin') {
done(false)
return
}
ChildProcess.exec(`codesign --verbose --deep --force --sign \"${OSX_COMMON_NAME}\" dist/Boostnote-darwin-x64/Boostnote.app`,
function (err, stdout, stderr) {
ChildProcess.exec(
`codesign --verbose --deep --force --sign \"${OSX_COMMON_NAME}\" dist/Boostnote-darwin-x64/Boostnote.app`,
function(err, stdout, stderr) {
grunt.log.writeln(stdout)
if (err) {
grunt.log.writeln(err)
@@ -197,44 +197,43 @@ module.exports = function (grunt) {
return
}
done()
})
}
)
})
grunt.registerTask('create-osx-installer', function () {
grunt.registerTask('create-osx-installer', function() {
var done = this.async()
var execPath = 'appdmg appdmg.json dist/Boostnote-mac.dmg'
grunt.log.writeln(execPath)
ChildProcess.exec(execPath,
function (err, stdout, stderr) {
grunt.log.writeln(stdout)
if (err) {
grunt.log.writeln(err)
grunt.log.writeln(stderr)
done(false)
return
}
done()
})
ChildProcess.exec(execPath, function(err, stdout, stderr) {
grunt.log.writeln(stdout)
if (err) {
grunt.log.writeln(err)
grunt.log.writeln(stderr)
done(false)
return
}
done()
})
})
grunt.registerTask('zip', function (platform) {
grunt.registerTask('zip', function(platform) {
var done = this.async()
switch (platform) {
case 'osx':
var execPath = 'cd dist/Boostnote-darwin-x64 && zip -r -y -q ../Boostnote-mac.zip Boostnote.app'
var execPath =
'cd dist/Boostnote-darwin-x64 && zip -r -y -q ../Boostnote-mac.zip Boostnote.app'
grunt.log.writeln(execPath)
ChildProcess.exec(execPath,
function (err, stdout, stderr) {
grunt.log.writeln(stdout)
if (err) {
grunt.log.writeln(err)
grunt.log.writeln(stderr)
done(false)
return
}
done()
ChildProcess.exec(execPath, function(err, stdout, stderr) {
grunt.log.writeln(stdout)
if (err) {
grunt.log.writeln(err)
grunt.log.writeln(stderr)
done(false)
return
}
)
done()
})
break
default:
done()
@@ -242,7 +241,7 @@ module.exports = function (grunt) {
}
})
function getTarget () {
function getTarget() {
switch (process.platform) {
case 'darwin':
return 'osx'
@@ -255,7 +254,7 @@ module.exports = function (grunt) {
}
}
grunt.registerTask('build', function (platform) {
grunt.registerTask('build', function(platform) {
if (platform == null) platform = getTarget()
switch (platform) {
@@ -263,15 +262,26 @@ module.exports = function (grunt) {
grunt.task.run(['compile', 'pack:win', 'create-windows-installer'])
break
case 'osx':
grunt.task.run(['compile', 'pack:osx', 'codesign', 'create-osx-installer', 'zip:osx'])
grunt.task.run([
'compile',
'pack:osx',
'codesign',
'create-osx-installer',
'zip:osx'
])
break
case 'linux':
grunt.task.run(['compile', 'pack:linux', 'electron-installer-debian', 'electron-installer-redhat'])
grunt.task.run([
'compile',
'pack:linux',
'electron-installer-debian',
'electron-installer-redhat'
])
break
}
})
grunt.registerTask('pre-build', function (platform) {
grunt.registerTask('pre-build', function(platform) {
if (platform == null) platform = getTarget()
switch (platform) {
@@ -286,11 +296,11 @@ module.exports = function (grunt) {
}
})
grunt.registerTask('bfm', function () {
grunt.registerTask('bfm', function() {
const Color = require('color')
const parseCSS = require('css').parse
function generateRule (selector, bgColor, fgColor) {
function generateRule(selector, bgColor, fgColor) {
if (bgColor.isLight()) {
bgColor = bgColor.mix(fgColor, 0.05)
} else {
@@ -298,48 +308,79 @@ module.exports = function (grunt) {
}
if (selector && selector.length > 0) {
return `${selector} .cm-table-row-even { background-color: ${bgColor.rgb().string()}; }`
return `${selector} .cm-table-row-even { background-color: ${bgColor
.rgb()
.string()}; }`
} else {
return `.cm-table-row-even { background-color: ${bgColor.rgb().string()}; }`
return `.cm-table-row-even { background-color: ${bgColor
.rgb()
.string()}; }`
}
}
const root = path.join(__dirname, 'node_modules/codemirror/theme/')
const colors = fs.readdirSync(root).filter(file => file !== 'solarized.css').map(file => {
const css = parseCSS(fs.readFileSync(path.join(root, file), 'utf8'))
const colors = fs
.readdirSync(root)
.filter(file => file !== 'solarized.css')
.map(file => {
const css = parseCSS(fs.readFileSync(path.join(root, file), 'utf8'))
const rules = css.stylesheet.rules.filter(rule => rule.selectors && /\b\.CodeMirror$/.test(rule.selectors[0]))
if (rules.length === 1) {
let bgColor = Color('white')
let fgColor = Color('black')
const rules = css.stylesheet.rules.filter(
rule => rule.selectors && /\b\.CodeMirror$/.test(rule.selectors[0])
)
if (rules.length === 1) {
let bgColor = Color('white')
let fgColor = Color('black')
rules[0].declarations.forEach(declaration => {
if (declaration.property === 'background-color' || declaration.property === 'background') {
bgColor = Color(declaration.value.split(' ')[0])
} else if (declaration.property === 'color') {
const value = /^(.*?)(?:\s*!important)?$/.exec(declaration.value)[1]
const match = /^rgba\((.*?),\s*1\)$/.exec(value)
if (match) {
fgColor = Color(`rgb(${match[1]})`)
} else {
fgColor = Color(value)
rules[0].declarations.forEach(declaration => {
if (
declaration.property === 'background-color' ||
declaration.property === 'background'
) {
bgColor = Color(declaration.value.split(' ')[0])
} else if (declaration.property === 'color') {
const value = /^(.*?)(?:\s*!important)?$/.exec(
declaration.value
)[1]
const match = /^rgba\((.*?),\s*1\)$/.exec(value)
if (match) {
fgColor = Color(`rgb(${match[1]})`)
} else {
fgColor = Color(value)
}
}
}
})
})
return generateRule(rules[0].selectors[0], bgColor, fgColor)
}
}).filter(value => !!value)
return generateRule(rules[0].selectors[0], bgColor, fgColor)
}
})
.filter(value => !!value)
// default
colors.unshift(generateRule(null, Color('white'), Color('black')))
// solarized dark
colors.push(generateRule('.cm-s-solarized.cm-s-dark', Color('#002b36'), Color('#839496')))
colors.push(
generateRule(
'.cm-s-solarized.cm-s-dark',
Color('#002b36'),
Color('#839496')
)
)
// solarized light
colors.push(generateRule('.cm-s-solarized.cm-s-light', Color('#fdf6e3'), Color('#657b83')))
colors.push(
generateRule(
'.cm-s-solarized.cm-s-light',
Color('#fdf6e3'),
Color('#657b83')
)
)
fs.writeFileSync(path.join(__dirname, 'extra_scripts/codemirror/mode/bfm/bfm.css'), colors.join('\n'), 'utf8')
fs.writeFileSync(
path.join(__dirname, 'extra_scripts/codemirror/mode/bfm/bfm.css'),
colors.join('\n'),
'utf8'
)
})
grunt.registerTask('default', ['build'])