UNPKG

@tangelo/tangelo-configuration-toolkit

Version:

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

80 lines (62 loc) 3.54 kB
const commands = require('./commands'); const {execSync} = require('child_process'); const fs = require('fs-extra'); const globby = require('globby'); const path = require('path'); const fdtPackage = '@fontoxml/fontoxml-development-tools'; const fdtCommand = fv => `npx -y ${fdtPackage}@${fv.replace(/^(7\.|8\.[012]\.).*/, '3.12.0')}`; module.exports = function fonto (argv) { const allowedFontoVersionRegex = (() => { const cvRegex = _settingsTdi().compatibleFontoVersions ?? _modulesTdi.require('fonto/compatibleVersions.json', {throws: false})?.regex; if (cvRegex) return RegExp(cvRegex); // old way: a regex for each basecommit is stored in global._git.commitTdi _info('Fallback to list of commits for determining compatible Fonto versions\n'); for (const fv of _git.commitTdi.fontoVersions) { if (_git.commitTdi.after(fv.commitHash)) return fv.regex; } })(); // check if FDT is not installed globally, because then it won't be possible to use specific versions with npx if (fs.pathExistsSync(path.join(_appdata.npmPath, 'node_modules', fdtPackage))) { _error(`A global installation of FDT has been found! Remove it first.\nExecute: npm r -g ${fdtPackage}`); } process.chdir(_paths.apply || '.'); // find fonto instances by searching for fonto/manifest.json files const fontoPaths = globby.sync(['**/fonto/manifest.json', 'manifest.json', `!${_paths.tdi}/**`, ..._filters.fontoSources]) .map(p => ([p.replace('manifest.json', ''), fs.readJsonSync(p).sdkVersion.replace(/Nightlies.*/, 'nightly')])) ; if (fontoPaths.length===0) _error('No Fonto instance found.'); let promiseChain = Promise.resolve(); // for sequentially executing commands for each fonto instance fontoPaths.forEach(([fontoPath, fontoVersionCurrent], i) => { promiseChain = promiseChain .then(() => { process.chdir(path.join(_paths.repo, _paths.apply, fontoPath)); if (fontoPath !== '.') _info(`${i>0 ? '\n' : ''}Fonto instance #${i+1}: ${path.join(_paths.apply, fontoPath)}\n`); // execute commands sequentially and in correct order return new Promise(resolve => { _info('Determining Fonto version:'); let fontoVersionNew = typeof argv.init == 'string' ? argv.init : fontoVersionCurrent; if (fontoVersionNew === 'latest') { const data = execSync(`${fdtCommand(fontoVersionCurrent)} editor versions`, {encoding: 'UTF-8'}); fontoVersionNew = data.match(/\d+\.\d+\.\d+/g).find(v => allowedFontoVersionRegex.test(v)); } else if (fontoVersionNew !== 'nightly' && !allowedFontoVersionRegex.test(fontoVersionNew)) { _error(`Fonto version ${fontoVersionNew} is not compatible with the current TDI submodule commit!\nExecute: ${'tct fonto --init latest'.cyan}`); } _write(fontoVersionNew+'\n'); return resolve([fdtCommand(fontoVersionNew), fontoVersionNew]); }) .then(argv.init && commands.init) .then(argv.schema && commands.schema) .then(argv.elements && commands.elements) .then(argv.attributes && commands.attributes) .then(argv.localize && commands.localize) .then(argv.build && commands.build) .then(argv.run && commands.run) ; }); }); promiseChain .catch(error => { if (error) _warn(error.message || error); }); };