Skip to content

Commit

Permalink
Added assetfix to manage plaform assets
Browse files Browse the repository at this point in the history
  • Loading branch information
DerGoogler committed Jul 11, 2023
1 parent 58697c7 commit defaa23
Show file tree
Hide file tree
Showing 18 changed files with 2,951 additions and 10 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package.json
package-lock.json
node_modules/
__pycache__/
__pycache__/

# Ignore www bundles
www/bundle/*
www/files/*
4 changes: 2 additions & 2 deletions Android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ bin/
gen/
*.cxx
app/.cxx/*
app/src/main/assets/www/bundle/*
app/src/main/assets/www/files/*
app/src/main/assets/www/*
!/app/src/main/assets/**/.gitkeep

# Local configuration file (sdk path, etc)
local.properties
Expand Down
Empty file.
Empty file added Browser/.gitkeep
Empty file.
65 changes: 65 additions & 0 deletions Website/assetfix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const { program } = require("commander");
const { readdirSync, unlinkSync, rmSync } = require("fs");
const { copySync } = require("fs-extra");
const { resolve } = require("path");

program.name("assetfix").description("CLI to manage release or development assets").version("1.0.0");

program
.command("android")
.description("Prepares assets for Android")
.option("-b, --build", "Builds the assets for Android")
.option("-c, --clean", "Cleans the Android assets directory")
.action((opt) => {
// We only want to remove the *.map files
const wwwPath = resolve(__dirname, "./../www");
const assetsPath = resolve(__dirname, "./../Android/app/src/main/assets");

if (opt.build) {
const regex = /(app|vendor)[.]bundle[.](js|css)[.]map$/;
// Copy files to android app assets
copySync(wwwPath, resolve(assetsPath, "www"), { overwrite: true, filter: (src) => !regex.test(src) });
}

if (opt.clean) {
// We want to keep .gitkeep
const regex = /[.]gitkeep$/;
readdirSync(resolve(assetsPath, "www"))
.filter((f) => !regex.test(f))
.map((f) => unlinkSyncResolve(assetsPath, "www", f));
}
});

program
.command("web")
.description("Prepares assets for Browsers")
.option("-b, --build", "Builds the assets for Browser")
.option("-c, --clean", "Cleans the Browser assets directory")
.action((opt) => {
// We only want to remove the *.map files
const wwwPath = resolve(__dirname, "./../www");
const browserPath = resolve(__dirname, "./../Browser");

if (opt.build) {
const regex = /((app|vendor)[.]bundle[.](js|css)[.]map|(plugins|cordova-js-src))$/;
// Copy files to browser assets
copySync(wwwPath, browserPath, { overwrite: true, filter: (src) => !regex.test(src) });
}

if (opt.clean) {
// We want to keep .gitkeep
const regex = /[.]gitkeep$/;
readdirSync(resolve(browserPath))
.filter((f) => !regex.test(f))
.map((f) => unlinkSyncResolve(browserPath, f));
}
});

program.parse();

function unlinkSyncResolve(...pathSegments) {
const pth = resolve(...pathSegments);
// Maybe additional check if exists?
rmSync(pth, { recursive: true, force: true });
console.log(`Removed \x1b[32m${pth}\x1b[39m`);
}
148 changes: 144 additions & 4 deletions Website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion Website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
"web:dev": "webpack --config webpack.dev.ts",
"web:prod": "webpack --config webpack.prod.ts && rm ./../Android/app/src/main/assets/**/*.map",
"app:dev": "npm run web:dev && cd ../Android && ./gradlew installDebug",
"util:licenses": "npm license.ts > ./src/utils/licenses.json && cd ../Android && ./gradlew app:printSolvedDepsTreeInJson"
"assetfix:android-build": "node assetsfix.js android --build",
"assetfix:android-clean": "node assetsfix.js android --clean",
"assetfix:web-build": "node assetsfix.js web --build",
"assetfix:web-clean": "node assetsfix.js web --clean"
},
"resolutions": {
"react": "^18.2.0",
Expand Down Expand Up @@ -59,6 +62,7 @@
"@babel/core": "^7.16.5",
"@babel/preset-env": "^7.16.5",
"@babel/preset-react": "^7.16.5",
"@types/fs-extra": "^11.0.1",
"@types/node": "^18.0.6",
"@types/object-assign": "^4.0.30",
"@types/react": "^18.2.8",
Expand All @@ -69,9 +73,11 @@
"@types/underscore": "^1.11.5",
"@types/webpack": "^5.28.0",
"babel-loader": "^8.2.3",
"commander": "^11.0.0",
"css-loader": "^6.5.1",
"css-minimizer-webpack-plugin": "^4.0.0",
"file-loader": "^6.2.0",
"fs-extra": "^11.1.1",
"js-yaml-loader": "^1.2.2",
"license-checker": "^25.0.1",
"mini-css-extract-plugin": "^2.5.3",
Expand Down
Loading

0 comments on commit defaa23

Please sign in to comment.