Skip to content

Commit

Permalink
Merge branch 'release/v1.7' into fix/AG-16962
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-atr committed Nov 9, 2022
2 parents a93acba + 0fb636b commit c4a87c6
Show file tree
Hide file tree
Showing 54 changed files with 3,569 additions and 522 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,9 @@ and open needed HTML file from `tests/dist` in your browser with devtools

## <a id="how-to-update-wiki"></a> How to update wiki

```
yarn wiki:update
```
`about-scriptlets.md` and `about-redirects.md` are being built from JSDoc notation of corresponding scriptlets and redirects source files with `@scriptlet/@redirect` and `@description` tags.
There are two scripts to update wiki:
1. `yarn wiki:build-table` — checks compatibility data updates and updates the compatibility table. Should be run manually while the release preparation.
2. `yarn wiki:build-docs` — updates wiki pages `about-scriptlets.md` and `about-redirects.md`. They are being generated from JSDoc-type comments of corresponding scriptlets and redirects source files due to `@scriptlet`/`@redirect` and `@description` tags. Runs automatically while the release build.

## <a id="browser-compatibility"> Browser Compatibility
| Chrome | Edge | Firefox | IE | Opera | Safari |
Expand Down
2 changes: 2 additions & 0 deletions bamboo-specs/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ Build:
yarn install ${bamboo.varsYarn}
yarn build
yarn wiki:build-docs
rm -rf node_modules
- inject-variables:
file: dist/build.txt
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"gui-test": "babel-node scripts/build-tests.js && open http://localhost:8585 && node ./tests/server.js",
"lint": "eslint .",
"lint-staged": "lint-staged",
"wiki:build-table": "node ./scripts/check-sources-updates.js && node ./scripts/build-compatibility-table.js",
"wiki:build-docs": "node scripts/build-docs.js",
"wiki:check-updates": "node ./scripts/check-sources-updates.js",
"wiki:update": "yarn wiki:check-updates && node ./scripts/build-compatibility-table.js",
"prepublishOnly": "yarn build",
"increment": "yarn version --patch --no-git-tag-version"
},
Expand Down
109 changes: 72 additions & 37 deletions scripts/build-compatibility-table.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,115 @@
const path = require('path');
const fs = require('fs');
const os = require('os');
const { EOL } = require('os');

const {
REMOVED_MARKER,
WIKI_DIR_PATH,
COMPATIBILITY_TABLE_DATA_PATH,
WIKI_COMPATIBILITY_TABLE_PATH,
} = require('./constants');

const COMPATIBILITY_TABLE_OUTPUT_FILENAME = 'compatibility-table.md';

/**
* Path to **output** wiki compatibility table file
*/
const WIKI_COMPATIBILITY_TABLE_PATH = path.resolve(
__dirname,
WIKI_DIR_PATH,
COMPATIBILITY_TABLE_OUTPUT_FILENAME,
);

/**
* @typedef {Object} CompatibilityItem
* @property {string} adg
* @property {string} abp
* @property {string} ubo
*/

/**
* Returns data for compatibility tables
* @typedef {Object} CompatibilityData
* @property {CompatibilityItem[]} scriptlets
* @property {CompatibilityItem[]} redirects
*/
function getTableData() {

/**
* Returns data for compatibility table
*
* @returns {CompatibilityData} input compatibility data from json
*/
const getTableData = () => {
const rawData = fs.readFileSync(COMPATIBILITY_TABLE_DATA_PATH);
const parsed = JSON.parse(rawData);
return parsed;
}
return JSON.parse(rawData);
};

/**
* Returns markdown row of compatibility table
* @param {{
* adg: string,
* ubo: string,
* abp: string
* }} item { an }
*
* @param {'scriptlets'|'redirects'} id
* @param {CompatibilityItem} item params object
* @param {string} item.adg AdGuard name
* @param {string} item.abp Adblock Plus name
* @param {string} item.ubo uBlock name
*
* @returns {string} markdown table row
*/
const getRow = (id, item) => {
const getRow = (id, { adg, abp, ubo }) => {
let adgCell = '';
if (item.adg) {
adgCell = item.adg.includes(REMOVED_MARKER)
? item.adg
: `[${item.adg}](../wiki/about-${id}.md#${item.adg})`;
if (adg) {
adgCell = adg.includes(REMOVED_MARKER)
? adg
: `[${adg}](${WIKI_DIR_PATH}/about-${id}.md#${adg})`;
}

return `| ${adgCell} | ${item.ubo || ''} | ${item.abp || ''} |${os.EOL}`;
return `| ${adgCell} | ${ubo || ''} | ${abp || ''} |${EOL}`;
};

/**
* Generates table header
*
* @returns {string}
*/
const getTableHeader = () => {
let res = `| AdGuard | uBO | Adblock Plus |${os.EOL}`;
res += `|---|---|---|${os.EOL}`;
let res = `| AdGuard | uBO | Adblock Plus |${EOL}`;
res += `|---|---|---|${EOL}`;
return res;
};

/**
* Builds markdown string with scriptlets compatibility table
* @param {Array} data array with scriptlets names
* Builds markdown string of scriptlets/redirect compatibility table
* @param {string} title title for scriptlets or redirects
* @param {CompatibilityItem[]} data array of scriptlets or redirects compatibility data items
* @param {'scriptlets'|'redirects'} id
*
* @returns {string} scriptlets or redirects compatibility table
*/
function buildTable(title, data = [], id = '') {
const buildTable = (title, data = [], id = '') => {
// title
let res = `# <a id="${id}"></a> ${title}${os.EOL}${os.EOL}`;
let res = `# <a id="${id}"></a> ${title}${EOL}${EOL}`;
// header
res += getTableHeader();
// rows
res += data
.map((item) => {
const row = getRow(id, item);
return row;
})
.map((item) => getRow(id, item))
.join('');

return res;
}
};

/**
* Save tables to compatibility table
* Saves tables to compatibility table
*
* @param {string[]} args
*/
function saveTables(...args) {
const res = args.join(`${os.EOL}${os.EOL}`);
const saveTables = (...args) => {
const res = args.join(`${EOL}${EOL}`);
fs.writeFileSync(WIKI_COMPATIBILITY_TABLE_PATH, res);
}
};

/**
* Entry function
* Builds full compatibility table
*/
function init() {
const buildCompatibilityTable = () => {
const { scriptlets, redirects } = getTableData();

const scriptletsTable = buildTable(
Expand All @@ -89,6 +124,6 @@ function init() {
);

saveTables(scriptletsTable, redirectsTable);
}
};

init();
buildCompatibilityTable();
Loading

0 comments on commit c4a87c6

Please sign in to comment.