Elliott Marquez ead86aeb8f build(catalog): node scripts to copy readmes and stories
PiperOrigin-RevId: 534960601
2023-05-24 13:27:21 -07:00

31 lines
914 B
JavaScript

/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {cp} from 'fs/promises';
import {join, parse} from 'path';
import tinyGlob from 'tiny-glob';
// Glob(s) from which to copy story files
const storyDirectories = ['../*/demo'];
const dirPromises = storyDirectories.map(async (entry) => tinyGlob(entry));
const directories = (await Promise.all(dirPromises)).flat();
const parsedDirectories = directories.map((entry) => {
// get the component name from the directory name
const componentName = parse(parse(entry).dir).base;
// set the destination to /catalog/stories/<component name>
const destination = join('.', 'stories', componentName);
console.log(`Copying ${entry} to ${destination}`);
// recursively copy the files
return cp(entry, destination, {recursive: true}, (err) => {
if (err) throw err;
});
});
await Promise.all(parsedDirectories);