diff --git a/README.md b/README.md index 9b13bda..9c5ff00 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A browser extension that automatically gets rid of sticky elements on websites y ### Building from source -You can build the extension from source, using the provided `build.sh` script, passing the argument `chrome` (for Chrome, Opera, Vivaldi, etc.) or `firefox` (for Firefox & other Gecko-based browsers). +You can build the extension from source, using the provided `build.php` script. ### Post-installation diff --git a/build.php b/build.php new file mode 100644 index 0000000..20b8acc --- /dev/null +++ b/build.php @@ -0,0 +1,56 @@ + | all } +## ('all' builds for all available platforms) +## +## This script will create build/ and build/ if needed, then will +## copy files from src/ and src/platform/ into build//. +## The extension can then be loaded from build/. + +## No platform specified. +if ($argc < 2) { + echo "Syntax is:\n"; + echo "\tphp build.php { | all }\n"; +} + +## Determine path to repository root. +$root = preg_replace('/\/[^\/]+$/', '', dirname(__FILE__)); + +## Determine what platforms are available. +$platforms = array_filter(scandir("{$root}/src/platform/"), function ($str) { + return strncmp($str, ".", 1); +}); + +## No platform specified, or specified platform does not exist. +## NOTE: specifying 'all' will build for all platforms. +if ($argc < 2 || !(in_array($argv[1], $platforms) || $argv[1] == "all")) { + echo "Available platforms are:\n"; + foreach ($platforms as $platform) + echo "\t{$platform}\n"; + die; +} + +## Build for specified platform (or for all platforms, if 'all' is given). +if ($argv[1] == "all") { + foreach ($platforms as $platform) { + build_for_platform($platform); + } +} else { + build_for_platform($argv[1]); +} + +function build_for_platform($platform) { + global $root; + echo "Building for: {$platform}\n"; + + $command = "cd {$root}; "; + $command .= "mkdir -p build/{$platform}; "; + $command .= "rm -rf build/{$platform}/*; "; + $command .= "cp -R src/{*.js,*.html,*.css,fonts,images} build/{$platform}/; "; + $command .= "cp -R src/platform/{$platform}/* build/{$platform}/"; + + `{$command}`; +} + +?> \ No newline at end of file diff --git a/build.sh b/build.sh deleted file mode 100755 index 6c91683..0000000 --- a/build.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -mkdir -p build/$1 -rm -rf build/$1/* -cp -R src/{*.js,*.html,*.css,fonts,images} build/$1/ -cp -R src/platform/$1/* build/$1/ diff --git a/util/README-UTIL.md b/util/README-UTIL.md index eaf4776..62fc1f1 100644 --- a/util/README-UTIL.md +++ b/util/README-UTIL.md @@ -2,15 +2,11 @@ This folder contains some convenience scripts. They’re mostly for me, but may be useful for anyone who wants to contribute to developing AlwaysKillSticky, so they’re documented here for completeness. -## `build-all.php` - -Runs `build.sh` with all available platforms. This will create a `build/` directory (in the root directory of the repository) and subdirectories for each platform, and copy files from `src/` into those subdirectories. The extension can then be loaded from those subdirectories by the appropriate kind of browser. - ## `package.php` Will create `.tar.gz` and `.zip` archives in the `release/` directory (creating it if needed) of the built extension for each platform (in `build/`). The archives will be named according to platform and version (read from `manifest.json` in each platform’s build directory). -Passing the `-b` flag will run `build-all.php` first, before packaging. +Passing the `-b` flag will run `build.php all` first, before packaging. ## `compute_FontAwesome_subset.php` diff --git a/util/build-all.php b/util/build-all.php deleted file mode 100644 index 2e9d771..0000000 --- a/util/build-all.php +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/util/package.php b/util/package.php index ac8f3d6..8794406 100644 --- a/util/package.php +++ b/util/package.php @@ -1,14 +1,14 @@