-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(extras): replace "glob" with "tinyglobby"
Vite did similar: vitejs/vite#18243
- Loading branch information
Showing
11 changed files
with
680 additions
and
591 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,90 @@ | ||
const packageName = 'animate.css' | ||
const packageName = "animate.css"; | ||
|
||
// ------------ | ||
|
||
const glob = require('glob') | ||
const { copySync } = require('fs-extra') | ||
const { writeFileSync } = require('fs') | ||
const { join, resolve, basename } = require('path') | ||
const tinyglobby = require("tinyglobby"); | ||
const { copySync } = require("fs-extra"); | ||
const { writeFileSync } = require("fs"); | ||
const { join, resolve, basename } = require("path"); | ||
|
||
const dist = resolve(__dirname, '../animate') | ||
const dist = resolve(__dirname, "../animate"); | ||
|
||
const pkgFolder = resolve(__dirname, `../node_modules/${ packageName }/`) | ||
const cssFiles = glob.sync(pkgFolder + '/source/*/*.css') | ||
const cssNames = new Set() | ||
const pkgFolder = resolve(__dirname, `../node_modules/${packageName}/`); | ||
const cssFiles = tinyglobby.sync(pkgFolder + "/source/*/*.css"); | ||
const cssNames = new Set(); | ||
|
||
const inAnimations = [] | ||
const outAnimations = [] | ||
const generalAnimations = [] | ||
const inAnimations = []; | ||
const outAnimations = []; | ||
const generalAnimations = []; | ||
|
||
function extract (file) { | ||
const name = basename(file).match(/(.*)\.css/)[ 1 ] | ||
function extract(file) { | ||
const name = basename(file).match(/(.*)\.css/)[1]; | ||
|
||
if (cssNames.has(name)) { | ||
return | ||
return; | ||
} | ||
|
||
copySync(file, join(dist, name + '.css')) | ||
cssNames.add(name) | ||
copySync(file, join(dist, name + ".css")); | ||
cssNames.add(name); | ||
|
||
if (name.indexOf('In') > -1) { | ||
inAnimations.push(name) | ||
} | ||
else if (name.indexOf('Out') > -1) { | ||
outAnimations.push(name) | ||
} | ||
else { | ||
generalAnimations.push(name) | ||
if (name.indexOf("In") > -1) { | ||
inAnimations.push(name); | ||
} else if (name.indexOf("Out") > -1) { | ||
outAnimations.push(name); | ||
} else { | ||
generalAnimations.push(name); | ||
} | ||
} | ||
|
||
function getList (prefix) { | ||
function getList(prefix) { | ||
return ` | ||
${ prefix }generalAnimations = ${ JSON.stringify(generalAnimations, null, 2) } | ||
${prefix}generalAnimations = ${JSON.stringify(generalAnimations, null, 2)} | ||
${ prefix }inAnimations = ${ JSON.stringify(inAnimations, null, 2) } | ||
${prefix}inAnimations = ${JSON.stringify(inAnimations, null, 2)} | ||
${ prefix }outAnimations = ${ JSON.stringify(outAnimations, null, 2) } | ||
`.replace(/"/g, '\'') | ||
${prefix}outAnimations = ${JSON.stringify(outAnimations, null, 2)} | ||
`.replace(/"/g, "'"); | ||
} | ||
|
||
if (cssFiles.length === 0) { | ||
console.log('WARNING. Animate.css skipped completely') | ||
} | ||
else { | ||
cssFiles.forEach(file => { | ||
extract(file) | ||
}) | ||
|
||
generalAnimations.sort() | ||
inAnimations.sort() | ||
outAnimations.sort() | ||
|
||
copySync(join(pkgFolder, 'LICENSE'), join(dist, 'LICENSE')) | ||
|
||
const common = getList('module.exports.') | ||
|
||
writeFileSync(join(dist, 'animate-list.js'), common, 'utf-8') | ||
writeFileSync(join(dist, 'animate-list.mjs'), getList('export const '), 'utf-8') | ||
writeFileSync(join(dist, 'animate-list.common.js'), common, 'utf-8') | ||
|
||
writeFileSync(join(dist, 'animate-list.d.ts'), getList('export type ').replace(/\[/g, '').replace(/\]/g, ';').replace(/\ {2}'/g, ' | \'').replace(/,/g, ''), 'utf-8') | ||
writeFileSync(join(dist, 'animate-list.common.d.ts'), getList('export type ').replace(/\[/g, '').replace(/\]/g, ';').replace(/\ {2}'/g, ' | \'').replace(/,/g, ''), 'utf-8') | ||
console.log("WARNING. Animate.css skipped completely"); | ||
} else { | ||
cssFiles.forEach((file) => { | ||
extract(file); | ||
}); | ||
|
||
generalAnimations.sort(); | ||
inAnimations.sort(); | ||
outAnimations.sort(); | ||
|
||
copySync(join(pkgFolder, "LICENSE"), join(dist, "LICENSE")); | ||
|
||
const common = getList("module.exports."); | ||
|
||
writeFileSync(join(dist, "animate-list.js"), common, "utf-8"); | ||
writeFileSync( | ||
join(dist, "animate-list.mjs"), | ||
getList("export const "), | ||
"utf-8", | ||
); | ||
writeFileSync(join(dist, "animate-list.common.js"), common, "utf-8"); | ||
|
||
writeFileSync( | ||
join(dist, "animate-list.d.ts"), | ||
getList("export type ") | ||
.replace(/\[/g, "") | ||
.replace(/\]/g, ";") | ||
.replace(/\ {2}'/g, " | '") | ||
.replace(/,/g, ""), | ||
"utf-8", | ||
); | ||
writeFileSync( | ||
join(dist, "animate-list.common.d.ts"), | ||
getList("export type ") | ||
.replace(/\[/g, "") | ||
.replace(/\]/g, ";") | ||
.replace(/\ {2}'/g, " | '") | ||
.replace(/,/g, ""), | ||
"utf-8", | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,102 @@ | ||
const packageName = 'bootstrap-icons' | ||
const distName = 'bootstrap-icons' | ||
const iconSetName = 'Bootstrap' | ||
const prefix = 'bi' | ||
const packageName = "bootstrap-icons"; | ||
const distName = "bootstrap-icons"; | ||
const iconSetName = "Bootstrap"; | ||
const prefix = "bi"; | ||
|
||
// ------------ | ||
|
||
const glob = require('glob') | ||
const { copySync } = require('fs-extra') | ||
const { writeFileSync } = require('fs') | ||
const { resolve, join } = require('path') | ||
const tinyglobby = require("tinyglobby"); | ||
const { copySync } = require("fs-extra"); | ||
const { writeFileSync } = require("fs"); | ||
const { resolve, join } = require("path"); | ||
|
||
const skipped = [] | ||
const distFolder = resolve(__dirname, '../bootstrap-icons') | ||
const { defaultNameMapper, extract, writeExports, copyCssFile } = require('./utils') | ||
const skipped = []; | ||
const distFolder = resolve(__dirname, "../bootstrap-icons"); | ||
const { | ||
defaultNameMapper, | ||
extract, | ||
writeExports, | ||
copyCssFile, | ||
} = require("./utils"); | ||
|
||
const svgFolder = resolve(__dirname, `../node_modules/${ packageName }/icons/`) | ||
const svgFiles = glob.sync(svgFolder + '/*.svg') | ||
let iconNames = new Set() | ||
const svgFolder = resolve(__dirname, `../node_modules/${packageName}/icons/`); | ||
const svgFiles = tinyglobby.sync(svgFolder + "/*.svg"); | ||
let iconNames = new Set(); | ||
|
||
const svgExports = [] | ||
const typeExports = [] | ||
const svgExports = []; | ||
const typeExports = []; | ||
|
||
svgFiles.forEach(file => { | ||
const name = defaultNameMapper(file, prefix) | ||
svgFiles.forEach((file) => { | ||
const name = defaultNameMapper(file, prefix); | ||
|
||
if (iconNames.has(name)) { | ||
return | ||
return; | ||
} | ||
|
||
try { | ||
const { svgDef, typeDef } = extract(file, name) | ||
svgExports.push(svgDef) | ||
typeExports.push(typeDef) | ||
|
||
iconNames.add(name) | ||
} | ||
catch (err) { | ||
console.error(err) | ||
skipped.push(name) | ||
const { svgDef, typeDef } = extract(file, name); | ||
svgExports.push(svgDef); | ||
typeExports.push(typeDef); | ||
|
||
iconNames.add(name); | ||
} catch (err) { | ||
console.error(err); | ||
skipped.push(name); | ||
} | ||
}) | ||
}); | ||
|
||
iconNames = [ ...iconNames ] | ||
iconNames = [...iconNames]; | ||
svgExports.sort((a, b) => { | ||
return ('' + a).localeCompare(b) | ||
}) | ||
return ("" + a).localeCompare(b); | ||
}); | ||
typeExports.sort((a, b) => { | ||
return ('' + a).localeCompare(b) | ||
}) | ||
return ("" + a).localeCompare(b); | ||
}); | ||
iconNames.sort((a, b) => { | ||
return ('' + a).localeCompare(b) | ||
}) | ||
|
||
writeExports(iconSetName, packageName, distFolder, svgExports, typeExports, skipped) | ||
return ("" + a).localeCompare(b); | ||
}); | ||
|
||
writeExports( | ||
iconSetName, | ||
packageName, | ||
distFolder, | ||
svgExports, | ||
typeExports, | ||
skipped, | ||
); | ||
|
||
// then update webfont files | ||
|
||
const webfont = [ | ||
'bootstrap-icons.woff', | ||
'bootstrap-icons.woff2' | ||
] | ||
const webfont = ["bootstrap-icons.woff", "bootstrap-icons.woff2"]; | ||
|
||
webfont.forEach(file => { | ||
webfont.forEach((file) => { | ||
copySync( | ||
resolve(__dirname, `../node_modules/${ packageName }/font/fonts/${ file }`), | ||
resolve(__dirname, `../bootstrap-icons/${ file }`) | ||
) | ||
}) | ||
resolve(__dirname, `../node_modules/${packageName}/font/fonts/${file}`), | ||
resolve(__dirname, `../bootstrap-icons/${file}`), | ||
); | ||
}); | ||
|
||
copyCssFile({ | ||
from: resolve(__dirname, `../node_modules/${ packageName }/font/bootstrap-icons.css`), | ||
to: resolve(__dirname, '../bootstrap-icons/bootstrap-icons.css'), | ||
replaceFn: content => { | ||
return content.replace(/src:[^;]+;/, 'src: url("./bootstrap-icons.woff2") format("woff2"), url("./bootstrap-icons.woff") format("woff");') | ||
} | ||
}) | ||
from: resolve( | ||
__dirname, | ||
`../node_modules/${packageName}/font/bootstrap-icons.css`, | ||
), | ||
to: resolve(__dirname, "../bootstrap-icons/bootstrap-icons.css"), | ||
replaceFn: (content) => { | ||
return content.replace( | ||
/src:[^;]+;/, | ||
'src: url("./bootstrap-icons.woff2") format("woff2"), url("./bootstrap-icons.woff") format("woff");', | ||
); | ||
}, | ||
}); | ||
|
||
copySync( | ||
resolve(__dirname, `../node_modules/${ packageName }/LICENSE`), | ||
resolve(__dirname, '../bootstrap-icons/LICENSE') | ||
) | ||
resolve(__dirname, `../node_modules/${packageName}/LICENSE`), | ||
resolve(__dirname, "../bootstrap-icons/LICENSE"), | ||
); | ||
|
||
// write the JSON file | ||
const file = resolve(__dirname, join('..', distName, 'icons.json')) | ||
writeFileSync(file, JSON.stringify([ ...iconNames ].sort(), null, 2), 'utf-8') | ||
const file = resolve(__dirname, join("..", distName, "icons.json")); | ||
writeFileSync(file, JSON.stringify([...iconNames].sort(), null, 2), "utf-8"); | ||
|
||
console.log(`${ distName } done with ${ iconNames.length } icons`) | ||
console.log(`${distName} done with ${iconNames.length} icons`); |
Oops, something went wrong.