kopia lustrzana https://github.com/shoelace-style/shoelace
don't swallow errors
rodzic
c37e4ba6b5
commit
ca8ba2d16b
|
@ -16,35 +16,29 @@ const iconDir = path.join(outdir, '/assets/icons');
|
||||||
|
|
||||||
const iconPackageData = JSON.parse(await fs.readFile('./node_modules/bootstrap-icons/package.json', 'utf8'));
|
const iconPackageData = JSON.parse(await fs.readFile('./node_modules/bootstrap-icons/package.json', 'utf8'));
|
||||||
|
|
||||||
|
const version = iconPackageData.version;
|
||||||
|
const srcPath = `./.cache/icons/icons-${version}`;
|
||||||
|
const url = `https://github.com/twbs/icons/archive/v${version}.zip`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const version = iconPackageData.version;
|
|
||||||
const srcPath = `./.cache/icons/icons-${version}`;
|
|
||||||
const url = `https://github.com/twbs/icons/archive/v${version}.zip`;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await fs.stat(`${srcPath}/LICENSE.md`);
|
await fs.stat(`${srcPath}/LICENSE.md`);
|
||||||
} catch {
|
} catch {
|
||||||
// Download the source from GitHub (since not everything is published to NPM)
|
// Download the source from GitHub (since not everything is published to NPM)
|
||||||
console.log(`Downloading and extracting Bootstrap Icons ${version}...`);
|
|
||||||
await download(url, './.cache/icons', { extract: true });
|
await download(url, './.cache/icons', { extract: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy icons
|
// Copy icons
|
||||||
console.log(`Copying icons and license...`);
|
await deleteAsync([iconDir]);
|
||||||
await deleteAsync([iconDir]);
|
await fs.mkdir(iconDir, { recursive: true });
|
||||||
await fs.mkdir(iconDir, { recursive: true });
|
await Promise.all([
|
||||||
await Promise.all([
|
|
||||||
copy(`${srcPath}/icons`, iconDir),
|
copy(`${srcPath}/icons`, iconDir),
|
||||||
copy(`${srcPath}/LICENSE.md`, path.join(iconDir, 'LICENSE.md')),
|
copy(`${srcPath}/LICENSE.md`, path.join(iconDir, 'LICENSE.md')),
|
||||||
copy(`${srcPath}/bootstrap-icons.svg`, './docs/assets/images/sprite.svg', { overwrite: true })
|
copy(`${srcPath}/bootstrap-icons.svg`, './docs/assets/images/sprite.svg', { overwrite: true })
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Generate metadata
|
// Generate metadata
|
||||||
const files = await globby(`${srcPath}/docs/content/icons/**/*.md`);
|
const files = await globby(`${srcPath}/docs/content/icons/**/*.md`);
|
||||||
|
const metadata = await Promise.all(
|
||||||
console.log(`Generating metadata for ${files.length} icons...`);
|
|
||||||
|
|
||||||
const metadata = await Promise.all(
|
|
||||||
files.map(async file => {
|
files.map(async file => {
|
||||||
const name = path.basename(file, path.extname(file));
|
const name = path.basename(file, path.extname(file));
|
||||||
const data = fm(await fs.readFile(file, 'utf8')).attributes;
|
const data = fm(await fs.readFile(file, 'utf8')).attributes;
|
||||||
|
@ -56,9 +50,6 @@ try {
|
||||||
tags: data.tags
|
tags: data.tags
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
await fs.writeFile(path.join(iconDir, 'icons.json'), JSON.stringify(metadata, null, 2), 'utf8');
|
await fs.writeFile(path.join(iconDir, 'icons.json'), JSON.stringify(metadata, null, 2), 'utf8');
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
|
|
|
@ -18,14 +18,13 @@ const embeds = {};
|
||||||
|
|
||||||
mkdirSync(themesDir, { recursive: true });
|
mkdirSync(themesDir, { recursive: true });
|
||||||
|
|
||||||
try {
|
// Gather an object containing the source of all files named "_filename.css" so we can embed them later
|
||||||
// Gather an object containing the source of all files named "_filename.css" so we can embed them later
|
filesToEmbed.forEach(file => {
|
||||||
filesToEmbed.forEach(file => {
|
|
||||||
embeds[path.basename(file)] = fs.readFileSync(file, 'utf8');
|
embeds[path.basename(file)] = fs.readFileSync(file, 'utf8');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Loop through each theme file, copying the .css and generating a .js version for Lit users
|
// Loop through each theme file, copying the .css and generating a .js version for Lit users
|
||||||
files.forEach(file => {
|
files.forEach(file => {
|
||||||
let source = fs.readFileSync(file, 'utf8');
|
let source = fs.readFileSync(file, 'utf8');
|
||||||
|
|
||||||
// If the source has "/* _filename.css */" in it, replace it with the embedded styles
|
// If the source has "/* _filename.css */" in it, replace it with the embedded styles
|
||||||
|
@ -53,8 +52,4 @@ try {
|
||||||
|
|
||||||
fs.writeFileSync(cssFile, css, 'utf8');
|
fs.writeFileSync(cssFile, css, 'utf8');
|
||||||
fs.writeFileSync(jsFile, js, 'utf8');
|
fs.writeFileSync(jsFile, js, 'utf8');
|
||||||
});
|
});
|
||||||
} catch (err) {
|
|
||||||
console.error(chalk.red('Error generating stylesheets!'));
|
|
||||||
console.error(err);
|
|
||||||
}
|
|
||||||
|
|
Ładowanie…
Reference in New Issue