var path = require('path'); var _ = require('lodash'); const fg = require('fast-glob'); const _resolve = require('@plastichub/osr-cli-commons/fs').resolve; const sync = require('@plastichub/osr-sync/lib/sync').sync; const BPromise = require('bluebird'); const osr = path.resolve('../pp-next2/machines/'); const files = (dir, glob) => fg.sync(glob, { dot: true, cwd: dir, absolute: true }); const create_sync_args = (root, source, target, profile) => { return { source, target, debug: 'false', verbose: 'false', clear: 'false', profile: profile } } const syncItem = (root, product, options) => { const src = path.resolve(`./products/${product}/`); const target = path.resolve(`${options.dst}/users/plastichub/products/${product}/`); const args = create_sync_args(root, src, target, options.profile); console.log(root, product, options, args); return sync(args); } const convert = async (items, options) => { return BPromise.resolve(items).map((target) => { return syncItem(options.cwd || '.', target, options); }, { concurrency: 1 }); } module.exports = function (grunt) { const log = grunt.verbose.writeln; const error = grunt.log.error; grunt.registerMultiTask('sync-osr-assets', 'Sync to OSR', function () { const done = this.async(); this.files.forEach(function (filePair) { const items = filePair.orig.src.map(function (src) { return src; }); convert(items, { verbose: grunt.option('verbose') !== undefined ? grunt.option('verbose') : false, skip: grunt.option('skip') !== undefined ? grunt.option('skip') : true, cwd: grunt.option('cwd'), profile: path.resolve(filePair.profile), dst: _resolve(filePair.dst) }).then((e) => { done(); }); }) }); };