FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

test: check for README changes in the unit tests · shelljs/shelljs@964fb48 · GitHub

Commit 964fb48

Browse files
committed
test: check for README changes in the unit tests
No change to logic. This checks for stale README in the unit tests instead of by calling 'gendocs' directly. The main goal is for GitHub CI to stop getting tripped up by package-lock.json formatting changes. `npm install` sometimes overwrites the package-lock file with a new format, and this breaks the after-travis step. Test: node_modules/.bin/ava test/docs.js
1 parent d44f3b9 commit 964fb48

5 files changed

Lines changed: 83 additions & 201 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ jobs:
2626
- name: test with coverage
2727
run: npm run test-with-coverage
2828
- run: npm run lint
29-
- run: npm run gendocs
3029
- run: npm run check-node-support
31-
- name: Check for modified files (skip on Windows)
32-
run: npm run after-travis
33-
if: matrix.os != 'windows-latest'
3430
- name: Upload coverage reports to Codecov
3531
uses: codecov/codecov-action@v4
3632
with:

‎package-lock.json‎

Lines changed: 1 addition & 153 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"test-with-coverage": "nyc --reporter=text --reporter=lcov ava",
4949
"gendocs": "node scripts/generate-docs",
5050
"lint": "eslint .",
51-
"after-travis": "travis-check-changes",
5251
"changelog": "shelljs-changelog",
5352
"release:major": "shelljs-release major",
5453
"release:minor": "shelljs-release minor",
@@ -81,8 +80,7 @@
8180
"nyc": "^17.1.0",
8281
"shelljs-changelog": "^0.2.6",
8382
"shelljs-release": "^0.5.3",
84-
"shx": "^0.4.0",
85-
"travis-check-changes": "^0.5.1"
83+
"shx": "^0.4.0"
8684
},
8785
"engines": {
8886
"node": ">=18"

‎scripts/generate-docs.js‎

Lines changed: 70 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,73 @@ require('../global');
44

55
var path = require('path');
66

7-
echo('Appending docs to README.md');
8-
9-
cd(path.join(__dirname, '..'));
10-
11-
// Extract docs from shell.js
12-
var docs = grep('^//@', 'shell.js');
13-
14-
// Insert the docs for all the registered commands
15-
var blocklist = [
16-
'./src/common.js',
17-
'./src/error.js',
18-
'./src/errorCode.js',
19-
];
20-
docs = docs.replace(/\/\/@commands\n/g, function () {
21-
return ls('./src/*.js').map(function (file) {
22-
if (blocklist.includes(file)) {
23-
return '';
24-
}
25-
var commandDoc = grep('^//@', file).toString();
26-
if (commandDoc !== '') {
27-
commandDoc += '\n';
28-
}
29-
return commandDoc;
30-
}).join('');
31-
});
32-
33-
// Now extract docs from the remaining src/*.js files
34-
docs = docs.replace(/\/\/@include (.+)/g, function (match, filename) {
35-
return grep('^//@', filename);
36-
});
37-
38-
// Remove '//@'
39-
docs = docs.replace(/\/\/@ ?/g, '');
40-
41-
// Wipe out the old docs
42-
ShellString(cat('README.md').replace(/## Command reference(.|\n)*\n## Team/, '## Command reference\n## Team')).to('README.md');
43-
44-
// Append new docs to README
45-
sed('-i', /## Command reference/, '## Command reference\n\n' + docs, 'README.md');
46-
47-
echo('All done.');
7+
var COMMAND_PREFIX = '## Command reference';
8+
var COMMAND_SUFFIX = '\n## Team';
9+
var COMMAND_PATTERN = /## Command reference\n\n((?:.|\n)*)\n## Team/;
10+
function extractCurrentDocs() {
11+
var m = cat('README.md').match(COMMAND_PATTERN);
12+
if (m) {
13+
var docs = m[1];
14+
return docs;
15+
}
16+
/* istanbul ignore next */
17+
throw new Error('Unable to extract current docs');
18+
}
19+
module.exports.extractCurrentDocs = extractCurrentDocs;
20+
21+
function generateNewDocs() {
22+
// Extract docs from shell.js
23+
var docs = grep('^//@', 'shell.js');
24+
25+
// Insert the docs for all the registered commands
26+
var blocklist = [
27+
'./src/common.js',
28+
'./src/error.js',
29+
'./src/errorCode.js',
30+
];
31+
docs = docs.replace(/\/\/@commands\n/g, function () {
32+
return ls('./src/*.js').map(function (file) {
33+
if (blocklist.includes(file)) {
34+
return '';
35+
}
36+
var commandDoc = grep('^//@', file).toString();
37+
if (commandDoc !== '') {
38+
commandDoc += '\n';
39+
}
40+
return commandDoc;
41+
}).join('');
42+
});
43+
44+
// Now extract docs from the remaining src/*.js files
45+
docs = docs.replace(/\/\/@include (.+)/g, function (match, filename) {
46+
return grep('^//@', filename);
47+
});
48+
49+
// Remove '//@'
50+
docs = docs.replace(/\/\/@ ?/g, '');
51+
return docs;
52+
}
53+
module.exports.generateNewDocs = generateNewDocs;
54+
55+
/* istanbul ignore next */
56+
function main() {
57+
echo('Appending docs to README.md');
58+
59+
cd(path.join(__dirname, '..'));
60+
61+
var docs = generateNewDocs();
62+
63+
// Wipe out the old docs
64+
ShellString(cat('README.md').replace(COMMAND_PATTERN,
65+
COMMAND_PREFIX + COMMAND_SUFFIX)).to('README.md');
66+
67+
// Append new docs to README
68+
sed('-i', /## Command reference/, COMMAND_PREFIX + '\n\n' + docs, 'README.md');
69+
70+
echo('All done.');
71+
}
72+
73+
/* istanbul ignore if */
74+
if (require.main === module) {
75+
main();
76+
}

‎test/docs.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const test = require('ava');
2+
3+
const gendocs = require('../scripts/generate-docs');
4+
5+
test('Documentation generation', t => {
6+
if (gendocs.extractCurrentDocs() === gendocs.generateNewDocs()) {
7+
t.pass();
8+
} else {
9+
t.fail('README documentation is stale. Please run `npm run gendocs`.');
10+
}
11+
});

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL