build.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. const cp = require('child_process');
  2. const fs = require('fs-extra');
  3. const path = require('path');
  4. const yaml = require('js-yaml');
  5. const STAGING_DIR = path.resolve(__dirname, '..', 'config-staging');
  6. function copyAndExpand(dir = './') {
  7. const absDir = path.resolve(__dirname, dir);
  8. const targetDir = path.resolve(STAGING_DIR, dir);
  9. if (!fs.existsSync(targetDir)) {
  10. fs.mkdirSync(targetDir);
  11. }
  12. for (const file of fs.readdirSync(absDir)) {
  13. if (!file.endsWith('.yml')) {
  14. if (fs.statSync(path.resolve(absDir, file)).isDirectory()) {
  15. copyAndExpand(path.join(dir, file));
  16. }
  17. continue;
  18. }
  19. fs.writeFileSync(path.resolve(targetDir, file), yaml.dump(yaml.load(fs.readFileSync(path.resolve(absDir, file), 'utf8')), {
  20. noRefs: true,
  21. }));
  22. }
  23. }
  24. if (fs.pathExists(STAGING_DIR)) fs.removeSync(STAGING_DIR);
  25. copyAndExpand();
  26. const output = cp.spawnSync(process.env.CIRCLECI_BINARY || 'circleci', ['config', 'pack', STAGING_DIR]);
  27. fs.writeFileSync(path.resolve(STAGING_DIR, 'built.yml'), output.stdout.toString());