Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a thing that broke execution (larger icon set) #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const PAGE = {
ICON_INPUT: '.menuList2.menuList3 .file input[type="file"]',
FIRST_ICON_BOX: '#set0 .miBox:not(.mi-selected)',
REMOVE_SET_BUTTON: '.menuList2.menuList3 li:last-child button',
OPEN_FEATURES_MENU: '#setH0 > button',
SELECT_ALL_BUTTON: 'button[ng-click="selectAllNone($index, true)"]',
GENERATE_LINK: 'a[href="#/select/font"]',
GLYPH_SET: '#glyphSet0',
Expand Down Expand Up @@ -66,7 +67,7 @@ const checkDownload = dest => new Promise((resolve, reject) => {
}, interval);
});

const checkDuplicateName = ({ selectionPath, icons, names }, forceOverride) => {
const checkDuplicateName = ({selectionPath, icons, names}, forceOverride) => {
const iconNames = icons.map((icon, index) => {
if (names[index]) {
return names[index];
Expand All @@ -75,17 +76,17 @@ const checkDuplicateName = ({ selectionPath, icons, names }, forceOverride) => {
});
const duplicates = [];
const selection = fs.readJSONSync(selectionPath);
selection.icons.forEach(({ properties }, index) => {
selection.icons.forEach(({properties}, index) => {
if (iconNames.includes(properties.name)) {
duplicates.push({ name: properties.name, index });
duplicates.push({name: properties.name, index});
}
});
if (!duplicates.length) {
return;
}
if (forceOverride) {
selection.icons = selection.icons.filter((icon, index) => !duplicates.some(d => d.index === index));
fs.writeJSONSync(selectionPath, selection, { spaces: 2 });
fs.writeJSONSync(selectionPath, selection, {spaces: 2});
} else {
throw new Error(`Found duplicate icon names: ${duplicates.map(d => d.name).join(',')}`);
}
Expand All @@ -106,7 +107,7 @@ async function pipeline(options = {}) {
logger('Preparing...');
if (!icons || !icons.length) {
if (whenFinished) {
whenFinished({ outputDir });
whenFinished({outputDir});
}
return logger('No new icons found.');
}
Expand All @@ -122,7 +123,7 @@ async function pipeline(options = {}) {
await fs.remove(outputDir);
await fs.ensureDir(outputDir);

const browser = await puppeteer.launch({ headless: !visible });
const browser = await puppeteer.launch({headless: !visible});
logger('Started a new chrome instance, going to load icomoon.io.');
const page = await (await browser).newPage();
await page._client.send('Page.setDownloadBehavior', {
Expand All @@ -138,13 +139,13 @@ async function pipeline(options = {}) {

const importInput = await page.waitForSelector(PAGE.IMPORT_SELECTION_INPUT);
await importInput.uploadFile(absoluteSelectionPath);
await page.waitForSelector(PAGE.OVERLAY_CONFIRM, { visible: true });
await page.waitForSelector(PAGE.OVERLAY_CONFIRM, {visible: true});
await page.click(PAGE.OVERLAY_CONFIRM);
const selection = fs.readJSONSync(selectionPath);
if (selection.icons.length === 0) {
logger('Selection icons is empty, going to create an empty set');
await page.click(PAGE.MAIN_MENU_BUTTON);
await page.waitForSelector(PAGE.NEW_SET_BUTTON, { visible: true });
await page.waitForSelector(PAGE.NEW_SET_BUTTON, {visible: true});
await page.click(PAGE.NEW_SET_BUTTON);
}
logger('Uploaded config, going to upload new icon files');
Expand All @@ -153,6 +154,9 @@ async function pipeline(options = {}) {
const iconPaths = icons.map(getAbsolutePath);
await iconInput.uploadFile(...iconPaths);
await page.waitForSelector(PAGE.FIRST_ICON_BOX);
await sleep(1000);
await page.click(PAGE.OPEN_FEATURES_MENU);
await sleep(1000);
await page.click(PAGE.SELECT_ALL_BUTTON);
logger('Uploaded and selected all new icons');
await page.click(PAGE.GENERATE_LINK);
Expand All @@ -163,20 +167,20 @@ async function pipeline(options = {}) {
await sleep(1000);
await page.evaluate(names => {
const request = indexedDB.open('IDBWrapper-storage', 1);
request.onsuccess = function() {
request.onsuccess = function () {
const db = request.result;
const tx = db.transaction('storage', 'readwrite');
const store = tx.objectStore('storage');
const keys = store.getAllKeys();
keys.onsuccess = function() {
keys.onsuccess = function () {
let timestamp;
keys.result.forEach(function(key) {
keys.result.forEach(function (key) {
if (typeof key === 'number') {
timestamp = key;
}
});
const main = store.get(timestamp);
main.onsuccess = function() {
main.onsuccess = function () {
const data = main.result;
for (let i = 0; i < names.length; i++) {
data.obj.iconSets[0].selection[i].name = names[i];
Expand Down Expand Up @@ -205,16 +209,19 @@ async function pipeline(options = {}) {
logger('Successfully downloaded, going to unzip it.');
await page.close();
// unzip stage
extract(zipPath, { dir: outputDir }, async err => {
extract(zipPath, {dir: outputDir}, async err => {
if (err) {
throw err;
}
await fs.remove(zipPath);
logger(`Finished. The output directory is ${outputDir}.`);
if (whenFinished) {
whenFinished({ outputDir });
whenFinished({outputDir});
}
});

await browser.close();

} catch (error) {
console.error(error);
}
Expand Down
8 changes: 5 additions & 3 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@ const runCase = (name, fn) => new Promise((resolve, reject) => {
resolve();
}
}

console.log(`\r\n============= Start test '${name}' =============`);
fn(done);
});

(async function() {
(async function () {
await runCase('test with selection file which already has icons', done => {
const names = ['new1', 'new2'];
pipeline({
icons: ['test-assets/1.svg', 'test-assets/2.svg'],
names,
selectionPath: 'test-assets/selection.json',
forceOverride: true,
whenFinished (result) {
// visible: true,
whenFinished(result) {
const newSelection = JSON.parse(fs.readFileSync(path.resolve(result.outputDir, 'selection.json')));
assert.deepEqual(
newSelection.icons.slice(0, names.length).map(icon => icon.properties.name),
Expand All @@ -44,7 +46,7 @@ const runCase = (name, fn) => new Promise((resolve, reject) => {
names,
selectionPath: 'test-assets/selection-empty.json',
forceOverride: true,
whenFinished (result) {
whenFinished(result) {
const newSelection = JSON.parse(fs.readFileSync(path.resolve(result.outputDir, 'selection.json')));
assert.deepEqual(
newSelection.icons.map(icon => icon.properties.name),
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "icomoon-cli",
"version": "1.3.2",
"version": "1.3.3",
"description": "",
"main": "index.js",
"bin": {
Expand All @@ -17,12 +17,12 @@
"author": "",
"license": "ISC",
"dependencies": {
"extract-zip": "^1.6.6",
"fs-extra": "^4.0.2",
"yargs": "^10.0.3",
"puppeteer": "2.0.0"
"extract-zip": "^2.0.1",
"fs-extra": "^9.1.0",
"yargs": "^16.2.0",
"puppeteer": "5.5.0"
},
"devDependencies": {
"eslint": "^4.10.0"
"eslint": "^7.18.0"
}
}