Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(frontend-icons): change icon scripts to be synchronous
This is necessary for running the scripts sequentially without having the next script start before the callbacks are finished on the previous script (unless all scripts are made asynchronous).
- Loading branch information
1 parent
ed65a62
commit 08682aa
Showing
2 changed files
with
25 additions
and
36 deletions.
There are no files selected for viewing
34 changes: 14 additions & 20 deletions
34
server/zanata-frontend/src/frontend/scripts/createIconsComponent.js
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,29 +1,23 @@ | ||
/* eslint-disable no-console */ | ||
var fs = require('fs') | ||
// build spritesheet used in this script (could change to return sheet) | ||
require('./build-icon-spritesheet') | ||
|
||
var svgFile = './app/components/Icons/icons.svg' | ||
var componentFileSrc = './app/components/Icons/index.jsx.src' | ||
var componentFile = './app/components/Icons/index.jsx' | ||
|
||
function getSVG (cb) { | ||
fs.readFile(svgFile, 'utf8', function (err, data) { | ||
var result | ||
if (err) return console.log(err) | ||
result = data.replace(/ style="position:absolute"/g, '') | ||
cb(result) | ||
}) | ||
function getSVG () { | ||
const data = fs.readFileSync(svgFile, 'utf8') | ||
return data.replace(/ style="position:absolute"/g, '') | ||
} | ||
|
||
function generateComponent (cb) { | ||
fs.readFile(componentFileSrc, 'utf8', function (err, data) { | ||
if (err) return console.log(err) | ||
getSVG(function (svg) { | ||
var component = data.replace(/{{svgFile: 'icons.svg'}}/, '\'' + svg + '\'') | ||
cb(component) | ||
}) | ||
}) | ||
function generateComponent () { | ||
const data = fs.readFileSync(componentFileSrc, 'utf8') | ||
const svg = getSVG() | ||
return data.replace(/{{svgFile: 'icons.svg'}}/, '\'' + svg + '\'') | ||
} | ||
|
||
generateComponent(function (component) { | ||
fs.writeFile(componentFile, component, 'utf8', function (err) { | ||
if (err) return console.log(err) | ||
}) | ||
}) | ||
process.stdout.write('Generating Icons component with embedded SVG') | ||
fs.writeFileSync(componentFile, generateComponent(), 'utf8') | ||
console.log(' ... Done') |
27 changes: 11 additions & 16 deletions
27
server/zanata-frontend/src/frontend/scripts/generateIconList.js
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,21 +1,16 @@ | ||
/* eslint-disable no-console */ | ||
var fs = require('fs') | ||
var iconsSrc = './app/components/Icons/svgs' | ||
var iconsFileName = './app/components/Icon/list.js' | ||
var svgFileRegex = /Icon-(.*).svg/ | ||
|
||
fs.readdir(iconsSrc, function (err, files) { | ||
if (err) { | ||
console.error(err) | ||
return | ||
} | ||
const fileNames = files.map(file => { | ||
const fileName = file.match(svgFileRegex) | ||
return fileName ? fileName[1] : undefined | ||
}).filter(file => file) | ||
const iconsFile = | ||
`module.exports = [${fileNames.map(file => `'${file}'`)}]\r\n` | ||
fs.writeFile(iconsFileName, iconsFile, (err) => { | ||
if (err) throw err | ||
console.log('Icon file list saved') | ||
}) | ||
}) | ||
process.stdout.write('Generating list of icon names in Icon/list.js') | ||
const files = fs.readdirSync(iconsSrc) | ||
const fileNames = files.map(file => { | ||
const fileName = file.match(svgFileRegex) | ||
return fileName ? fileName[1] : undefined | ||
}).filter(file => file) | ||
const iconsFile = | ||
`module.exports = [${fileNames.map(file => `'${file}'`)}]\r\n` | ||
fs.writeFileSync(iconsFileName, iconsFile) | ||
console.log(' ... Done') |