Skip to content

Commit 197e540

Browse files
authored
Merge pull request #306 from richardfrost/updates
Update Dev Dependencies
2 parents a1049ed + 1b30b3f commit 197e540

11 files changed

+7502
-10606
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ language: node_js
22

33
node_js:
44
- "node"
5-
- "15"
5+
- "16"
66

77
before_script:
88
- npm install
99
- npm run package
1010

1111
script:
12+
- npm run test:lint:all
1213
- npm run test:all

bin/bookmarklet.webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
const TerserPlugin = require("terser-webpack-plugin");
1+
/* eslint-disable @typescript-eslint/naming-convention */
2+
const TerserPlugin = require('terser-webpack-plugin'); // eslint-disable-line @typescript-eslint/no-var-requires
23

34
module.exports = {
45
entry: {

bin/clean.js

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

bin/clean.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* eslint-disable no-console */
2+
import fse from 'fs-extra';
3+
4+
const folders = ['./dist', './test/built', './extension', './extension-chrome', './extension-firefox'];
5+
folders.forEach((folder) => {
6+
console.log(`Cleaning ${folder}...`);
7+
fse.removeSync(folder);
8+
});

bin/copy-static.js renamed to bin/copy-static.mjs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
'use strict';
1+
/* eslint-disable no-console */
2+
import fse from 'fs-extra';
23

3-
// eslint-disable-next-line
4-
const fse = require('fs-extra');
5-
6-
// eslint-disable-next-line no-console
74
console.log('Copying static assets to ./dist folder...');
85
fse.copySync('./src/static', './dist');
96
fse.copySync('./src/audio', './dist/audio');

bin/package-extension.js renamed to bin/package-extension.mjs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
/* eslint-disable no-console, @typescript-eslint/no-var-requires */
2-
'use strict';
3-
const fse = require('fs-extra');
4-
const path = require('path');
5-
const AdmZip = require('adm-zip');
1+
/* eslint-disable no-console */
2+
import fse from 'fs-extra';
3+
import path from 'path';
4+
import AdmZip from 'adm-zip';
65

76
function buildAll() {
87
build(prepareZip());
@@ -13,7 +12,7 @@ function buildAll() {
1312

1413
function build(zip, name = '') {
1514
if (name) { name = '-' + name; }
16-
let packagePath = `./extension${name}.zip`;
15+
const packagePath = `./extension${name}.zip`;
1716
console.log(`Building ${packagePath}`);
1817
fse.removeSync(packagePath);
1918
zip.writeZip(packagePath);
@@ -24,21 +23,20 @@ function buildBookmarklet() {
2423
}
2524

2625
function buildEdgeLegacy(manifest, zip) {
27-
let packagePath = './extension-edge-legacy.zip';
26+
const packagePath = './extension-edge-legacy.zip';
2827
console.log(`Building ${packagePath}`);
2928

3029
if (!fse.existsSync('./store/edge')) {
3130
console.log('Error! Missing Edge legacy polyfills.');
3231
return false;
3332
}
3433

35-
let msPreload = {
34+
const msPreload = {
3635
backgroundScript: 'backgroundScriptsAPIBridge.js',
3736
contentScript: 'contentScriptsAPIBridge.js'
3837
};
3938

4039
// Fix options_page
41-
// eslint-disable-next-line @typescript-eslint/camelcase
4240
manifest.options_page = manifest.options_ui.page;
4341
delete manifest.options_ui;
4442

@@ -52,9 +50,9 @@ function buildEdgeLegacy(manifest, zip) {
5250
}
5351

5452
function buildFirefox(manifest, zip) {
55-
let packagePath = './extension-firefox.zip';
53+
const packagePath = './extension-firefox.zip';
5654
console.log(`Building ${packagePath}`);
57-
let firefoxManifest = {
55+
const firefoxManifest = {
5856
applications: {
5957
gecko: {
6058
id: '{853d1586-e2ab-4387-a7fd-1f7f894d2651}'
@@ -78,8 +76,8 @@ function packageSource() {
7876
console.log('Building ./extension-source.zip');
7977
console.log('Build from source: npm install && npm run package');
8078

81-
let sourceZip = new AdmZip();
82-
let files = [
79+
const sourceZip = new AdmZip();
80+
const files = [
8381
'LICENSE',
8482
'package.json',
8583
'package-lock.json',
@@ -89,23 +87,23 @@ function packageSource() {
8987
sourceZip.addLocalFolder('./bin', 'bin');
9088
sourceZip.addLocalFolder('./src', 'src');
9189
sourceZip.addLocalFolder('./test', 'test');
92-
files.forEach(file => { sourceZip.addLocalFile(path.join('./', file), null); });
90+
files.forEach((file) => { sourceZip.addLocalFile(path.join('./', file), null); });
9391
sourceZip.writeZip('./extension-source.zip');
9492
}
9593

9694
function prepareZip() {
97-
let zip = new AdmZip();
95+
const zip = new AdmZip();
9896
zip.addLocalFolder(dist, null);
9997
return zip;
10098
}
10199

102100
function updateManifestFile(file, obj) {
103-
let content = JSON.stringify(obj, null, 2);
101+
const content = JSON.stringify(obj, null, 2);
104102
fse.writeFileSync(file, content);
105103
}
106104

107105
function updateManifestFileInZip(zip, obj) {
108-
let content = JSON.stringify(obj, null, 2);
106+
const content = JSON.stringify(obj, null, 2);
109107
zip.updateFile('manifest.json', Buffer.alloc(content.length, content));
110108
}
111109

@@ -117,12 +115,12 @@ function updateManifestVersion(manifest, newVersion) {
117115
}
118116

119117
function updateOptionPageVersion(newVersion) {
120-
let filename = 'optionPage.html';
121-
let optionPage = path.join(staticDir, filename);
122-
let optionPageHTML = fse.readFileSync(optionPage).toString();
118+
const filename = 'optionPage.html';
119+
const optionPage = path.join(staticDir, filename);
120+
const optionPageHTML = fse.readFileSync(optionPage).toString();
123121
let foundMatch = false;
124122

125-
let newOptionPageHTML = optionPageHTML.replace(/id="helpVersion">.*?<\/a>/, function(match) {
123+
const newOptionPageHTML = optionPageHTML.replace(/id="helpVersion">.*?<\/a>/, function(match) {
126124
foundMatch = true;
127125
return `id="helpVersion">${newVersion}</a>`;
128126
});
@@ -137,9 +135,9 @@ function updateOptionPageVersion(newVersion) {
137135
}
138136

139137
function updateVersions() {
140-
let manifest = getManifestJSON();
138+
const manifest = getManifestJSON();
141139
if (manifest.version != process.env.npm_package_version) {
142-
let newVersion = process.env.npm_package_version;
140+
const newVersion = process.env.npm_package_version;
143141
console.log('Version number is being updated: ' + manifest.version + ' -> ' + newVersion);
144142
updateManifestVersion(manifest, newVersion);
145143
updateOptionPageVersion(newVersion);
@@ -148,6 +146,6 @@ function updateVersions() {
148146

149147
const dist = './dist/';
150148
const staticDir = './src/static/';
151-
let manifestPath = path.join(staticDir, 'manifest.json');
149+
const manifestPath = path.join(staticDir, 'manifest.json');
152150
updateVersions();
153151
buildAll();

bin/update-help.js

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

bin/update-help.mjs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* eslint-disable no-console */
2+
import fse from 'fs-extra';
3+
import path from 'path';
4+
import marked from 'marked';
5+
import download from 'download';
6+
7+
const readmeURI = 'https://raw.githubusercontent.com/wiki/richardfrost/AdvancedProfanityFilter/Home.md';
8+
const optionPage = path.join('src/static', 'optionPage.html');
9+
const optionPageHTML = fse.readFileSync(optionPage).toString();
10+
const prefix = '<div id="helpContainer">';
11+
const postfix = '\n </div>';
12+
let foundMatch = false;
13+
14+
console.log('Downloading Wiki...');
15+
download(readmeURI).then((data) => {
16+
console.log('Parsing markdown...');
17+
const md = data.toString();
18+
const html = marked(md);
19+
20+
const newOptionPageHTML = optionPageHTML.replace(/<div id="helpContainer">.*?<\/div>/s, function(match) {
21+
foundMatch = true;
22+
let output = prefix;
23+
html.split('\n').forEach((line) => { if (line.trim() != '') output += `\n ${line}`; });
24+
return output + postfix;
25+
});
26+
if (foundMatch) {
27+
console.log('Updating Help content...');
28+
fse.writeFileSync(optionPage, newOptionPageHTML);
29+
} else {
30+
throw `Failed to update ${optionPage}`;
31+
}
32+
});
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
'use strict';
1+
/* eslint-disable no-console */
2+
import fse from 'fs-extra';
3+
import path from 'path';
4+
import chokidar from 'chokidar';
5+
import { execSync } from 'child_process';
26

3-
const chokidar = require('chokidar');
4-
const execSync = require('child_process').execSync;
5-
const path = require('path');
6-
const fse = require('fs-extra');
7-
let scriptRegExp = new RegExp('\/script\/');
8-
let staticRegExp = new RegExp('\/static\/');
7+
const scriptRegExp = new RegExp('\/script\/');
8+
const staticRegExp = new RegExp('\/static\/');
99

1010
function copyStatic(file) {
11-
let basename = path.basename(file);
11+
const basename = path.basename(file);
1212
console.log('Copying static file: ', basename);
1313
fse.copySync(file, path.join('./dist/', basename));
1414

@@ -20,8 +20,8 @@ function copyStatic(file) {
2020
}
2121

2222
function compileScript(file) {
23-
let basename = path.basename(file);
24-
console.log('TypeScript file updated: ', basename)
23+
const basename = path.basename(file);
24+
console.log('TypeScript file updated: ', basename);
2525

2626
try {
2727
console.log('Building Typescript...');
@@ -32,7 +32,7 @@ function compileScript(file) {
3232
}
3333
}
3434

35-
let watcher = chokidar.watch(
35+
const watcher = chokidar.watch(
3636
[
3737
path.join(process.cwd() + '/src/**/*.ts'),
3838
path.join(process.cwd() + '/src/static/**/*.(css|html|json|)')
@@ -42,7 +42,7 @@ let watcher = chokidar.watch(
4242
}
4343
);
4444

45-
let log = console.log.bind(console);
45+
const log = console.log.bind(console);
4646
// watcher.on('add', filePath => log(`File ${filePath} has been added`))
4747
// watcher.on('unlink', filePath => log(`File ${filePath} has been removed`));
4848
watcher.on('ready', () => log('Initial scan complete. Watching for changes...\n\n'));
@@ -51,4 +51,4 @@ watcher.on('change', (filePath, stats) => {
5151
// console.log(filePath, stats);
5252
if (scriptRegExp.test(filePath)) { compileScript(filePath); }
5353
if (staticRegExp.test(filePath)) { copyStatic(filePath); }
54-
});
54+
});

0 commit comments

Comments
 (0)