38 lines
1.5 KiB
TypeScript
38 lines
1.5 KiB
TypeScript
|
|
import { isArray } from '@plastichub/core/primitives'
|
|
import { sync } from '@plastichub/osr-sync/lib/sync'
|
|
import { resolve } from '@plastichub/osr-commons'
|
|
import { option } from '../library'
|
|
import { logger } from '../src'
|
|
|
|
export const register = (grunt) => {
|
|
grunt.registerMultiTask('sync', 'Synchronizes folders, using osr-sync', function () {
|
|
const done = this.async()
|
|
const task_options = this.data || {}
|
|
let source: string[] = isArray(this.data.src) ? this.data.src : [this.data.src]
|
|
const variables = { ...task_options.variables || {} }
|
|
logger.setSettings({ minLevel: option('logLevel', task_options, grunt, 'warn') })
|
|
source = source.map(f => resolve(f, false, variables))
|
|
const options = {
|
|
source,
|
|
target: resolve(option('target', task_options, grunt), variables),
|
|
root: option('root', task_options, grunt),
|
|
clear: option('clear', task_options, grunt),
|
|
debug: false,
|
|
verbose: false,
|
|
//debug: option('debug', task_options, grunt),
|
|
//verbose: option('verbose', task_options, grunt, false),
|
|
profile: option('profile', task_options, grunt),
|
|
logLevel: option('logLevel', task_options, grunt, 'warn'),
|
|
variables: variables
|
|
}
|
|
try {
|
|
sync(options)
|
|
} catch (e) {
|
|
logger.error(`Error while syncing : ${source.join('\n')} : ${e.messsage}`, e)
|
|
}
|
|
done()
|
|
return true
|
|
})
|
|
}
|