Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit964fb48

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

File tree

5 files changed

+83
-201
lines changed

5 files changed

+83
-201
lines changed

‎.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 aboutcustomizing 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
varpath=require('path');
66

7-
echo('Appending docs to README.md');
8-
9-
cd(path.join(__dirname,'..'));
10-
11-
// Extract docs from shell.js
12-
vardocs=grep('^//@','shell.js');
13-
14-
// Insert the docs for all the registered commands
15-
varblocklist=[
16-
'./src/common.js',
17-
'./src/error.js',
18-
'./src/errorCode.js',
19-
];
20-
docs=docs.replace(/\/\/@commands\n/g,function(){
21-
returnls('./src/*.js').map(function(file){
22-
if(blocklist.includes(file)){
23-
return'';
24-
}
25-
varcommandDoc=grep('^//@',file).toString();
26-
if(commandDoc!==''){
27-
commandDoc+='\n';
28-
}
29-
returncommandDoc;
30-
}).join('');
31-
});
32-
33-
// Now extract docs from the remaining src/*.js files
34-
docs=docs.replace(/\/\/@include(.+)/g,function(match,filename){
35-
returngrep('^//@',filename);
36-
});
37-
38-
// Remove '//@'
39-
docs=docs.replace(/\/\/@?/g,'');
40-
41-
// Wipe out the old docs
42-
ShellString(cat('README.md').replace(/##Commandreference(.|\n)*\n##Team/,'## Command reference\n## Team')).to('README.md');
43-
44-
// Append new docs to README
45-
sed('-i',/##Commandreference/,'## Command reference\n\n'+docs,'README.md');
46-
47-
echo('All done.');
7+
varCOMMAND_PREFIX='## Command reference';
8+
varCOMMAND_SUFFIX='\n## Team';
9+
varCOMMAND_PATTERN=/##Commandreference\n\n((?:.|\n)*)\n##Team/;
10+
functionextractCurrentDocs(){
11+
varm=cat('README.md').match(COMMAND_PATTERN);
12+
if(m){
13+
vardocs=m[1];
14+
returndocs;
15+
}
16+
/* istanbul ignore next */
17+
thrownewError('Unable to extract current docs');
18+
}
19+
module.exports.extractCurrentDocs=extractCurrentDocs;
20+
21+
functiongenerateNewDocs(){
22+
// Extract docs from shell.js
23+
vardocs=grep('^//@','shell.js');
24+
25+
// Insert the docs for all the registered commands
26+
varblocklist=[
27+
'./src/common.js',
28+
'./src/error.js',
29+
'./src/errorCode.js',
30+
];
31+
docs=docs.replace(/\/\/@commands\n/g,function(){
32+
returnls('./src/*.js').map(function(file){
33+
if(blocklist.includes(file)){
34+
return'';
35+
}
36+
varcommandDoc=grep('^//@',file).toString();
37+
if(commandDoc!==''){
38+
commandDoc+='\n';
39+
}
40+
returncommandDoc;
41+
}).join('');
42+
});
43+
44+
// Now extract docs from the remaining src/*.js files
45+
docs=docs.replace(/\/\/@include(.+)/g,function(match,filename){
46+
returngrep('^//@',filename);
47+
});
48+
49+
// Remove '//@'
50+
docs=docs.replace(/\/\/@?/g,'');
51+
returndocs;
52+
}
53+
module.exports.generateNewDocs=generateNewDocs;
54+
55+
/* istanbul ignore next */
56+
functionmain(){
57+
echo('Appending docs to README.md');
58+
59+
cd(path.join(__dirname,'..'));
60+
61+
vardocs=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',/##Commandreference/,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+
consttest=require('ava');
2+
3+
constgendocs=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)

[8]ページ先頭

©2009-2025 Movatter.jp