UNPKG

@ycmd/creds

Version:

LSK.js CLI Creds is the easiest way to manage GitHub / Gitlab secrets and credentials

107 lines (105 loc) 2.95 kB
import { log } from './chunk-CHOKACPI.js'; import { GitlabService } from './chunk-DJTLL3YR.js'; import { GithubService } from './chunk-VTCDYEPL.js'; import { __name, __require } from './chunk-U2DZE3DI.js'; import { Err } from '@lsk4/err'; import { getComment, jsonToFile } from '@lskjs/stringify'; import { mapSeries } from 'fishbird'; import { unlink, mkdir } from 'fs/promises'; async function loadConfig(dirname) { const configPath = `${dirname}/config.js`; try { const res = await import(configPath); return res.default || res; } catch (err) { if (Err.getCode(err) === "ERR_MODULE_NOT_FOUND") { log.error(`${configPath} not found`); throw new Err(`${configPath} not found`); } throw err; } try { return __require(configPath); } catch (err) { console.log("require", err); if (Err.getCode(err) === "MODULE_NOT_FOUND") { log.error(`${configPath} not found`); throw new Err(`${configPath} not found`); } throw err; } } __name(loadConfig, "loadConfig"); async function build(serviceDirname, options = {}) { const log2 = options.log || log; const buildDir = options.buildDir || `${serviceDirname}/build`; const config = await loadConfig(serviceDirname); await unlink(`${buildDir}`).catch(() => { }); await mkdir(buildDir, { recursive: true }); const serviceName = config.service?.serviceName; if (!serviceName) throw new Err("!serviceName"); let service; if (serviceName === "github") { service = new GithubService({ ...config.service, ...options }); } else if (serviceName === "gitlab") { service = new GitlabService({ ...config.service, ...options }); } else { throw new Err("incorrect serviceName", { serviceName }); } const { files = [] } = config; await mapSeries(files, async (fileOptions) => { const { type, filename, handler } = fileOptions; const res = await handler(fileOptions, config); const comment = getComment({ filename, values: [ [ "Server", service.getServiceLink() ], [ "Project", service.getProjectPath() ], [ "Project ID", service.getProjectId() ], [ "Project Url", service.getProjectUrl() ], [ "CI/CD Setting", service.getProjectCICDSettingURL() ] ], footer: service.getProjectCredsUrl() && ` Auto generated by ${service.getProjectCredsUrl()} If you want to change something, please contact admin repo. `.trim() }); await jsonToFile(`${buildDir}/${filename}`, res, { type, compare: !options.force, comment }); log2.info(`[build] ${service.getProjectPath()} (${filename})`); }); } __name(build, "build"); export { build }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-PPPG2265.js.map