#!/usr/bin/env node const { spawn } = require('child_process'); const { promisify } = require('util'); const { readdir: readdirRaw, readFile: readFileRaw, writeFile: writeFileRaw, statSync, readFileSync, } = require('fs'); const { join } = require('path'); const readdir = promisify(readdirRaw); const writeFile = promisify(writeFileRaw); const p = (l) => join(__dirname, '..', ...l); const logger = console; const exec = async (command, args = [], options = {}) => new Promise((resolve, reject) => { const child = spawn(command, args, { ...options, stdio: 'inherit', shell: true }); child .on('close', (code) => { if (code) { reject(); } else { resolve(); } }) .on('error', (e) => { logger.error(e); reject(); }); }); const getDeployables = (files) => { return files.filter((f) => { const packageJsonLocation = p(['examples', f, 'package.json']); let stats = null; try { stats = statSync(packageJsonLocation); } catch (e) { // the folder had no package.json, we'll ignore } return stats && stats.isFile() && hasBuildScript(packageJsonLocation); }); }; const hasBuildScript = (l) => { const text = readFileSync(l, 'utf8'); const json = JSON.parse(text); return !!json.scripts['build-storybook']; }; const createContent = (deployables) => { return `