Skip to content

Commit

Permalink
fix: options on serve
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorybesson committed Oct 15, 2017
1 parent 47ada41 commit a68bb7f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 53 deletions.
105 changes: 59 additions & 46 deletions src/cli/cms/templates/assets.js
Expand Up @@ -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()) {
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions src/cli/core/manager/Manager.js
Expand Up @@ -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(
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Expand Up @@ -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.'
Expand All @@ -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
}

Expand Down

0 comments on commit a68bb7f

Please sign in to comment.