/
ivanby
/
Compote
Обзор
Документация
Войти
/
ivanby
/
Compote
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
1
CI/CD
Аналитика
Безопасность
master
yaga/make.js
116 строк
4 KB
Иван Быков
Initial commit
19 июн 2026, 08:50
19 июн 2026, 08:50
b4391e5
Код
Авторство
О чём код?
#!/usr/bin/env node /* jshint evil: true */ /* */ const toolName = 'make -> '; //*** начало общий код для всех утилит const fs = require('node:fs'); const path = require('node:path'); const process = require('node:process'); const yaml = require('yaml'); let indicatorCurPos = 0; function indicator() { const indicatorChars = ['|', '/', '–', '\\']; if(indicatorCurPos < indicatorChars.length) indicatorCurPos++; if(indicatorCurPos >= indicatorChars.length) indicatorCurPos = 0; return indicatorChars[indicatorCurPos]; } const projectDir = process.cwd(); // доступен ли yaga.config.yaml const yagaConfigYamlPath = path.join( projectDir, 'yaga.config.yaml'); if (!fs.existsSync(yagaConfigYamlPath)) { console.log(toolName + '\x1b[31mПродолжение невозможно: отсутсвует yaga.config.yaml - ' + yagaConfigYamlPath + '\x1b[0m'); process.exit(1); } // читаем yaga.config.yaml let yagaConfigYaml = ''; try { yagaConfigYaml = fs.readFileSync( yagaConfigYamlPath , 'utf8'); } catch (err) { console.log(toolName + '\x1b[31mПродолжение невозможно: не могу прочитать yaga.config.yaml - ' + yagaConfigYamlPath + '\x1b[0m'); process.exit(1); } // парсим yaga.config.yaml let yagaConfig = ''; try { yagaConfig = yaml.parse(yagaConfigYaml); } catch (err) { console.log(toolName + '\x1b[31mПродолжение невозможно: не могу разобрать yaga.config.yaml - ' + yagaConfigYamlPath + '\x1b[0m'); console.log(err); process.exit(1); } // проверяем yagaConfig.target_dir if(!yagaConfig.target_dir || typeof yagaConfig.target_dir != 'string') { console.log(toolName + '\x1b[31mПродолжение невозможно: неверно указана целевая директория yagaConfig.target_dir - ' + yagaConfig.target_dir + '\x1b[0m'); process.exit(1); } const targetDirPath = path.join(projectDir, yagaConfig.target_dir); // проверяем yagaConfig.target_dir if(!fs.existsSync(targetDirPath)) { console.log(toolName + '\x1b[31mПродолжение невозможно: отсутсвует целевая директория yagaConfig.target_dir - ' + targetDirPath + '\x1b[0m'); process.exit(1); } //*** конец общий код для всех утилит // собственно код make.js // проверяем yagaConfig.make if( !yagaConfig.make || !yagaConfig.make.always || !Array.isArray(yagaConfig.make.always) || !yagaConfig.make.actions || !Array.isArray(yagaConfig.make.actions) ) { console.log(toolName + '\x1b[31mПродолжение невозможно: в ' + yagaConfigYamlPath + ' некорректно настроен ключ make\x1b[0m'); process.exit(1); } try { if(process.argv.length < 3) { let makeNoti = toolName + 'Собираю '+(yagaConfig.name? '`'+yagaConfig.name+'` ': '')+'в ' + targetDirPath; console.log(makeNoti); for(let act of yagaConfig.make.always) eval(fs.readFileSync( path.join(projectDir, 'yaga', act+'.js'), 'utf8')); for(let act of yagaConfig.make.actions) eval(fs.readFileSync( path.join(projectDir, 'yaga', act+'.js'), 'utf8')); } else { let acts = process.argv.slice(2); for(let act of yagaConfig.make.always) eval(fs.readFileSync( path.join(projectDir, 'yaga', act+'.js'), 'utf8')); for(let act of acts) eval(fs.readFileSync( path.join(projectDir, 'yaga', act+'.js'), 'utf8')); } } catch (err) { console.log(toolName + '\x1b[31mПродолжение невозможно: в ' + yagaConfigYamlPath + ' некорректно настроен ключ make или неверная команда\x1b[0m'); console.log(err); process.exit(1); } console.log(toolName + '\x1b[32mЗадачи выполнены\x1b[0m'); console.log();