Skip to content

Commit

Permalink
Pass dist folder as param to stats
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeLonewolf committed Dec 16, 2023
1 parent 30f93e6 commit a6803d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:
- name: Capture main branch usage statistics
id: main-stats
run: |
MAIN_STATS=$(node ../pr-branch/scripts/stats.js -j)
MAIN_STATS=$(node scripts/stats.js -d ../main/dist -j)
echo "MAIN_STATS<<EOF" >> $GITHUB_ENV
echo -e "$MAIN_STATS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
working-directory: main
working-directory: pr-branch
- name: Checkout PR Branch 🛎️
uses: actions/checkout@v3
- name: Install and Build PR Branch 🔧
Expand Down
18 changes: 12 additions & 6 deletions scripts/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ program
)
.option("-loc, --locales <locale1 locale2...>", "language codes", ["mul"])
.option("-j, --all-json", "output all stats in JSON")
.option("-pp, --pretty", "pretty-print JSON output");
.option("-pp, --pretty", "pretty-print JSON output")
.option(
"-d, --directory <dir>",
"specify location of Americana distribution",
["dist"]
);

program.parse(process.argv);

Expand All @@ -42,6 +47,7 @@ const opts = program.opts();
if (Object.keys(opts).length === 1) program.help();

const locales = opts.locales[0].split(",");
const distDir = opts.directory;

const style = Style.build(
config.OPENMAPTILES_URL,
Expand All @@ -58,16 +64,16 @@ if (opts.layerCount) {
process.exit();
}

function spriteSheetSize(single) {
function spriteSheetSize(distDir, single) {
let size = single ? "" : "@2x";
return (
fs.statSync(`dist/sprites/sprite${size}.png`).size +
fs.statSync(`dist/sprites/sprite${size}.json`).size
fs.statSync(`${distDir}/sprites/sprite${size}.png`).size +
fs.statSync(`${distDir}/sprites/sprite${size}.json`).size
);
}

const spriteSheet1xSize = spriteSheetSize(true);
const spriteSheet2xSize = spriteSheetSize(false);
const spriteSheet1xSize = spriteSheetSize(distDir, true);
const spriteSheet2xSize = spriteSheetSize(distDir, false);

if (opts.spritesheet1xSize) {
console.log(spriteSheet1xSize);
Expand Down

0 comments on commit a6803d7

Please sign in to comment.