import { promises as fs, readFileSync } from 'fs'; import { posix } from 'path'; import arg from 'arg'; import glob from 'globby'; import tar from 'tar'; const { resolve, dirname, sep, join } = posix; /** @type {import('arg').Spec} */ const spec = { '--tgz': Boolean, }; export default async function copy() { let { _: patterns, ['--tgz']: isCompress } = arg(spec); patterns = patterns.slice(1); if (isCompress) { const files = await glob(patterns, { gitignore: true }); const rootDir = resolveRootDir(files); const destDir = rootDir.replace(/^[^/]+/, 'dist'); const templates = files.reduce((acc, curr) => { const name = curr.replace(rootDir, '').slice(1).split(sep)[0]; if (acc[name]) { acc[name].push(resolve(curr)); } else { acc[name] = [resolve(curr)]; } return acc; }, {}); let meta = {}; return Promise.all( Object.entries(templates).map(([template, files]) => { const cwd = resolve(join(rootDir, template)); const dest = join(destDir, `${template}.tgz`); const metafile = files.find((f) => f.endsWith('meta.json')); if (metafile) { files = files.filter((f) => f !== metafile); meta[template] = JSON.parse(readFileSync(metafile).toString()); } return fs.mkdir(dirname(dest), { recursive: true }).then(() => tar.create( { gzip: true, portable: true, file: dest, cwd, }, files.map((f) => f.replace(cwd, '').slice(1)) ) ); }) ).then(() => { if (Object.keys(meta).length > 0) { return fs.writeFile(resolve(destDir, 'meta.json'), JSON.stringify(meta, null, 2)); } }); } const files = await glob(patterns); await Promise.all( files.map((file) => { const dest = resolve(file.replace(/^[^/]+/, 'dist')); return fs.mkdir(dirname(dest), { recursive: true }).then(() => fs.copyFile(resolve(file), dest)); }) ); } function resolveRootDir(files) { return files .reduce((acc, curr) => { const currParts = curr.split(sep); if (acc.length === 0) return currParts; const result = []; currParts.forEach((part, i) => { if (acc[i] === part) result.push(part); }); return result; }, []) .join(sep); } -branch Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/examples/with-react/src/components/Counter.jsx (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-04-10attempt to fix the 'no commits' bug in changesetGravatar Fred K. Schott 1-1/+1
2022-04-10revert releaseGravatar Fred K. Schott 76-225/+329
2022-04-10Update astro changelogGravatar Fred K. Schott 1-29/+0
2022-04-11[ci] formatGravatar FredKSchott 3-34/+34
2022-04-10[ci] release (#3060)Gravatar github-actions[bot] 76-363/+288
2022-04-10update changesetGravatar Fred K. Schott 1-1/+0
2022-04-10update changesetGravatar Fred K. Schott 1-1/+1
2022-04-10update lockfile (#3059)Gravatar Fred K. Schott 29-914/+698
2022-04-10correct changesetsGravatar Fred K. Schott 3-3/+11
2022-04-10chore: webapi test now use chai (#3048)Gravatar Juan Martín Seery 16-814/+539
2022-04-10update test names containing spacesGravatar Fred K. Schott 26-17/+17
2022-04-11[ci] formatGravatar FredKSchott 2-8/+7
2022-04-10Fix SSR static build public file copying. fixes #3016 (#3037)Gravatar Steve Lee 8-5/+48
2022-04-10fix our weird beta release issues (#3031)Gravatar Fred K. Schott 4-6/+116
2022-04-10update tailwind integration readmeGravatar Fred K. Schott 2-9/+38
2022-04-10Fixed MD Lint issues (#3038)Gravatar Rafid Muhymin Wafi 1-12/+11