kopia lustrzana https://github.com/shoelace-style/shoelace
don't swallow errors
rodzic
c37e4ba6b5
commit
ca8ba2d16b
|
@ -16,49 +16,40 @@ const iconDir = path.join(outdir, '/assets/icons');
|
|||
|
||||
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 {
|
||||
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`);
|
||||
} catch {
|
||||
// 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 });
|
||||
}
|
||||
|
||||
// Copy icons
|
||||
console.log(`Copying icons and license...`);
|
||||
await deleteAsync([iconDir]);
|
||||
await fs.mkdir(iconDir, { recursive: true });
|
||||
await Promise.all([
|
||||
copy(`${srcPath}/icons`, iconDir),
|
||||
copy(`${srcPath}/LICENSE.md`, path.join(iconDir, 'LICENSE.md')),
|
||||
copy(`${srcPath}/bootstrap-icons.svg`, './docs/assets/images/sprite.svg', { overwrite: true })
|
||||
]);
|
||||
|
||||
// Generate metadata
|
||||
const files = await globby(`${srcPath}/docs/content/icons/**/*.md`);
|
||||
|
||||
console.log(`Generating metadata for ${files.length} icons...`);
|
||||
|
||||
const metadata = await Promise.all(
|
||||
files.map(async file => {
|
||||
const name = path.basename(file, path.extname(file));
|
||||
const data = fm(await fs.readFile(file, 'utf8')).attributes;
|
||||
|
||||
return {
|
||||
name,
|
||||
title: data.title,
|
||||
categories: data.categories,
|
||||
tags: data.tags
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
await fs.writeFile(path.join(iconDir, 'icons.json'), JSON.stringify(metadata, null, 2), 'utf8');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
await fs.stat(`${srcPath}/LICENSE.md`);
|
||||
} catch {
|
||||
// Download the source from GitHub (since not everything is published to NPM)
|
||||
await download(url, './.cache/icons', { extract: true });
|
||||
}
|
||||
|
||||
// Copy icons
|
||||
await deleteAsync([iconDir]);
|
||||
await fs.mkdir(iconDir, { recursive: true });
|
||||
await Promise.all([
|
||||
copy(`${srcPath}/icons`, iconDir),
|
||||
copy(`${srcPath}/LICENSE.md`, path.join(iconDir, 'LICENSE.md')),
|
||||
copy(`${srcPath}/bootstrap-icons.svg`, './docs/assets/images/sprite.svg', { overwrite: true })
|
||||
]);
|
||||
|
||||
// Generate metadata
|
||||
const files = await globby(`${srcPath}/docs/content/icons/**/*.md`);
|
||||
const metadata = await Promise.all(
|
||||
files.map(async file => {
|
||||
const name = path.basename(file, path.extname(file));
|
||||
const data = fm(await fs.readFile(file, 'utf8')).attributes;
|
||||
|
||||
return {
|
||||
name,
|
||||
title: data.title,
|
||||
categories: data.categories,
|
||||
tags: data.tags
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
await fs.writeFile(path.join(iconDir, 'icons.json'), JSON.stringify(metadata, null, 2), 'utf8');
|
||||
|
|
|
@ -18,43 +18,38 @@ const embeds = {};
|
|||
|
||||
mkdirSync(themesDir, { recursive: true });
|
||||
|
||||
try {
|
||||
// Gather an object containing the source of all files named "_filename.css" so we can embed them later
|
||||
filesToEmbed.forEach(file => {
|
||||
embeds[path.basename(file)] = fs.readFileSync(file, 'utf8');
|
||||
// Gather an object containing the source of all files named "_filename.css" so we can embed them later
|
||||
filesToEmbed.forEach(file => {
|
||||
embeds[path.basename(file)] = fs.readFileSync(file, 'utf8');
|
||||
});
|
||||
|
||||
// Loop through each theme file, copying the .css and generating a .js version for Lit users
|
||||
files.forEach(file => {
|
||||
let source = fs.readFileSync(file, 'utf8');
|
||||
|
||||
// If the source has "/* _filename.css */" in it, replace it with the embedded styles
|
||||
Object.keys(embeds).forEach(key => {
|
||||
source = source.replace(`/* ${key} */`, embeds[key]);
|
||||
});
|
||||
|
||||
// Loop through each theme file, copying the .css and generating a .js version for Lit users
|
||||
files.forEach(file => {
|
||||
let source = fs.readFileSync(file, 'utf8');
|
||||
|
||||
// If the source has "/* _filename.css */" in it, replace it with the embedded styles
|
||||
Object.keys(embeds).forEach(key => {
|
||||
source = source.replace(`/* ${key} */`, embeds[key]);
|
||||
});
|
||||
|
||||
const css = prettier.format(stripComments(source), {
|
||||
parser: 'css'
|
||||
});
|
||||
|
||||
let js = prettier.format(
|
||||
`
|
||||
import { css } from 'lit';
|
||||
|
||||
export default css\`
|
||||
${css}
|
||||
\`;
|
||||
`,
|
||||
{ parser: 'babel-ts' }
|
||||
);
|
||||
|
||||
const cssFile = path.join(themesDir, path.basename(file));
|
||||
const jsFile = path.join(themesDir, path.basename(file).replace('.css', '.styles.js'));
|
||||
|
||||
fs.writeFileSync(cssFile, css, 'utf8');
|
||||
fs.writeFileSync(jsFile, js, 'utf8');
|
||||
const css = prettier.format(stripComments(source), {
|
||||
parser: 'css'
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(chalk.red('Error generating stylesheets!'));
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
let js = prettier.format(
|
||||
`
|
||||
import { css } from 'lit';
|
||||
|
||||
export default css\`
|
||||
${css}
|
||||
\`;
|
||||
`,
|
||||
{ parser: 'babel-ts' }
|
||||
);
|
||||
|
||||
const cssFile = path.join(themesDir, path.basename(file));
|
||||
const jsFile = path.join(themesDir, path.basename(file).replace('.css', '.styles.js'));
|
||||
|
||||
fs.writeFileSync(cssFile, css, 'utf8');
|
||||
fs.writeFileSync(jsFile, js, 'utf8');
|
||||
});
|
||||
|
|
Ładowanie…
Reference in New Issue