Skip to content

Commit 365daa5

Browse files
authored
🔀 Merge pull request #380 from richardfrost/build_improvements
Add additional release state file to preserve `.build.json`.
2 parents 144c8a8 + 2c351e8 commit 365daa5

File tree

9 files changed

+159
-55
lines changed

9 files changed

+159
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ bin/git-filters/*.js
66

77
# Build state file
88
/.build.json
9+
/.release.json
910

1011
# Packaged extensions
1112
/dist/*

README.md

Lines changed: 59 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ A browser extension to filter profanity from webpages.
1010

1111
For an overview of features and options, please head to the [wiki](https://github.com/richardfrost/AdvancedProfanityFilter/wiki).
1212

13-
### Installation
13+
## Installation
1414
| Browser | Download |
1515
|---------|----------|
1616
| Chrome | [Chrome Web Store](https://chrome.google.com/webstore/detail/advanced-profanity-filter/piajkpdbaniagacofgklljacgjhefjeh) |
@@ -22,7 +22,7 @@ For an overview of features and options, please head to the [wiki](https://githu
2222
| iOS/Other | [Bookmarklet Info](https://github.com/richardfrost/AdvancedProfanityFilter/wiki/Bookmarklet) |
2323
| TV Cast | [Instructions](https://github.com/richardfrost/AdvancedProfanityFilter/wiki/Audio#watch-on-tv) - [Discussion](https://github.com/richardfrost/AdvancedProfanityFilter/issues/206) |
2424

25-
### Features
25+
## Features
2626
* Filter modes
2727
* Censor - Hide offending words
2828
* Substitute - Replace offensive words
@@ -44,22 +44,69 @@ For an overview of features and options, please head to the [wiki](https://githu
4444

4545
For a detailed overview of the features and settings, please see the [Getting Started page](https://github.com/richardfrost/AdvancedProfanityFilter/wiki).
4646

47-
### Issues, Suggestions or Feedback?
47+
## Issues, Suggestions or Feedback?
4848
* Found a bug? Please open an [issue](https://github.com/richardfrost/AdvancedProfanityFilter/issues/new).
4949
* Have a great idea to improve the project? Want to share some feedback? Head over [here](https://goo.gl/forms/LTqFpJ0mCTsrgGgf2).
5050

51-
### Beta Testing
51+
## Beta Testing
5252
If you would like to help with development, but don't have experience coding, its very helpful to have users test a release candidate before actually publishing it to everyone. If you are interested in testing new versions see [this page](https://github.com/richardfrost/AdvancedProfanityFilter/wiki/Beta-Testing) for more information.
5353

54-
### Development
55-
This project is written in TypeScript, and during the build/package process it will be converted to JS. Please see `package.json`'s scripts for more info on the process.
54+
## Development
55+
### Quick Start
56+
After downloading/cloning the repository, run the following commands to get started:
5657

57-
Getting started
58-
```
58+
```sh
59+
# Install dependencies
5960
npm install
60-
```
6161

62-
To Build the extension
63-
```
64-
npm run package
62+
# Build the extension for the default target browser for local development
63+
# See table below for supported targets
64+
npm run build
6565
```
66+
Once the extension has been built, you can load the unpacked extension (found in `dist/`) in your browser.
67+
68+
### Stages
69+
| Stage | Output | Description |
70+
|---------|--------------------------|---------------------------------------------------|
71+
| build | `dist/` | Build/compile the extension for local development |
72+
| package | `extension-target.zip` | Package the files for the target browser |
73+
| release | `extension-target.zip` | Create an official release for a target browser |
74+
75+
### Targets
76+
| Target | Browser |
77+
|---------|--------------------|
78+
| v3* | Chrome, Edge, etc. |
79+
| v2 | Chrome, Edge, etc. |
80+
| firefox | Firefox |
81+
| safari | Safari (MacOS/iOS) |
82+
83+
_* = default target_
84+
85+
### Scripts
86+
For all scripts, please see `package.json`.
87+
88+
#### Commonly used scripts
89+
| Target | Stage | Script | Description |
90+
|---------|---------|--------------------------|-----------------------------------|
91+
| v3 | build | `npm run build:v3` | Development build for Manifest V3 |
92+
| v2 | build | `npm run build:v2` | Development build for Manifest V2 |
93+
| firefox | build | `npm run build:firefox` | Development build for Firefox |
94+
| safari | build | `npm run build:safari` | Development build for Safari |
95+
| safari | release | `npm run package:safari` | Official release for safari |
96+
| | release | `npm run release:all` | Official relase for all targets |
97+
98+
### State files
99+
The state files hold the details about the current build. These files are managed by `bin/prebuild.mjs`.
100+
101+
- `.build.json`
102+
- Current development target details
103+
- This is used for active development, and allows the developer to run simple commands such as `npm run build` to rebuild the project for the target specified in the file
104+
- `.release.json`
105+
- Current release target details
106+
- Takes precedence over `.build.json`, but gets removed after release is finished
107+
108+
#### Details contained in state files:
109+
- `config`: Overrides for the target
110+
- `manifestVersion`: Manifest version from `src/static/manifest.json`
111+
- `target`: Target browser
112+
- `version`: Build version from `package.json`

bin/clean.mjs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ const dist = [
1212
path.join('dist-lib'),
1313
];
1414

15+
const release = [
16+
path.join('./.release.json'),
17+
];
18+
1519
const test = [
1620
path.join('test', 'built'),
1721
];
1822

19-
function clean(folders) {
20-
folders.forEach((folder) => {
21-
console.log(`Cleaning ${folder}...`);
22-
fse.removeSync(folder);
23+
function clean(items) {
24+
items.forEach((item) => {
25+
console.log(`Cleaning ${item}...`);
26+
fse.removeSync(item);
2327
});
2428
}
2529

@@ -29,26 +33,29 @@ function main() {
2933
// argv[1] = script (this file)
3034
// argv[2] = first argument
3135
if (process.argv.length >= 2) {
32-
const args = process.argv.slice(2);
33-
let folders = [];
34-
36+
let args = process.argv.slice(2);
3537
if (args.length == 0 || args.includes('--all')) {
36-
folders = folders.concat(built).concat(dist).concat(test);
37-
} else {
38-
if (args.includes('--built')) {
39-
folders = folders.concat(built);
40-
}
38+
args = ['--built', '--dist', '--release', '--test'];
39+
}
4140

42-
if (args.includes('--dist')) {
43-
folders = folders.concat(dist);
44-
}
41+
let toRemove = [];
42+
if (args.includes('--built')) {
43+
toRemove = toRemove.concat(built);
44+
}
45+
46+
if (args.includes('--dist')) {
47+
toRemove = toRemove.concat(dist);
48+
}
49+
50+
if (args.includes('--release')) {
51+
toRemove = toRemove.concat(release);
52+
}
4553

46-
if (args.includes('--test')) {
47-
folders = folders.concat(test);
48-
}
54+
if (args.includes('--test')) {
55+
toRemove = toRemove.concat(test);
4956
}
5057

51-
clean(folders);
58+
clean(toRemove);
5259
} else {
5360
usage();
5461
}
@@ -61,7 +68,10 @@ function main() {
6168
function usage() {
6269
console.log(`usage:
6370
npm run clean
71+
npm run clean:built
6472
npm run clean:dist
73+
npm run clean:release
74+
npm run clean:test
6575
`);
6676
}
6777

bin/package-extension.mjs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import fse from 'fs-extra';
33
import path from 'path';
44
import AdmZip from 'adm-zip';
55

6+
let buildData;
67
const buildDataPath = path.join('.build.json');
78
const dist = './dist/';
8-
let buildData;
9+
const releaseFilePath = path.join('.release.json');
910

1011
function buildArchive() {
1112
const zip = new AdmZip();
@@ -24,7 +25,13 @@ function loadJSONFile(file) {
2425

2526
function main() {
2627
try {
27-
buildData = loadJSONFile(buildDataPath);
28+
// Load .release.json if present, otherwise load .build.json
29+
if (fse.existsSync(releaseFilePath)) {
30+
buildData = loadJSONFile(releaseFilePath);
31+
} else {
32+
buildData = loadJSONFile(buildDataPath);
33+
}
34+
2835
const zip = buildArchive();
2936
const packagePath = `./${zipName()}.zip`;
3037
console.log(`Building ${packagePath}`);

bin/package-source.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import AdmZip from 'adm-zip';
77
function packageSource() {
88
fse.removeSync('./extension-source.zip');
99
console.log('Building ./extension-source.zip');
10-
console.log('Build from source: npm install && npm run package:firefox');
10+
console.log('Build from source: npm install && npm run build:bookmarklet && npm run package:firefox');
11+
console.log(' Unpacked: ./dist');
12+
console.log(' Packed: ./extension-firefox.zip');
1113

1214
const sourceZip = new AdmZip();
1315
const files = [

bin/postbuild.mjs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
import fse from 'fs-extra';
44
import path from 'path';
55

6+
let buildData;
67
const buildDataPath = path.join('.build.json');
78
const manifestPath = path.join('dist', 'manifest.json');
9+
const releaseFilePath = path.join('.release.json');
10+
const srcManifestPath = path.join('src', 'static', 'manifest.json');
811

912
function common() {
1013
handleManifestVersion();
@@ -56,6 +59,11 @@ function handleVersion() {
5659
console.log(`Updating manifest.json version (${manifest.version} -> ${buildData.version})`);
5760
manifest.version = buildData.version;
5861
writeJSONFile(manifestPath, manifest);
62+
63+
// Update source manfiest.json
64+
const srcManifest = loadJSONFile(srcManifestPath);
65+
srcManifest.version = buildData.version;
66+
writeJSONFile(srcManifestPath, srcManifest);
5967
}
6068
}
6169

@@ -64,7 +72,14 @@ function loadJSONFile(file) {
6472
}
6573

6674
function main() {
67-
buildData = loadJSONFile(buildDataPath);
75+
// Load .release.json if present, otherwise load .build.json
76+
if (fse.existsSync(releaseFilePath)) {
77+
buildData = loadJSONFile(releaseFilePath);
78+
} else {
79+
buildData = loadJSONFile(buildDataPath);
80+
}
81+
82+
// Perform postbuild actions
6883
common();
6984

7085
if (buildData.target == 'firefox') {
@@ -130,5 +145,4 @@ function writeJSONFile(file, object) {
130145
fse.writeFileSync(file, content);
131146
}
132147

133-
let buildData;
134148
main();

bin/prebuild.mjs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const data = {
1212
target: 'chrome',
1313
version: '1.0.0',
1414
};
15+
const releaseFilePath = path.join('.release.json');
1516

1617
function common() {
1718
data.version = process.env.npm_package_version;
@@ -29,16 +30,25 @@ function main() {
2930
// argv[0] = process (node)
3031
// argv[1] = script (this file)
3132
// argv[2] = first argument
32-
if (process.argv.length == 2 || process.argv.length == 3) {
33-
const arg = process.argv.slice(2)[0];
34-
// Exit if no arg passed and .build.json already exists
35-
if (!arg && fse.existsSync(buildFilePath)) {
33+
if (process.argv.length >= 2 && process.argv.length <= 4) {
34+
const args = process.argv.slice(2);
35+
const release = args.includes('--release');
36+
if (release) {
37+
args.splice(args.indexOf('--release'), 1);
38+
} else if (fse.existsSync(releaseFilePath)) {
39+
// Remove .release.json if it exists when not prepareing for a release build
40+
fse.removeSync(releaseFilePath);
41+
}
42+
const target = args[0];
43+
44+
// Exit if no target was passed and .build.json already exists (preserve current build target)
45+
if (!target && fse.existsSync(buildFilePath)) {
3646
return;
3747
}
3848

3949
common();
4050

41-
switch (arg) {
51+
switch (target) {
4252
case '--firefox':
4353
firefoxBuild();
4454
break;
@@ -54,7 +64,7 @@ function main() {
5464
default:
5565
defaultBuild();
5666
}
57-
writeData();
67+
writeData(release);
5868
} else {
5969
throw (new Error('Incorrect number of arguments.'));
6070
}
@@ -73,9 +83,10 @@ function safariBuild() {
7383
data.config.muteMethod = 2; // Constants.MUTE_METHODS.VIDEO_MUTE;
7484
}
7585

76-
function writeData() {
86+
function writeData(release = false) {
87+
const filePath = release ? releaseFilePath : buildFilePath;
7788
const content = JSON.stringify(data, null, 2);
78-
fse.writeFileSync(buildFilePath, content);
89+
fse.writeFileSync(filePath, content);
7990
}
8091

8192
main();

package.json

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,24 @@
2929
"build:v3": "node bin/prebuild.mjs --manifestV3 && npm run build",
3030
"build": "npm run build:static && webpack --config bin/webpack.config.js",
3131
"clean:dist": "node bin/clean.mjs --dist",
32+
"clean:release": "node bin/clean.mjs --release",
3233
"clean": "node bin/clean.mjs --all",
33-
"package:firefox": "npm run build:firefox && npm run package",
34-
"package:v2": "npm run build:v2 && npm run package",
35-
"package:v3": "npm run build:v3 && npm run package",
36-
"package": "npm run build:bookmarklet && node bin/package-extension.mjs",
34+
"package:firefox": "npm run clean:release && node bin/prebuild.mjs --release --firefox && npm run release:build && npm run package",
35+
"package:v2": "npm run clean:release && node bin/prebuild.mjs --release --manifestV2 && npm run release:build && npm run package",
36+
"package:v3": "npm run clean:release && node bin/prebuild.mjs --release --manifestV3 && npm run release:build && npm run package",
37+
"package": "node bin/package-extension.mjs",
3738
"postbuild": "node bin/postbuild.mjs",
38-
"postpackage:firefox": "node bin/package-source.mjs",
39+
"postpackage": "npm run clean:release",
40+
"postrelease:build": "node bin/postbuild.mjs",
41+
"postrelease:firefox": "node bin/package-source.mjs",
3942
"prebuild": "node bin/prebuild.mjs",
40-
"release": "npm run clean && npm run package:v2 && npm run package:v3 && npm run package:firefox && npm run update:bookmarklet",
41-
"test:addon": "npx addons-linter ./extension-firefox.zip",
43+
"release:all": "npm run clean && npm run build:bookmarklet && npm run release:v3 && npm run release:v2 && npm run release:firefox && npm run update:bookmarklet",
44+
"release:build": "npm run build:static && webpack --config bin/webpack.config.js",
45+
"release:firefox": "npm run package:firefox",
46+
"release:safari": "npm run clean && node bin/prebuild.mjs --release --safari && npm run release:build && npm run clean:release",
47+
"release:v2": "npm run package:v2",
48+
"release:v3": "npm run package:v3",
49+
"test:addon": "npm run package:firefox && npx addons-linter ./extension-firefox.zip",
4250
"test:all": "npm run test && npm run test:lint:tests",
4351
"test:cov": "npm run build:test && nyc --reporter=lcov --reporter=text node_modules/mocha/bin/_mocha",
4452
"test:debug": "node --inspect-brk node_modules/mocha/bin/_mocha --reporter tap",

src/static/manifest.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"short_name": "Profanity Filter",
44
"author": "Richard Frost",
55
"manifest_version": 3,
6-
"version": "2.30.0",
6+
"version": "2.31.0",
77
"description": "Advanced Profanity Filter helps to clean up bad language on the websites you and your family visit.",
88
"icons": {
99
"16": "img/icon16.png",
@@ -46,8 +46,12 @@
4646
},
4747
"web_accessible_resources": [
4848
{
49-
"resources": [ "audio/*.mp3" ],
50-
"matches": [ "<all_urls>" ]
49+
"resources": [
50+
"audio/*.mp3"
51+
],
52+
"matches": [
53+
"<all_urls>"
54+
]
5155
}
5256
]
53-
}
57+
}

0 commit comments

Comments
 (0)