From a6803d71443d93d5e1e9b6451797f68f60ecbd86 Mon Sep 17 00:00:00 2001 From: Brian Sperlongano Date: Sat, 16 Dec 2023 08:55:34 -0500 Subject: [PATCH] Pass dist folder as param to stats --- .github/workflows/build-preview.yml | 4 ++-- scripts/stats.js | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-preview.yml b/.github/workflows/build-preview.yml index 7aa51e631..c446c98b9 100644 --- a/.github/workflows/build-preview.yml +++ b/.github/workflows/build-preview.yml @@ -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<> $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 🔧 diff --git a/scripts/stats.js b/scripts/stats.js index f5da4f778..05ec52d85 100644 --- a/scripts/stats.js +++ b/scripts/stats.js @@ -33,7 +33,12 @@ program ) .option("-loc, --locales ", "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 ", + "specify location of Americana distribution", + ["dist"] + ); program.parse(process.argv); @@ -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, @@ -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);