From e46ddb029315c8ebe9ad2642602da51f4b3191c8 Mon Sep 17 00:00:00 2001 From: gregorybesson Date: Sat, 20 May 2017 08:15:30 +0200 Subject: [PATCH] fix: Error during the init process --- src/cli/cms/operations/initSite.js | 85 ++++++++++++++++-------------- src/cli/cms/themes/themes.js | 9 ++-- src/index.js | 4 +- 3 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/cli/cms/operations/initSite.js b/src/cli/cms/operations/initSite.js index fcc6dc90..8a11aafb 100755 --- a/src/cli/cms/operations/initSite.js +++ b/src/cli/cms/operations/initSite.js @@ -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 @@ -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') ) } @@ -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() @@ -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([ @@ -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) diff --git a/src/cli/cms/themes/themes.js b/src/cli/cms/themes/themes.js index 93c801c0..c713efe4 100644 --- a/src/cli/cms/themes/themes.js +++ b/src/cli/cms/themes/themes.js @@ -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) @@ -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 => { diff --git a/src/index.js b/src/index.js index 426ede25..525c47c1 100755 --- a/src/index.js +++ b/src/index.js @@ -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) @@ -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') ) })