You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
4.5 KiB
149 lines
4.5 KiB
#!/usr/bin/env node
|
|
|
|
const util = require("./util")
|
|
|
|
let wanted_icons = util.fread('../wanted.ini').split('\n')
|
|
.filter((x) => x.length && x[0] !== '#')
|
|
.map((x) => x.trim().replace(/\s*#.*/, ''))
|
|
|
|
|
|
let iconsfile = util.fread('templates/icons.yml')
|
|
let fontcustom = util.fread('../fontcustom.yml')
|
|
if (!fontcustom.fonts_path_relative_to_css) {
|
|
fontcustom.fonts_path_relative_to_css = './'
|
|
}
|
|
|
|
|
|
// find which aliases are defined
|
|
let alias_map = {}
|
|
iconsfile.icons.forEach((icon) => {
|
|
if (icon.aliases) {
|
|
icon.aliases.forEach((alias) => {
|
|
alias_map[alias] = icon.id
|
|
})
|
|
}
|
|
})
|
|
|
|
console.log(`Including ${wanted_icons.length} icons out of ${iconsfile.icons.length}`)
|
|
console.log(`Found ${Object.keys(alias_map).length} aliases defined in the dictionary`)
|
|
|
|
console.log('Preparing icons.yml...')
|
|
|
|
let wanted_all = []
|
|
let applied_aliases = {}
|
|
for(let id of wanted_icons) {
|
|
wanted_all.push(id)
|
|
if (alias_map[id]) {
|
|
applied_aliases[id] = alias_map[id]
|
|
wanted_all.push(alias_map[id])
|
|
}
|
|
}
|
|
|
|
let iconsfile_filtered = {
|
|
icons: iconsfile.icons.filter((x) => {
|
|
return wanted_all.indexOf(x.id) !== -1
|
|
})
|
|
}
|
|
|
|
// store the result for the postprocessing script
|
|
util.fwrite('../Fork-Awesome/src/icons/icons.yml', iconsfile_filtered)
|
|
util.fwrite('../Fork-Awesome/src/icons/fontcustom.yml', fontcustom)
|
|
|
|
if (util.exists('../Fork-Awesome/src/icons/.fontcustom-manifest.json')) {
|
|
util.rm('../Fork-Awesome/src/icons/.fontcustom-manifest.json')
|
|
}
|
|
|
|
let font_name = fontcustom.font_name
|
|
let fa_output_dir = `../Fork-Awesome/src/icons/${font_name}`
|
|
|
|
util.rmInDir('../Fork-Awesome/src/icons/svg')
|
|
util.rmInDir(fa_output_dir)
|
|
util.rmInDir('../output')
|
|
|
|
console.log('Copying icons ...')
|
|
for (let a of wanted_all) {
|
|
if (typeof alias_map[a] !== 'undefined') {
|
|
console.log(`Skipping alias ${a}`)
|
|
continue;
|
|
}
|
|
|
|
if (!util.cp(`./templates/svg/${a}.svg`,
|
|
`../Fork-Awesome/src/icons/svg/${a}.svg`,
|
|
false)) {
|
|
console.log(`- \x1b[31,1mFile "${a}.svg" not found!\x1b[m`)
|
|
}
|
|
}
|
|
|
|
console.log('Running builder script')
|
|
|
|
util.exec('bundle exec fontcustom compile', '../Fork-Awesome/src/icons/')
|
|
|
|
if (!util.exists(`${fa_output_dir}/${font_name}.css`)) {
|
|
util.abort('\x1b[31;1mBuild failed, no CSS in output directory.\x1b[m')
|
|
}
|
|
|
|
let suffixes = ['.css', '.eot', '.svg', '.ttf', '.woff', '.woff2', '-preview.html']
|
|
suffixes.forEach((x) => {
|
|
util.cp(`${fa_output_dir}/${font_name}${x}`, `../output/${font_name}${x}`)
|
|
})
|
|
|
|
let cssfile = `../output/${font_name}.css`
|
|
let htmlfile = `../output/${font_name}-preview.html`
|
|
|
|
console.log('Post-processing CSS')
|
|
let orig_css = util.fread(cssfile)
|
|
|
|
let iconstyles_begin_token = 'antialiased;\n}\n'
|
|
let iconstyles = orig_css
|
|
.substr(orig_css.indexOf(iconstyles_begin_token) + iconstyles_begin_token.length)
|
|
|
|
let template = util.fread('./css-template.css')
|
|
|
|
let prefix = fontcustom.css_selector
|
|
if (!prefix.endsWith('{{glyph}}')) {
|
|
util.abort(`CSS selector must end with {{glyph}}`)
|
|
}
|
|
prefix = prefix.replace('{{glyph}}', '').replace('.', '')
|
|
|
|
|
|
let fa_packagejson = util.fread('../Fork-Awesome/package.json')
|
|
|
|
let fontpath = fontcustom.fonts_path_relative_to_css
|
|
if (!fontpath.endsWith('/')) fontpath += '/'
|
|
|
|
console.log('Collected information:')
|
|
console.log(` \x1b[36mFont name:\x1b[m ${font_name}`)
|
|
console.log(` \x1b[36mFont path:\x1b[m ${fontpath} (relative to CSS)`)
|
|
console.log(` \x1b[36mCSS class prefix:\x1b[m ${prefix}`)
|
|
console.log(` \x1b[36mFork-Awesome version:\x1b[m ${fa_packagejson.version}`)
|
|
|
|
let html_content = util.fread(htmlfile)
|
|
|
|
let css_header = template.replace(/\$prefix/g, prefix)
|
|
.replace(/\$fontname/g, font_name)
|
|
.replace(/\$fontpath/g, fontpath)
|
|
.replace(/\$version/g, fa_packagejson.version)
|
|
|
|
for (let alias in applied_aliases) {
|
|
if (applied_aliases.hasOwnProperty(alias)) {
|
|
let orig = `.${prefix}${applied_aliases[alias]}:before`
|
|
let added = `.${prefix}${alias}:before`
|
|
console.log(`Adding CSS alias ${added} -> ${orig}`)
|
|
|
|
iconstyles = iconstyles.replace(orig, `${orig}, ${added}`)
|
|
|
|
html_content = html_content.replace(
|
|
`value=".${prefix}${applied_aliases[alias]}" />`,
|
|
`value=".${prefix}${applied_aliases[alias]}" />
|
|
<input class="class" type="text" readonly="readonly" onClick="this.select();" value="${added.replace(':before','')}" />`
|
|
)
|
|
}
|
|
}
|
|
|
|
util.fwrite(cssfile,
|
|
css_header + iconstyles.replace(/([^:]):before/g, '$1::before'))
|
|
|
|
util.fwrite(htmlfile, html_content)
|
|
|
|
console.log(`\x1b[32;1m=== Your font "${font_name}" is ready in the output directory ===\x1b[m`)
|
|
|
|
|