@tangelo/tangelo-configuration-toolkit
Version:
Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.
89 lines (74 loc) • 3.74 kB
JavaScript
const globby = require('globby');
const inquirer = require('inquirer');
const path = require('path');
const TclConfig = require('../../lib/tcl-config');
module.exports = function migrate (argv) {
if (_isPre51()) _error('This command only works when using branch release/5.1 and up.');
const scripts =
globby
.sync(_paths.tdi + '/tct/migrate/*.js')
.map(s => s.match(/([^/]+)$/)[1].replace('.js', ''))
.sort((a, b) => {
const aRelease = /^\d+-\d+/.test(a), bRelease = /^\d+-\d+/.test(b);
if (aRelease && bRelease) return a > b ? -1 : 1;
if (aRelease) return -1;
if (bRelease) return 1;
return a > b ? 1 : -1;
})
.map(s => ({
name: s.replace(/(\d+)-(\d+)-?(.*)/, (m, p1, p2, p3) => `${p1} -> ${p2}${p3 ? ` (${p3})` : ''}`),
value: s
}))
;
// Search scriptname set in commandline in scripts and return in cmdlScript if found
const cmdlScript = Object.values(scripts).filter(s => s.name === `${argv.execute}`)[0];
if (cmdlScript) {
_info(`Migration: ${cmdlScript.name}`);
}
inquirer
.prompt([{
message: 'Choose a migration: ', name: 'script', type: 'list', choices: scripts, pageSize: 5, loop: false,
when: !(cmdlScript) // Only show choice for migration when no script is set in commandline
}, {
message: 'Choose filter: ', name: 'filter', type: 'list', pageSize: 5, loop: false,
choices: [{name: `- All`, value: '**'}, {name: '- Choose active projects', value: 'projects'}],
when: !argv.filter // Only show this message if no custom filter was added to the command argument -f
}, {
message: 'Choose active projects: ', name: 'projects', type: 'checkbox', validate: v => !!v[0],
choices: _repoconfig.map(p => ({name: `${p.customer_name} ${p.project_name}`, value: p})),
when: a => a.filter === 'projects' // Only show this message if 'Choose active projects' was chosen previously
}])
.then(a => {
_write();
_info(`Working folder set to: ${_paths.repo}`);
if (cmdlScript) {
// Set script to execute to script entered in commandline
a.script = cmdlScript.value;
}
let filter = path.join(_paths.apply, argv.filter??'**').toFws; // Default set filter with filter added to the command argument -f
if (a.filter === 'projects' && _repoconfig.length > a.projects.length) {
// push paths of chosen active documents to projectFolders (only if not all projects are chosen)
const projectFolders = [];
a.projects.forEach(p => {
projectFolders.push(p.path_dbconfig ? p.path_dbconfig.join('/') : (_repoconfig.customer.dirname+'/'+p.dirname));
// push cmscustom path if it differs from dbconfig path
if (p.path_dbconfig.join('/') != p.path_cmscustom.join('/')) projectFolders.push(p.path_cmscustom.join('/'));
});
// Set filter to chosen active documents
filter = projectFolders.length === 1 ? `**/${projectFolders}/**` : `**/{${projectFolders.join(',')}}/**`;
}
_info(`Filter applied: ${filter}`);
_write();
inquirer
.prompt([{message: 'Continue?', name: 'confirm', type: 'confirm'}])
.then(({confirm}) => {
if (!confirm) return;
_write();
const startTime = new Date();
const projectsWithType = TclConfig.findProjects();
const scriptPath = path.join('migrate', a.script);
_modulesTdi.require(scriptPath).forEach(step => require('./steps')(step, argv.dry, filter, projectsWithType));
_perf(startTime);
});
});
};