Skip to content

Commit

Permalink
fix: Error during the init process
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed May 20, 2017
1 parent eedcdf2 commit e46ddb0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 48 deletions.
85 changes: 45 additions & 40 deletions src/cli/cms/operations/initSite.js
Expand Up @@ -19,22 +19,31 @@ export default class initSite {

init(pathSite) {
var p = new Promise((resolve) => {
pathSite = pathSite.split('/')
pathSite[pathSite.length - 1] = slug(pathSite[pathSite.length - 1])
pathSite = pathSite.join('/')
this.addFolder(pathSite)
.then(() => {
process.chdir(pathSite)
this.addFolder(config.publish.url)
this.addFolder(config.structure.url)
this.addFolder(config.reference.url)
this.addFolder(config.data.url)
this.addFolder(Manager.instance.pathTemplates.replace(config.root, ''))
this.addFolder(Manager.instance.pathPartials.replace(config.root, ''))
Manager.instance.init()
.then(()=> {
Manager.instance.pathTemplates = path.join(config.root, config.themes.path, config.themes.name, config.themes.templates.path)
Manager.instance.pathPartials = path.join(config.root, config.themes.path, config.themes.name, config.themes.partials.path)
pathSite = pathSite.split('/')
pathSite[pathSite.length - 1] = slug(pathSite[pathSite.length - 1])
pathSite = pathSite.join('/')
this.addFolder(pathSite)
.then(() => {
process.chdir(pathSite)
this.addFolder(config.publish.url)
this.addFolder(config.structure.url)
this.addFolder(config.reference.url)
this.addFolder(config.data.url)
this.addFolder(Manager.instance.pathTemplates.replace(config.root + '/', ''))
this.addFolder(Manager.instance.pathPartials.replace(config.root + '/', ''))
resolve()
}).catch(function(e) {
console.error(e.stack)
resolve()
})
}).catch(function(e) {
console.error(e)
console.error(e.stack)
resolve()
})
resolve()
})

return p
Expand Down Expand Up @@ -74,8 +83,7 @@ export default class initSite {
} else {
json.users = confUsers
console.log(
clc.green('[ Hint ]'),
'creating a local config abe.json',
'Creating a local config file abe.json',
clc.cyan.underline('https://github.com/abecms/abecms/blob/master/docs/abe-config.md')
)
}
Expand All @@ -91,13 +99,9 @@ export default class initSite {
'name':'Admin'
}
}
console.log('1')
User.manager.instance.update([])
console.log('2')
var admin = User.operations.add(u)
console.log('3')
User.operations.activate(admin.user.id)
console.log('4')
}

resolve()
Expand All @@ -112,30 +116,45 @@ export default class initSite {
if(answers.which !== 'Your own template'){
console.log('installing the theme ' + answers.which)
cmsThemes.themes.downloadTheme('https://github.com/abecms/theme-'+answers.which+'/archive/master.zip', answers.which).then(function (resp) {

resolve()
}).catch(function(e) {

resolve()
})
} else {
if(answers.url.indexOf('//') > -1){
console.log('installing theme from url:' + answers.url)
resolve()
} else {
console.log('installing the theme ' + answers.url + ' from themes.abecms.io')
cmsThemes.themes.downloadTheme('https://github.com/abecms/theme-'+answers.which+'/archive/master.zip', answers.which).then(function (resp) {

resolve()
}).catch(function(e) {

resolve()
})
}
}
}

resolve()
})

return p
}

/*
{
type : 'checkbox',
name : 'plugins',
choices: [
'abecms/abe-deployer-git',
'abecms/abe-deployer-sftp',
'abecms/abe-deployer-s3',
'abecms/abe-packagz',
'abecms/abe-sitemap',
'abecms/abe-elasticsearch',
'abecms/abe-algolia'
],
message : 'Select the plugins you want to install'
}
*/
askQuestions(){
var p = new Promise((resolve) => {
inquirer.prompt([
Expand Down Expand Up @@ -216,20 +235,6 @@ export default class initSite {

return true
}
},
{
type : 'checkbox',
name : 'plugins',
choices: [
'abecms/abe-deployer-git',
'abecms/abe-deployer-sftp',
'abecms/abe-deployer-s3',
'abecms/abe-packagz',
'abecms/abe-sitemap',
'abecms/abe-elasticsearch',
'abecms/abe-algolia'
],
message : 'Select the plugins you want to install'
}
]).then(function (answers) {
resolve(answers)
Expand Down
9 changes: 3 additions & 6 deletions src/cli/cms/themes/themes.js
Expand Up @@ -10,12 +10,6 @@ import {
coreUtils
} from '../../'

export function getThemeName(url) {
var name = url.split('/')

return name[name.length - 1].replace('.zip')
}

export function getThemeInfos() {
var pathToTheme = path.join(config.root, config.themes.path, config.themes.name)

Expand Down Expand Up @@ -67,6 +61,9 @@ export function downloadTheme(url, name) {

const dirs = coreUtils.file.getFoldersSync(PathToTmpTheme, false)
const currentPathToTheme = dirs[0].path
fse.removeSync(path.join(pathToThemes, name), err => {
if (err) return console.error(err)
})
fse.renameSync(currentPathToTheme, path.join(pathToThemes, name))

fse.remove(PathToTmpTheme, err => {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Expand Up @@ -36,7 +36,7 @@ program
.then(function(){
create.updateTheme(answers)
.then(function(){
if(answers.plugins.length > 0){
if(answers.plugins && answers.plugins.length > 0){
Array.prototype.forEach.call(answers.plugins, (plugin) => {
console.log('installing the plugin: ' + plugin)

Expand All @@ -48,7 +48,7 @@ program
})
}
console.log(
clc.green('Yeahhh ! Your Abe site ' + answers.name + ' is ready to launch!'),
clc.green('Yeahhh! Your Abe site ' + answers.name + ' is ready to launch! 🚀 '),
clc.cyan('\ncd ' + answers.name + '\nabe serve -i')
)
})
Expand Down

0 comments on commit e46ddb0

Please sign in to comment.