Skip to content

Commit b6a5f3c

Browse files
committed
Move build scripts into their own directory
1 parent 2bc3ba4 commit b6a5f3c

10 files changed

Lines changed: 75 additions & 46 deletions

File tree

.github/workflows/browser-extension-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Get version from git tag
4545
id: get-version
4646
run: |
47-
VERSION=$(node get-version.js)
47+
VERSION=$(npm run --silent get-version)
4848
if [[ -z "$VERSION" ]]; then
4949
echo "❌ Version extraction failed"
5050
exit 1

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ We have the following commands:
197197
* `npm run package-all`: Convenience command to run `npm run build`, `npm run package-chrome`, and `npm run package-firefox`. Intended for use when running locally.
198198
* `npm run dev-firefox`: Builds the extension and launches a Firefox window that has the extension temporarily installed, to help with testing during development. Intended for use when running locally.
199199
* `npm run lint-firefox`: Performs some of the same basic validations that the Firefox Add-on Hub enforces. Used to validate the addon before submitting it to Mozilla for signing. Runs both locally and in CI jobs.
200+
* `npm run get-version`: Tries to determine the target version number of browser extension builds. If the current git SHA is tagged with our semantic versioning scheme (`v1.2.3`), outputs that number without the `v` prefix (`1.2.3`) as the desired version. Otherwise falls back to using the version defined in `package.json`. Intended to be used in CI jobs.
200201

201202
## Contributing
202203

browser-extension/clean.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

browser-extension/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"version": "0.0.1",
44
"description": "Browser extensions for the Stream Deck Google Meet plugin",
55
"scripts": {
6-
"build": "node build.js",
7-
"clean": "node clean.js",
8-
"package-chrome": "node package-chrome.js",
6+
"build": "node scripts/build.js",
7+
"clean": "node scripts/clean.js",
8+
"package-chrome": "node scripts/package-chrome.js",
99
"package-firefox": "web-ext build --source-dir=build/firefox --artifacts-dir=build --filename=firefox-extension.zip --overwrite-dest",
1010
"sign-firefox": "web-ext sign --channel=unlisted --source-dir=build/firefox --artifacts-dir=build",
1111
"package-all": "npm run build && npm run package-chrome && npm run package-firefox",
1212
"lint-firefox": "web-ext lint --source-dir=build/firefox",
13-
"dev-firefox": "npm run build && web-ext run --source-dir=build/firefox --browser-console --start-url https://meet.google.com/"
13+
"dev-firefox": "npm run build && web-ext run --source-dir=build/firefox --browser-console --start-url https://meet.google.com/",
14+
"get-version": "node scripts/get-version.js"
1415
},
1516
"devDependencies": {
1617
"web-ext": "^8.9.0"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This directory contains scripts used during development or in CI jobs.
2+
3+
Nothing in this directory should be referenced during runtime of the browser extension.
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
const fs = require('fs');
22
const path = require('path');
33
const { getVersion } = require('./get-version');
4+
const { buildDir, chromeDir, firefoxDir, projectRoot } = require('./directories');
45

56
// Get version from git tag
67
const version = getVersion();
78
console.log(`Using version: ${version}`);
89

9-
// These directories are where we'll output our build artifacts:
10-
const buildDir = path.join(__dirname, 'build');
11-
const chromeDir = path.join(buildDir, 'chrome');
12-
const firefoxDir = path.join(buildDir, 'firefox');
13-
1410
// Ensure build directories exist
1511
if (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir);
1612
if (!fs.existsSync(chromeDir)) fs.mkdirSync(chromeDir);
@@ -70,14 +66,14 @@ copyFiles(sourceFilesInManifest, firefoxDir);
7066

7167
// Copy and update manifest files with dynamic version
7268
updateManifestVersion(
73-
path.join(__dirname, 'manifest.json'),
69+
path.join(projectRoot, 'manifest.json'),
7470
path.join(chromeDir, 'manifest.json'),
7571
version
7672
);
7773
// For Firefox, we use our Chrome manifest as a base and inject Firefox-specific fields
7874
renderFirefoxManifest(
79-
path.join(__dirname, 'manifest.json'),
80-
path.join(__dirname, 'manifest_firefox_stub.json'),
75+
path.join(projectRoot, 'manifest.json'),
76+
path.join(projectRoot, 'manifest_firefox_stub.json'),
8177
path.join(firefoxDir, 'manifest.json'),
8278
version
8379
);

browser-extension/scripts/clean.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* A platform-agnostic script to clean out old build artifacts.
3+
*/
4+
5+
const fs = require('fs');
6+
const path = require('path');
7+
const { projectRoot } = require('./directories');
8+
9+
// Which files/folders to delete, relative to the browser extension project root (where package.json is).
10+
const PATHS_TO_DELETE = [
11+
"build"
12+
]
13+
14+
function deleteRecursive(pathToDelete) {
15+
if (fs.existsSync(pathToDelete)) {
16+
console.log(`Deleting "${pathToDelete}"...`);
17+
fs.rmSync(pathToDelete, { recursive: true });
18+
}
19+
}
20+
21+
console.log('Cleaning browser-extension working tree...');
22+
23+
PATHS_TO_DELETE.forEach((pathToDelete) => {
24+
deleteRecursive(path.join(projectRoot, pathToDelete));
25+
});
26+
27+
console.log('Successfully cleaned working tree!');
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Define important build paths that are shared across build scripts.
3+
*/
4+
5+
const path = require('path');
6+
7+
// The root of the project, i.e. where package.json lives.
8+
const projectRoot = path.join(__dirname, '..');
9+
10+
// The directory to which we write all build artifacts.
11+
const buildDir = path.join(projectRoot, 'build');
12+
13+
// Where our built artifacts for Chrome get written.
14+
const chromeDir = path.join(buildDir, 'chrome');
15+
16+
// Where our built artifacts for Firefox get written.
17+
const firefoxDir = path.join(buildDir, 'firefox');
18+
19+
// Export for use in other scripts
20+
module.exports = {
21+
buildDir,
22+
chromeDir,
23+
firefoxDir,
24+
projectRoot
25+
};
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { execSync } = require('child_process');
22
const fs = require('fs');
33
const path = require('path');
4+
const { projectRoot } = require('./directories');
45

56
function getVersion() {
67
try {
@@ -15,7 +16,7 @@ function getVersion() {
1516
} catch (error) {
1617
// Fallback to package.json version
1718
console.warn('Warning: No git tags found. Using package.json version.');
18-
const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, 'package.json'), 'utf8'));
19+
const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
1920
return packageJson.version;
2021
}
2122
}

browser-extension/package-chrome.js renamed to browser-extension/scripts/package-chrome.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
const fs = require('fs');
22
const path = require('path');
33
const { execSync } = require('child_process');
4+
const { buildDir, chromeDir } = require('./directories');
45

5-
const buildDir = path.join(__dirname, 'build');
6-
const chromeDir = path.join(buildDir, 'chrome');
76
const outputFile = path.join(buildDir, 'chrome-extension.zip');
87

98
// Check if chrome build directory exists
@@ -21,21 +20,21 @@ try {
2120
// Try to use zip command first (available on Linux and macOS)
2221
if (process.platform !== 'win32') {
2322
console.log('📦 Creating Chrome extension zip with zip command...');
24-
execSync('zip -r ../chrome-extension.zip *', {
23+
execSync('zip -r ../chrome-extension.zip *', {
2524
cwd: chromeDir,
26-
stdio: 'inherit'
25+
stdio: 'inherit'
2726
});
2827
} else {
2928
// On Windows, use PowerShell
3029
console.log('📦 Creating Chrome extension zip with PowerShell...');
31-
execSync('powershell -Command "Compress-Archive -Path * -DestinationPath ../chrome-extension.zip -Force"', {
30+
execSync('powershell -Command "Compress-Archive -Path * -DestinationPath ../chrome-extension.zip -Force"', {
3231
cwd: chromeDir,
33-
stdio: 'inherit'
32+
stdio: 'inherit'
3433
});
3534
}
36-
35+
3736
console.log('✅ Chrome extension packaged successfully: build/chrome-extension.zip');
3837
} catch (error) {
3938
console.error('❌ Failed to create Chrome extension zip:', error.message);
4039
process.exit(1);
41-
}
40+
}

0 commit comments

Comments
 (0)