Skip to content

Commit

Permalink
AG-14398 Fix wiki build scripts
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 84393af
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Mon Nov 7 13:35:02 2022 +0200

    delete obsolete comment

commit 16bf367
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Mon Nov 7 13:34:08 2022 +0200

    fix getFilesList description

commit d0d6c71
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Mon Nov 7 13:33:16 2022 +0200

    rename writeFile helper back

commit 7790df7
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 21:13:07 2022 +0200

    fix specs -- update wiki about pages while build

commit 74523b4
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 21:11:56 2022 +0200

    update readme

commit c604e16
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 21:11:41 2022 +0200

    fix package.json scripts for wiki

commit 11d2e3c
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 21:10:23 2022 +0200

    do not throw error on some changes while checking compatibility table updated

commit 162089f
Merge: 4a4d308 788f73a
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 16:49:54 2022 +0200

    Merge branch 'release/v1.7' into fix/AG-14398

commit 4a4d308
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 00:03:26 2022 +0200

    update package.json scripts for wiki

commit a23f2b0
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 00:02:31 2022 +0200

    do not build compatibility table while build-docs

commit a43af1b
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 00:01:54 2022 +0200

    fix constants

commit 24e51b6
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Thu Nov 3 00:01:09 2022 +0200

    fix getCurrentUBORedirects()

commit 4c18c35
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 2 23:25:32 2022 +0200

    fix typo

commit 456f7c0
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 2 20:58:35 2022 +0200

    change fixme to todo

commit ec4e5e3
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 2 20:57:37 2022 +0200

    add comment for writeFileAsync

commit 7d1ca12
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 2 20:55:10 2022 +0200

    refactor scripts methods, fix types

commit f0e919f
Author: Slava Leleka <v.leleka@adguard.com>
Date:   Wed Nov 2 18:56:32 2022 +0200

    refactor build scripts helpers and constants

commit d2b9c93
Author: Stanislav A <s.atroschenko@adguard.com>
Date:   Wed Nov 2 13:43:04 2022 +0300

    Build wiki/compatibility-table.md while build
  • Loading branch information
stanislav-atr authored and slavaleleka committed Nov 8, 2022
1 parent 788f73a commit ee83930
Show file tree
Hide file tree
Showing 9 changed files with 365 additions and 218 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,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 ee83930

Please sign in to comment.