UNPKG

@tangelo/tangelo-configuration-toolkit

Version:

Tangelo Configuration Toolkit is a command-line toolkit which offers support for developing a Tangelo configuration.

80 lines (69 loc) 3.27 kB
const fs = require('fs-extra'); const globby = require('globby'); const inquirer = require('inquirer'); const oxygen = require('./oxygen'); const path = require('path'); const createSymlink = (t, p) => { const up = p.replace(/[^/]+/g, '..').replace(/^..\//, ''); fs.symlink(path.join(up, _paths.tdi, t), p, 'dir', err => { if (err) { if (err.code==='EEXIST') _write(`Symlink already exists: ${p}`); else _error((err.code!=='EPERM' ? err : `Can't create symlinks, restart your console as admin, or fix it permanently:\n 1. Open 'Local Security Policy' (secpol.msc)\n 2. Go to 'Security Settings > Local Policies > User Rights Assignment > Create symbolic links'\n 3. Add your own account\n 4. Restart Windows`)); } else _write(`Symlink created: ${p}`); }); }; const createSymlinks = () => { _info('Creating symlinks:'); const src = _isPre51() ? 'sources' : 'src'; createSymlink(src + '/config/cmscustom/tdi', 'config/cmscustom/tdi'); globby .sync('config/cmscustom/!(tdi)/**/fonto') .forEach(p => { const tdiCodebasePath = _settingsTdi().codebase === 'dual' && fs.existsSync(path.join(p, '../project.tcl')) ? '/tcl' : _settingsTdi().codebase === 'dual' ? '/traditional' : '' ; createSymlink(src + `/config/cmscustom/tdi${tdiCodebasePath}/fonto/packages-shared`, p + '/packages-shared'); }); }; module.exports = function build (argv) { if ((argv.init || argv.project) && _isPre51()) _error('This option only works when using branch release/5.1 and up.'); const predefinedAnswers = argv.file ? _appconfig.build?.[argv.file] : undefined; // if not chosen to use predefined values by passing "file", erase the "build" property for old TDI commits _appconfig.build = predefinedAnswers; if (argv.init) _modulesTdi.require('build/init')(createSymlinks, predefinedAnswers); if (argv.project && argv.file) _modulesTdi.require('build/project').projectNew(createSymlinks, _repoconfig[0], predefinedAnswers); else if (argv.project) { inquirer .prompt([{ message: 'Create project: ', name: 'project', type: 'list', choices: [ {name: 'New from TDI submodule', value: 'TDI'}, ...( _repoconfig.projects ? (_repoconfig.projects || []).map(p => ({name: 'Copy of ' + p.name, value: p})) // when using repoconfig file (old) : (_repoconfig || []).map(p => ({name: `Copy of ${p.customer_name} ${p.project_name}`, value: p})) ) ] }]) .then(a => { if (a.project === 'TDI') _modulesTdi.require('build/project').projectNew(createSymlinks, _repoconfig[0]); else _modulesTdi.require('build/project').projectCopy(createSymlinks, a.project); }); } if (argv.symlinks) { const symlinks = globby.sync(['config/cmscustom/tdi', 'config/cmscustom/!(tdi)/**/fonto//packages-shared']); if (symlinks[0]) { _info('Removing symlinks:'); symlinks.forEach(s => { fs.removeSync(s); _write('Symlink removed: ' + s); }); _write(); } createSymlinks(); } if (argv.oxygen) oxygen(argv.oxygen); };