Skip to content

Commit

Permalink
ic: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 8, 2017
1 parent e59fb56 commit 3f83729
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 115 deletions.
6 changes: 3 additions & 3 deletions src/cli/cms/data/attributes.js
Expand Up @@ -79,14 +79,14 @@ export function sanitizeSourceAttribute(obj, jsonPage) {
export function getAttrValuefromKey(template, key, attr, json) {
var value = null
var abeTags = cmsData.regex.getTagAbeWithKey(template, key)
if (abeTags.length > 0){
if (abeTags.length > 0) {
var attr = cmsData.regex.getAttr(abeTags[0], attr)
if(attr !== ''){
if (attr !== '') {
value = cmsData.attributes.getValueFromAttribute(attr, json)
}
}

return value
return value
}
/**
* This function will take the value of an Abe attribute and analyze its content.
Expand Down
5 changes: 4 additions & 1 deletion src/cli/cms/data/file.js
Expand Up @@ -16,7 +16,10 @@ export function getAbeMeta(fileObject, json) {
if (json.abe_meta.updatedDate != null) {
fileObject.date = json.abe_meta.updatedDate
date = json.abe_meta.updatedDate
} else if (json.abe_meta.latest != null && json.abe_meta.latest.date != null) {
} else if (
json.abe_meta.latest != null &&
json.abe_meta.latest.date != null
) {
fileObject.date = json.abe_meta.latest.date
date = json.abe_meta.latest.date
} else if (json.abe_meta.date !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/data/revision.js
Expand Up @@ -14,7 +14,7 @@ export function getVersions(docPath) {
config.data.url,
docPath.replace('.' + config.files.templates.extension, '.json')
)
if(files != null){
if (files != null) {
Array.prototype.forEach.call(files, file => {
if (file.path.indexOf(dataFile) > -1) {
result = file.revisions
Expand Down
3 changes: 1 addition & 2 deletions src/cli/cms/editor/handlebars/compileAbe.js
Expand Up @@ -28,8 +28,7 @@ export default function compileAbe() {
try {
value = content
? eval(
`content["${hash.dictionnary}"][${arguments[0].data
.index}].${key}`
`content["${hash.dictionnary}"][${arguments[0].data.index}].${key}`
)
: hash.key
// value = content ? content[hash['dictionnary']][arguments[0].data.index][key] : hash.key
Expand Down
56 changes: 35 additions & 21 deletions src/cli/cms/operations/initSite.js
Expand Up @@ -189,13 +189,19 @@ export default class initSite {
{
type: 'confirm',
name: 'deploy',
message: 'Do you want to publish your amazing contributions on Internet',
message:
'Do you want to publish your amazing contributions on Internet',
default: false
},
{
type: 'list',
name: 'which',
choices: ['on surge (it\'s free !)', 'a github repository', 'a S3 bucket', 'via (S)FTP'],
choices: [
"on surge (it's free !)",
'a github repository',
'a S3 bucket',
'via (S)FTP'
],
message: 'Please select a deployment method',
default: 0,
when: function(answers) {
Expand All @@ -205,17 +211,18 @@ export default class initSite {
{
type: 'input',
name: 'domain',
message: 'Please enter a domain (either your own domain or a domain.surge.sh)',
message:
'Please enter a domain (either your own domain or a domain.surge.sh)',
when: function(answers) {
return (answers.which === 'on surge (it\'s free !)')
return answers.which === "on surge (it's free !)"
}
},
{
type: 'input',
name: 'repository',
message: 'Please enter the github repository',
when: function(answers) {
return (answers.which === 'a github repository')
return answers.which === 'a github repository'
}
},
{
Expand All @@ -224,23 +231,23 @@ export default class initSite {
message: 'Please enter the github branch',
default: 'master',
when: function(answers) {
return (answers.which === 'a github repository')
return answers.which === 'a github repository'
}
},
{
type: 'input',
name: 'username',
message: 'Please enter the github username',
when: function(answers) {
return (answers.which === 'a github repository')
return answers.which === 'a github repository'
}
},
{
type: 'input',
name: 'email',
message: 'Please enter the github email',
when: function(answers) {
return (answers.which === 'a github repository')
return answers.which === 'a github repository'
}
},
{
Expand All @@ -249,39 +256,39 @@ export default class initSite {
message: 'Please enter the S3 region',
default: 'eu-central-1',
when: function(answers) {
return (answers.which === 'a S3 bucket')
return answers.which === 'a S3 bucket'
}
},
{
type: 'input',
name: 'accessKeyId',
message: 'Please enter the S3 accessKeyId',
when: function(answers) {
return (answers.which === 'a S3 bucket')
return answers.which === 'a S3 bucket'
}
},
{
type: 'input',
name: 'secretAccessKey',
message: 'Please enter the S3 secretAccessKey',
when: function(answers) {
return (answers.which === 'a S3 bucket')
return answers.which === 'a S3 bucket'
}
},
{
type: 'input',
name: 'bucket',
message: 'Please enter the S3 bucket',
when: function(answers) {
return (answers.which === 'a S3 bucket')
return answers.which === 'a S3 bucket'
}
},
{
type: 'input',
name: 'prefix',
message: 'Please enter the S3 prefix',
when: function(answers) {
return (answers.which === 'a S3 bucket')
return answers.which === 'a S3 bucket'
}
},
{
Expand All @@ -291,23 +298,23 @@ export default class initSite {
message: 'Please select the protocol',
default: 0,
when: function(answers) {
return (answers.which === 'via (S)FTP')
return answers.which === 'via (S)FTP'
}
},
{
type: 'input',
name: 'host',
message: 'Please enter the host',
when: function(answers) {
return (answers.which === 'via (S)FTP')
return answers.which === 'via (S)FTP'
}
},
{
type: 'input',
name: 'remoteDir',
message: 'Please enter the remote directory',
when: function(answers) {
return (answers.which === 'via (S)FTP')
return answers.which === 'via (S)FTP'
}
},
{
Expand All @@ -317,31 +324,38 @@ export default class initSite {
message: 'Please select the authentication type',
default: 1,
when: function(answers) {
return (answers.which === 'via (S)FTP')
return answers.which === 'via (S)FTP'
}
},
{
type: 'input',
name: 'username',
message: 'Please enter the username',
when: function(answers) {
return (answers.which === 'via (S)FTP')
return answers.which === 'via (S)FTP'
}
},
{
type: 'input',
name: 'password',
message: 'Please enter the password',
when: function(answers) {
return (answers.which === 'via (S)FTP' && answers.requiresType === 'It requires a password')
return (
answers.which === 'via (S)FTP' &&
answers.requiresType === 'It requires a password'
)
}
},
{
type: 'input',
name: 'sshKeyPath',
message: 'Please enter the ssh KeyPath on your computer (/path/to/id_rsa_pub)',
message:
'Please enter the ssh KeyPath on your computer (/path/to/id_rsa_pub)',
when: function(answers) {
return (answers.which === 'via (S)FTP' && answers.requiresType === 'It requires a SSH key')
return (
answers.which === 'via (S)FTP' &&
answers.requiresType === 'It requires a SSH key'
)
}
}
])
Expand Down
6 changes: 4 additions & 2 deletions src/cli/cms/templates/assets.js
Expand Up @@ -21,7 +21,9 @@ export function copy() {

directory = fse.lstatSync(dest)
if (directory.isSymbolicLink()) dest = fse.readlinkSync(dest)
var res = dircompare.compareSync(Manager.instance.pathTemplates, dest, {compareDate: true})
var res = dircompare.compareSync(Manager.instance.pathTemplates, dest, {
compareDate: true
})

res.diffSet.forEach(function(entry) {
var state = {
Expand All @@ -34,7 +36,7 @@ export function copy() {
var name1 = entry.name1 ? entry.name1 : ''
var name2 = entry.name2 ? entry.name2 : ''

let exclude = new RegExp("\."+config.files.templates.extension+"$")
let exclude = new RegExp('.' + config.files.templates.extension + '$')
if (
!exclude.test(name1) &&
!exclude.test(name2) &&
Expand Down
2 changes: 1 addition & 1 deletion src/cli/cms/templates/prepare.js
Expand Up @@ -98,7 +98,7 @@ export function addAbeDataAttrForHtmlTag(template) {

// Is this function useful ? What is it used for ?
export function addHasAbeAttr(text) {
return text.replace('}}', ' has-abe=\'1\'}}')
return text.replace('}}', " has-abe='1'}}")
}

export function getAbeAttributeData(match, text, htmlAttribute, abeTag) {
Expand Down
55 changes: 27 additions & 28 deletions src/cli/core/manager/Manager.js
Expand Up @@ -40,7 +40,7 @@ class Manager {
// Compatibility for abe version < 3.2.
// It's possible to reference html from any directory
if (process.env.ABE_TEMPLATES_PATH) {
if(process.env.ABE_TEMPLATES_PATH.charAt(0) === '/'){
if (process.env.ABE_TEMPLATES_PATH.charAt(0) === '/') {
this.pathTemplates = process.env.ABE_TEMPLATES_PATH
} else {
this.pathTemplates = path.join(
Expand Down Expand Up @@ -141,8 +141,8 @@ class Manager {
console.error(
clc.red("can't start the Abe's watch server\n"),
'This watch server has tried to listen on the port ' +
lport +
' but this server is already in use by another process... '
lport +
' but this server is already in use by another process... '
)
} else {
console.error(err)
Expand All @@ -155,15 +155,17 @@ class Manager {
console.log('SIGINT:Livereload server has been gracefully terminated')
process.exit(0)
})
} catch(error){}
} catch (error) {}
})
process.on('SIGTERM', () => {
try {
this.lserver.close(() => {
console.log('SIGTERM:Livereload server has been gracefully terminated')
console.log(
'SIGTERM:Livereload server has been gracefully terminated'
)
process.exit(0)
})
} catch(error){}
} catch (error) {}
})

// sync assets from templates to /site
Expand Down Expand Up @@ -264,23 +266,23 @@ class Manager {
this._watchPartialsFolder = watch.createMonitor(
this.pathPartials,
monitor => {
monitor.on('created', (f) => {
monitor.on('created', f => {
this.getKeysFromSelect()
this.updateStructureAndTemplates()
if (typeof this.lserver != 'undefined') {
tinylr.changed(f)
}
this.events.template.emit('update')
})
monitor.on('changed', (f) => {
monitor.on('changed', f => {
this.getKeysFromSelect()
this.updateStructureAndTemplates()
if (typeof this.lserver != 'undefined') {
tinylr.changed(f)
}
this.events.template.emit('update')
})
monitor.on('removed', (f) => {
monitor.on('removed', f => {
this.getKeysFromSelect()
this.updateStructureAndTemplates()
if (typeof this.lserver != 'undefined') {
Expand Down Expand Up @@ -336,7 +338,7 @@ class Manager {
}
this.events.reference.emit('update')
})
monitor.on('removed', (f) => {
monitor.on('removed', f => {
this.updateReferences()
if (typeof this.lserver != 'undefined') {
tinylr.changed(f)
Expand Down Expand Up @@ -368,7 +370,7 @@ class Manager {
}
this.events.locales.emit('update')
})
monitor.on('removed', (f) => {
monitor.on('removed', f => {
coreUtils.locales.instance.reloadLocales()
if (typeof this.lserver != 'undefined') {
tinylr.changed(f)
Expand All @@ -383,23 +385,20 @@ class Manager {

try {
fse.accessSync(this.pathScripts, fse.F_OK)
this._watchScripts = watch.createMonitor(
this.pathScripts,
monitor => {
monitor.on('created', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
monitor.on('changed', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
monitor.on('removed', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
}
)
this._watchScripts = watch.createMonitor(this.pathScripts, monitor => {
monitor.on('created', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
monitor.on('changed', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
monitor.on('removed', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
})
} catch (e) {
console.log('the directory ' + this.pathScripts + ' does not exist')
}
Expand Down

0 comments on commit 3f83729

Please sign in to comment.