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

Fix output formatting for torus cli #7

Merged
merged 1 commit into from
Nov 16, 2021
Merged
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
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"hgcheck",
"hgignore",
"intellij",
"listr",
"mergewith",
"mkdocs",
"npmignore",
Expand Down
105 changes: 94 additions & 11 deletions packages/eslint-config-vue/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,16 @@
"@typescript-eslint/types" "5.3.0"
eslint-visitor-keys "^3.0.0"

"@vue/eslint-config-airbnb@^5.3.0":
version "5.3.0"
resolved "https://registry.yarnpkg.com/@vue/eslint-config-airbnb/-/eslint-config-airbnb-5.3.0.tgz#896551d600816a06dff13fdd7d04fd5153379817"
integrity sha512-m9ldRhbqaODbcc9mQZjPgnTzyNweZblLMTqMfC2kHWY68dYd3kwG/hvENeZWXJnKKo+eGnoptk+7Zq/c1519ZQ==
dependencies:
eslint-config-airbnb-base "^14.0.0"
eslint-import-resolver-node "^0.3.4"
eslint-import-resolver-webpack "^0.13.0"
eslint-plugin-import "^2.21.2"

"@vue/eslint-config-typescript@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@vue/eslint-config-typescript/-/eslint-config-typescript-9.0.0.tgz#e6a46d4ffb2c82b639fe183ec734569f33b47605"
Expand Down Expand Up @@ -203,6 +213,11 @@ argparse@^2.0.1:
resolved "https://registry.yarnpkg.com/argparse/-/argparse-2.0.1.tgz#246f50f3ca78a3240f6c997e8a9bd1eac49e4b38"
integrity sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==

array-find@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/array-find/-/array-find-1.0.0.tgz#6c8e286d11ed768327f8e62ecee87353ca3e78b8"
integrity sha1-bI4obRHtdoMn+OYuzuhzU8o+eLg=

array-includes@^3.1.4:
version "3.1.4"
resolved "https://registry.yarnpkg.com/array-includes/-/array-includes-3.1.4.tgz#f5b493162c760f3539631f005ba2bb46acb45ba9"
Expand Down Expand Up @@ -354,6 +369,15 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"

enhanced-resolve@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-0.9.1.tgz#4d6e689b3725f86090927ccc86cd9f1635b89e2e"
integrity sha1-TW5omzcl+GCQknzMhs2fFjW4ni4=
dependencies:
graceful-fs "^4.1.2"
memory-fs "^0.2.0"
tapable "^0.1.8"

enquirer@^2.3.5:
version "2.3.6"
resolved "https://registry.yarnpkg.com/enquirer/-/enquirer-2.3.6.tgz#2a7fe5dd634a1e4125a975ec994ff5456dc3734d"
Expand Down Expand Up @@ -401,7 +425,7 @@ escape-string-regexp@^4.0.0:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==

eslint-config-airbnb-base@14.2.1, eslint-config-airbnb-base@^14.2.1:
eslint-config-airbnb-base@^14.0.0:
version "14.2.1"
resolved "https://registry.yarnpkg.com/eslint-config-airbnb-base/-/eslint-config-airbnb-base-14.2.1.tgz#8a2eb38455dc5a312550193b319cdaeef042cd1e"
integrity sha512-GOrQyDtVEc1Xy20U7vsB2yAoB4nBlfH5HZJeatRXHleO+OS5Ot+MWij4Dpltw4/DyIkqUfqz1epfhVR5XWWQPA==
Expand All @@ -410,13 +434,6 @@ eslint-config-airbnb-base@14.2.1, eslint-config-airbnb-base@^14.2.1:
object.assign "^4.1.2"
object.entries "^1.1.2"

eslint-config-airbnb-typescript@^14.0.1:
version "14.0.1"
resolved "https://registry.yarnpkg.com/eslint-config-airbnb-typescript/-/eslint-config-airbnb-typescript-14.0.1.tgz#6721eb320d3953ae0d4bf258e877900fcb543a38"
integrity sha512-tF4GwC3sRrw8kEj4/yxX8F7AcLzj/1IESBnsCiFMplzYmxre459qm2z9DFkCpqBVQFSH6j2K4+VKVteX4m0GsQ==
dependencies:
eslint-config-airbnb-base "14.2.1"

eslint-config-prettier@^8.3.0:
version "8.3.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-8.3.0.tgz#f7471b20b6fe8a9a9254cc684454202886a2dd7a"
Expand All @@ -432,15 +449,32 @@ eslint-config-standard@^16.0.3:
resolved "https://registry.yarnpkg.com/eslint-config-standard/-/eslint-config-standard-16.0.3.tgz#6c8761e544e96c531ff92642eeb87842b8488516"
integrity sha512-x4fmJL5hGqNJKGHSjnLdgA6U6h1YW/G2dW9fA+cyVur4SK6lyue8+UgNKWlZtUDTXvgKDD/Oa3GQjmB5kjtVvg==

eslint-import-resolver-node@^0.3.6:
eslint-import-resolver-node@^0.3.4, eslint-import-resolver-node@^0.3.6:
version "0.3.6"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz#4048b958395da89668252001dbd9eca6b83bacbd"
integrity sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw==
dependencies:
debug "^3.2.7"
resolve "^1.20.0"

eslint-module-utils@^2.7.0:
eslint-import-resolver-webpack@^0.13.0:
version "0.13.2"
resolved "https://registry.yarnpkg.com/eslint-import-resolver-webpack/-/eslint-import-resolver-webpack-0.13.2.tgz#fc813df0d08b9265cc7072d22393bda5198bdc1e"
integrity sha512-XodIPyg1OgE2h5BDErz3WJoK7lawxKTJNhgPNafRST6csC/MZC+L5P6kKqsZGRInpbgc02s/WZMrb4uGJzcuRg==
dependencies:
array-find "^1.0.0"
debug "^3.2.7"
enhanced-resolve "^0.9.1"
find-root "^1.1.0"
has "^1.0.3"
interpret "^1.4.0"
is-core-module "^2.7.0"
is-regex "^1.1.4"
lodash "^4.17.21"
resolve "^1.20.0"
semver "^5.7.1"

eslint-module-utils@^2.7.0, eslint-module-utils@^2.7.1:
version "2.7.1"
resolved "https://registry.yarnpkg.com/eslint-module-utils/-/eslint-module-utils-2.7.1.tgz#b435001c9f8dd4ab7f6d0efcae4b9696d4c24b7c"
integrity sha512-fjoetBXQZq2tSTWZ9yWVl2KuFrTZZH3V+9iD1V1RfpDgxzJR+mPd/KZmMiA8gbPqdBzpNiEHOuT7IYEWxrH0zQ==
Expand All @@ -457,6 +491,25 @@ eslint-plugin-es@^3.0.0:
eslint-utils "^2.0.0"
regexpp "^3.0.0"

eslint-plugin-import@^2.21.2:
version "2.25.3"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.25.3.tgz#a554b5f66e08fb4f6dc99221866e57cfff824766"
integrity sha512-RzAVbby+72IB3iOEL8clzPLzL3wpDrlwjsTBAQXgyp5SeTqqY+0bFubwuo+y/HLhNZcXV4XqTBO4LGsfyHIDXg==
dependencies:
array-includes "^3.1.4"
array.prototype.flat "^1.2.5"
debug "^2.6.9"
doctrine "^2.1.0"
eslint-import-resolver-node "^0.3.6"
eslint-module-utils "^2.7.1"
has "^1.0.3"
is-core-module "^2.8.0"
is-glob "^4.0.3"
minimatch "^3.0.4"
object.values "^1.1.5"
resolve "^1.20.0"
tsconfig-paths "^3.11.0"

eslint-plugin-import@^2.25.2:
version "2.25.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-import/-/eslint-plugin-import-2.25.2.tgz#b3b9160efddb702fc1636659e71ba1d10adbe9e9"
Expand Down Expand Up @@ -715,6 +768,11 @@ fill-range@^7.0.1:
dependencies:
to-regex-range "^5.0.1"

find-root@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/find-root/-/find-root-1.1.0.tgz#abcfc8ba76f708c42a97b3d685b7e9450bfb9ce4"
integrity sha512-NKfW6bec6GfKc0SGx1e07QZY9PE99u0Bft/0rzSD5k3sO/vwkVUpDUKVm5Gpp5Ue3YfShPFTX2070tDs5kB9Ng==

find-up@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7"
Expand Down Expand Up @@ -812,6 +870,11 @@ globby@^11.0.4:
merge2 "^1.3.0"
slash "^3.0.0"

graceful-fs@^4.1.2:
version "4.2.8"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.8.tgz#e412b8d33f5e006593cbd3cee6df9f2cebbe802a"
integrity sha512-qkIilPUYcNhJpd33n0GBXTB1MMPp14TxEsEs0pTrsSVucApsYzW5V+Q8Qxhik6KU3evy+qkAAowTByymK0avdg==

has-bigints@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/has-bigints/-/has-bigints-1.0.1.tgz#64fe6acb020673e3b78db035a5af69aa9d07b113"
Expand Down Expand Up @@ -891,6 +954,11 @@ internal-slot@^1.0.3:
has "^1.0.3"
side-channel "^1.0.4"

interpret@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==

is-bigint@^1.0.1:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-bigint/-/is-bigint-1.0.4.tgz#08147a1875bc2b32005d41ccd8291dffc6691df3"
Expand All @@ -911,7 +979,7 @@ is-callable@^1.1.4, is-callable@^1.2.4:
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.4.tgz#47301d58dd0259407865547853df6d61fe471945"
integrity sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==

is-core-module@^2.1.0, is-core-module@^2.2.0, is-core-module@^2.7.0:
is-core-module@^2.1.0, is-core-module@^2.2.0, is-core-module@^2.7.0, is-core-module@^2.8.0:
version "2.8.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.8.0.tgz#0321336c3d0925e497fd97f5d95cb114a5ccd548"
integrity sha512-vd15qHsaqrRL7dtH6QNuy0ndJmRDrS9HAM1CAiSifNUFv4x1a0CCVsj18hJ1mShxIG6T2i1sO78MkP56r0nYRw==
Expand Down Expand Up @@ -1063,6 +1131,11 @@ lru-cache@^6.0.0:
dependencies:
yallist "^4.0.0"

memory-fs@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.2.0.tgz#f2bb25368bc121e391c2520de92969caee0a0290"
integrity sha1-8rslNovBIeORwlIN6Slpyu4KApA=

merge2@^1.3.0:
version "1.4.1"
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
Expand Down Expand Up @@ -1310,6 +1383,11 @@ run-parallel@^1.1.9:
dependencies:
queue-microtask "^1.2.2"

semver@^5.7.1:
version "5.7.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.1.tgz#a954f931aeba508d307bbf069eff0c01c96116f7"
integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==

semver@^6.1.0:
version "6.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.0.tgz#ee0a64c8af5e8ceea67687b133761e1becbd1d3d"
Expand Down Expand Up @@ -1393,6 +1471,11 @@ supports-color@^7.1.0:
dependencies:
has-flag "^4.0.0"

tapable@^0.1.8:
version "0.1.10"
resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.1.10.tgz#29c35707c2b70e50d07482b5d202e8ed446dafd4"
integrity sha1-KcNXB8K3DlDQdIK10gLo7URtr9Q=

text-table@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
Expand Down
17 changes: 17 additions & 0 deletions packages/torus-scripts/helpers/formatRollupStats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const path = require("path");
const chalk = require("chalk");
const { formatSize, getGzippedBufferSize } = require("./utils");

module.exports = function formatStats(stats, dir, time) {
// First item in stats is the rollup file
const chunks = stats.filter((x) => x.type === "chunk");
const lastDir = dir.split("/").pop();
return chunks.map((chunk) => {
return [
/js$/.test(chunk.fileName) ? chalk.green(path.join(lastDir, chunk.fileName)) : chalk.blue(path.join(lastDir, chunk.fileName)),
formatSize(Buffer.byteLength(chunk.code, "utf8")),
getGzippedBufferSize(Buffer.from(chunk.code, "utf8")),
`${(Number(time) / 1000).toFixed(1)} sec`,
];
});
};
45 changes: 45 additions & 0 deletions packages/torus-scripts/helpers/formatWebpackStats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const path = require("path");
const chalk = require("chalk");
const { formatSize, getGzippedSize } = require("./utils");

module.exports = function formatStats(stats, dir) {
const json = stats.toJson({
hash: false,
modules: false,
chunks: false,
});

let assets = json.assets ? json.assets : json.children.reduce((acc, child) => acc.concat(child.assets), []);

const seenNames = new Map();
const isJS = (val) => /\.js$/.test(val);
const isCSS = (val) => /\.css$/.test(val);
const isMinJS = (val) => /\.min\.js$/.test(val);
assets = assets
.map((a) => {
a.name = a.name.split("?")[0];
return a;
})
.filter((a) => {
if (seenNames.has(a.name)) {
return false;
}
seenNames.set(a.name, true);
return isJS(a.name) || isCSS(a.name);
})
.sort((a, b) => {
if (isJS(a.name) && isCSS(b.name)) return -1;
if (isCSS(a.name) && isJS(b.name)) return 1;
if (isMinJS(a.name) && !isMinJS(b.name)) return -1;
if (!isMinJS(a.name) && isMinJS(b.name)) return 1;
return b.size - a.size;
});

const lastDir = dir.split("/").pop();
return assets.map((asset) => [
/js$/.test(asset.name) ? chalk.green(path.join(lastDir, asset.name)) : chalk.blue(path.join(lastDir, asset.name)),
formatSize(asset.size),
getGzippedSize(asset, dir),
`${(json.time / 1000).toFixed(1)} sec`,
]);
};
26 changes: 26 additions & 0 deletions packages/torus-scripts/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require("fs");
const path = require("path");
const zlib = require("zlib");

function formatSize(size) {
return (size / 1024).toFixed(2) + " KiB";
}

function getGzippedSize(asset, dir) {
const filepath = require.resolve(path.join(dir, asset.name));
const buffer = fs.readFileSync(filepath);
return formatSize(zlib.gzipSync(buffer).length);
}

function getGzippedBufferSize(assetBuffer) {
return formatSize(zlib.gzipSync(assetBuffer).length);
}

function makeRow(a, b, c) {
return ` ${a}\t ${b}\t ${c}`;
}

exports.formatSize = formatSize;
exports.getGzippedSize = getGzippedSize;
exports.makeRow = makeRow;
exports.getGzippedBufferSize = getGzippedBufferSize;
2 changes: 2 additions & 0 deletions packages/torus-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
"@rollup/plugin-typescript": "^8.3.0",
"babel-loader": "^8.2.3",
"babel-merge": "^3.0.0",
"chalk": "^4.1.2",
"listr": "^0.14.3",
"dotenv": "^10.0.0",
"eslint-webpack-plugin": "^2.5.4",
"lodash.mergewith": "^4.6.2",
Expand Down
Loading