From a68bb7f594f407ffa3b243aa2964157e982b941e Mon Sep 17 00:00:00 2001 From: gregorybesson Date: Sat, 14 Oct 2017 18:37:26 -0700 Subject: [PATCH] fix: options on serve --- src/cli/cms/templates/assets.js | 105 ++++++++++++++++++-------------- src/cli/core/manager/Manager.js | 1 + src/index.js | 14 ++--- 3 files changed, 67 insertions(+), 53 deletions(-) diff --git a/src/cli/cms/templates/assets.js b/src/cli/cms/templates/assets.js index a4e69994..f26c6e4e 100644 --- a/src/cli/cms/templates/assets.js +++ b/src/cli/cms/templates/assets.js @@ -10,6 +10,7 @@ import {coreUtils, cmsTemplates, config, Manager} from '../../' export function copy() { let dest = Manager.instance.pathPublish let directory = null + let source = Manager.instance.pathAssets try { directory = fse.lstatSync(dest) if (!directory.isDirectory() && !directory.isSymbolicLink()) { @@ -19,63 +20,75 @@ export function copy() { mkdirp.sync(dest) } + try { + dirSource = fse.lstatSync(source) + if (!dirSource.isDirectory() && !dirSource.isSymbolicLink()) { + source = null + } + } catch (e) { + source = null + } + directory = fse.lstatSync(dest) if (directory.isSymbolicLink()) dest = fse.readlinkSync(dest) - var res = dircompare.compareSync(Manager.instance.pathAssets, dest, { - compareDate: true - }) - res.diffSet.forEach(function(entry) { - var state = { - equal: '==', - left: '->', - right: '<-', - distinct: '<>' - }[entry.state] + if(source != null){ + var res = dircompare.compareSync(source, dest, { + compareDate: true + }) + + res.diffSet.forEach(function(entry) { + var state = { + equal: '==', + left: '->', + right: '<-', + distinct: '<>' + }[entry.state] - var name1 = entry.name1 ? entry.name1 : '' - var name2 = entry.name2 ? entry.name2 : '' + var name1 = entry.name1 ? entry.name1 : '' + var name2 = entry.name2 ? entry.name2 : '' - let exclude = new RegExp(`.${config.files.templates.extension}$`) - if ( - !exclude.test(name1) && - !exclude.test(name2) && - entry.type1 !== 'directory' && - entry.type2 !== 'directory' - ) { - if (typeof entry.path1 !== 'undefined' && entry.path1 !== null) { - var original = entry.path1 - var basePath = original.replace(Manager.instance.pathAssets, '') - var move = path.join(dest, basePath) + let exclude = new RegExp(`.${config.files.templates.extension}$`) + if ( + !exclude.test(name1) && + !exclude.test(name2) && + entry.type1 !== 'directory' && + entry.type2 !== 'directory' + ) { + if (typeof entry.path1 !== 'undefined' && entry.path1 !== null) { + var original = entry.path1 + var basePath = original.replace(Manager.instance.pathAssets, '') + var move = path.join(dest, basePath) - if (move === dest) { - fse.readdir(original, function(res, items) { - Array.prototype.forEach.call(items, item => { - var originalItem = path.join(original, item) - var lstat = fse.lstatSync(originalItem) - var destItem = path.join(dest, item) + if (move === dest) { + fse.readdir(original, function(res, items) { + Array.prototype.forEach.call(items, item => { + var originalItem = path.join(original, item) + var lstat = fse.lstatSync(originalItem) + var destItem = path.join(dest, item) - if (!lstat.isDirectory() && !exclude.test(originalItem)) { - try { - fsCompare(modifiedTime, originalItem, destItem, function( - err, - diff - ) { - if (diff > 0) fse.copySync(originalItem, destItem) - }) - } catch (e) { - fse.copySync(originalItem, destItem) + if (!lstat.isDirectory() && !exclude.test(originalItem)) { + try { + fsCompare(modifiedTime, originalItem, destItem, function( + err, + diff + ) { + if (diff > 0) fse.copySync(originalItem, destItem) + }) + } catch (e) { + fse.copySync(originalItem, destItem) + } } - } + }) }) - }) - } else if (entry.type2 === 'missing' || entry.state === 'distinct') { - fse.removeSync(move) - fse.copySync(original, move) + } else if (entry.type2 === 'missing' || entry.state === 'distinct') { + fse.removeSync(move) + fse.copySync(original, move) + } } } - } - }) + }) + } return true } diff --git a/src/cli/core/manager/Manager.js b/src/cli/core/manager/Manager.js index 8de71dd7..4bb49e3a 100644 --- a/src/cli/core/manager/Manager.js +++ b/src/cli/core/manager/Manager.js @@ -44,6 +44,7 @@ class Manager { config.root, process.env.ABE_TEMPLATES_PATH ) + this.pathPartials = this.pathTemplates } else if ( config.themes != null && coreUtils.file.exist( diff --git a/src/index.js b/src/index.js index 9791bdda..70b2e274 100755 --- a/src/index.js +++ b/src/index.js @@ -257,9 +257,9 @@ program ) .option('-p, --port [number]', 'change port of the web server') .option('-i, --interactive', 'open browser on web server startup') - .option('-t, --templates', 'give an absolute or relative path to your templates') - .option('-a, --assets', 'give an absolute or relative path to your assets') - .option('-d, --destination', 'give an absolute or relative path to your destination directory') + .option('-t, --templates [path]', 'give an absolute or relative path to your templates') + .option('-a, --assets [path]', 'give an absolute or relative path to your assets') + .option('-d, --destination [path]', 'give an absolute or relative path to your destination directory') .option( '-e, --env [development|production|...]', 'Abe is launched in development mode by default. Use another value to deactivate development mode. You may also use a global env variable NODE_ENV.' @@ -286,19 +286,19 @@ program } } - if (options.port != null) { + if (typeof options.port != 'undefined') { environment.PORT = options.port } - if (options.templates != null) { + if (typeof options.templates != 'undefined') { environment.ABE_TEMPLATES_PATH = options.templates } - if (options.assets != null) { + if (typeof options.assets != 'undefined') { environment.ABE_ASSETS_PATH = options.assets } - if (options.destination != null) { + if (typeof options.destination != 'undefined') { environment.ABE_DESTINATION_PATH = options.destination }