@atlaskit/pragmatic-drag-and-drop-docs
Version:
This package holds the documentation for Pragmatic drag and drop in one place. It is not intended to be consumed directly by consumers. The package is used by other tools for sharing examples
39 lines (28 loc) • 1.15 kB
text/typescript
import fs from 'fs/promises';
import path from 'path';
import glob from 'fast-glob';
import { createSignedArtifact } from '@atlassian/codegen';
async function generateSVGDataURIs() {
const imageFolder = path.resolve(__dirname, '../examples/data/people/images');
const svgFiles = await glob(`${imageFolder}/raw/*.svg`);
await Promise.all(
svgFiles.map(async (file) => {
const svg = await fs.readFile(file, { encoding: 'utf8' });
const dataURI = `data:image/svg+xml,${svg.replace(/\n/g, '').replace(/[#<>]/g, encodeURIComponent)}`;
const source = `export default '${dataURI}'`;
const signedSource = createSignedArtifact(
source,
'yarn workspace @atlaskit/pragmatic-drag-and-drop-docs codegen',
'This exists to workaround CodeSandbox issues with importing SVGs',
);
const outputFolder = path.join(imageFolder, 'processed');
// Using `recursive: true` so it doesn't throw if it already exists
await fs.mkdir(outputFolder, { recursive: true });
await fs.writeFile(
path.join(outputFolder, path.basename(file).replace('.svg', '.ts')),
signedSource,
);
}),
);
}
generateSVGDataURIs();