Skip to content

Commit

Permalink
Refactor: Moving printTable to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
afska committed Sep 2, 2020
1 parent 3a4ac89 commit 2831f03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
15 changes: 1 addition & 14 deletions scripts/importer/src/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ const fs = require("fs");
const mkdirp = require("mkdirp");
const $path = require("path");
const utils = require("./utils");
const {
printTableAndGetConsoleOutput,
} = require("console-table-printer/dist/src/internalTable/internal-table-printer");
const {
TableInternal,
} = require("console-table-printer/dist/src/internalTable/internal-table");
const getopt = require("node-getopt");
const _ = require("lodash");
require("colors");
Expand Down Expand Up @@ -47,13 +41,6 @@ const SELECTOR_PREFIXES = {
const LIBRARY_SUFFIX = "_list.txt";
const CAMPAIGN_LEVELS = _.keys(SELECTOR_PREFIXES);

const printTable = (rows) => {
let table = new TableInternal();
table.addRows(rows);
table.sortFunction = (a, b) => a.id - b.id;
printTableAndGetConsoleOutput(table);
};

// ------------
// COMMAND LINE
// ------------
Expand Down Expand Up @@ -283,7 +270,7 @@ fs.writeFileSync($path.join(OUTPUT_PATH, ROM_ID_FILE), romIdBuffer);
sortedSongsByLevel.forEach(({ difficultyLevel, songs }) => {
console.log(`\n${"SONG LIST".bold} - ${difficultyLevel.cyan}:`);

printTable(
utils.printTable(
songs.map(({ simfile: it, id }) => {
const normal = it.getChartByDifficulty("NORMAL");
const hard = it.getChartByDifficulty("HARD");
Expand Down
12 changes: 12 additions & 0 deletions scripts/importer/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const childProcess = require("child_process");
const readlineSync = require("readline-sync");
const {
printTableAndGetConsoleOutput,
} = require("console-table-printer/dist/src/internalTable/internal-table-printer");
const {
TableInternal,
} = require("console-table-printer/dist/src/internalTable/internal-table");
const _ = require("lodash");

module.exports = {
Expand Down Expand Up @@ -41,4 +47,10 @@ module.exports = {
restrictTo(value, min, max) {
return Math.max(Math.min(value, max), min);
},
printTable(rows) {
const table = new TableInternal();
table.addRows(rows);
table.sortFunction = (a, b) => a.id - b.id;
printTableAndGetConsoleOutput(table);
},
};

0 comments on commit 2831f03

Please sign in to comment.