machines/systems/flexibot/tasks/sync.js
2025-03-11 23:32:39 +01:00

81 lines
2.3 KiB
JavaScript

var path = require('path');
// var os = require('os');
var _ = require('lodash');
const fg = require('fast-glob');
/*
const cad = require('@plastichub/osr-cad/cad/sw-lib');
const cadArgsSanitize = require('@plastichub/osr-cad/argv').sanitize;
const read = require('@plastichub/fs/read').sync;
const write = require('@plastichub/fs/write').sync;
*/
const sync = require('@plastichub/osr-sync/lib/sync').sync;
const BPromise = require('bluebird');
var isWindows = process.platform === 'win32';
const osr = path.resolve('../../osr/osr-machines/');
const files = (dir, glob) => fg.sync(glob, {
dot: true,
cwd: dir,
absolute: true
});
const GLOB_MAIN_ASSEMBLY = "cad/*Global*.+(SLDASM)";
const GLOB_OUTPUT = "${SRC_DIR}/${SRC_NAME}.+(json)";
const create_sync_args = (root, source, target, profile) => {
return {
source,
target,
debug: 'false',
verbose: 'false',
clear: 'false',
profile: profile
}
}
const createMeta = (root, product, options) => {
const src = path.resolve(`./products/${product}/`);
const target = path.resolve(`${osr}/${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 createMeta(options.cwd || '.', target, options);
}, {
concurrency: 1
});
}
module.exports = function (grunt) {
const log = grunt.verbose.writeln;
const error = grunt.log.error;
grunt.registerMultiTask('sync-osr', 'Sync to OSR', function () {
const done = this.async();
this.files.forEach(function (filePair) {
const items = filePair.orig.src.map(function (src) {
return src;
});
//log('sync items ', items);
//log('sync pair ', filePair);
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: filePair.profile || './.osr-sync.json'
}).then((e) => {
done();
});
})
});
};