Skip to content

Commit 48fcfe3

Browse files
committed
v1.1.1 limit revisions
1 parent 2ad82f9 commit 48fcfe3

File tree

8 files changed

+36
-53
lines changed

8 files changed

+36
-53
lines changed

DEV.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ npx wiki2git-commit --help
4848

4949
Example:
5050
```
51-
npx wiki2git-load --site meta.wikimedia.org -p "User:Nux/global.js"
51+
npx wiki2git-load --site meta.wikimedia.org -p "User:Nux/global.js" -l 3
5252
npx wiki2git-commit --site meta.wikimedia.org --repo "repo/global-test" -o "global.js"
5353
```
5454

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "wiki-to-git",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Node.js tool that helps to download Mediwiki page history and push it to a Git repository.",
55
"type": "module",
66
"main": "src/main.js",
@@ -14,6 +14,7 @@
1414
"mocha": "10.x"
1515
},
1616
"scripts": {
17+
"test-load": "npx wiki2git-load --site meta.wikimedia.org -p \"User:Nux/global.js\" -l 2",
1718
"test": "mocha"
1819
},
1920
"bin": {

src/LoadData.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export class LoadData {
5454
const response = await fetch(url);
5555
url = await this.loadPage(response);
5656

57-
// page limit
57+
// page limit (batches limit)
5858
if (options.pages > 0) {
5959
count++;
6060
if (count >= options.pages) {
@@ -64,6 +64,8 @@ export class LoadData {
6464
// changes limit
6565
if (options.changes > 0) {
6666
if (this.history.length >= options.changes) {
67+
let deleteCount = this.history.length - options.changes;
68+
this.history.splice(-deleteCount, deleteCount);
6769
break;
6870
}
6971
}

src/cmd-commit-cmd.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ program
1313
.requiredOption('-s, --site <site>', `MediaWiki site domain (e.g. 'en.wikipedia.org').`)
1414
.requiredOption('-r, --repo <dirName>', 'Git repository name (new or existing subdirectory).')
1515
.requiredOption('-o, --output <fileName>', 'Output file name (new JS/CSS file in the git repo).')
16-
.option('-j, --json <fileName>', `Optional JSON file name for history data (default: 'history.json').`, '')
16+
.option('-j, --json <fileName>', `Optional JSON file name for history data (default: 'history.json').`)
1717
.parse(process.argv);
1818

1919
const options = program.opts();
2020

21-
const { site, repo, output, json } = options;
21+
let { site, repo, output, json } = options;
22+
23+
if (typeof json != 'string') {
24+
json = '';
25+
}
26+
2227

2328
await runScript(site, repo, output, json);

src/cmd-load-cmd.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env node
1+
#!/usr/bin/env node
22

33
/**
44
* Download page history from a MediaWiki site.
@@ -12,13 +12,18 @@ program
1212
.description('Download page history from a MediaWiki site. Loads metadata from a wiki site and save this to a history json.')
1313
.requiredOption('-s, --site <site>', `MediaWiki site domain (e.g. 'en.wikipedia.org').`)
1414
.requiredOption('-p, --page <page>', 'Page to download (title with namespace).')
15-
.option('-j, --json <fileName>', `Optional JSON file name for history data (default: 'history.json').`, '')
15+
.option('-j, --json <fileName>', `Optional JSON file name for history data (default: 'history.json').`)
16+
.option('-l, --limit <number>', `Optional limit of revisions to download from top (default: no limit).`)
1617
.parse(process.argv);
1718

1819
const options = program.opts();
1920

20-
const { site, page, json } = options;
21+
let { site, page, json, limit } = options;
22+
23+
if (typeof json != 'string') {
24+
json = '';
25+
}
2126

2227
// console.log('temp', { site, page, json });
2328

24-
await runScript(site, page, json);
29+
await runScript(site, page, json, limit);

src/cmd-load.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,23 @@ import { LoadData } from './LoadData.js';
66
/**
77
* Download page history from a MediaWiki site.
88
*/
9-
export async function runScript(site, page, historyFile) {
9+
export async function runScript(site, page, historyFile, limit) {
1010
const loader = new LoadData(site);
1111
loader.baseDir = './';
1212

13+
let options = {
14+
changes: -1, // no. changes (default - no limit)
15+
};
16+
if (limit) {
17+
let changes = parseInt(limit, 10);
18+
if (changes && changes > 0) {
19+
options.changes = changes;
20+
}
21+
}
22+
1323
console.log('\n\nDownload history for %s.', page);
1424
// this will load version history into internals
15-
await loader.load(page);
25+
await loader.load(page, options);
1626
// this will save history as JSON
1727
await loader.saveHistory(historyFile, true);
1828
// this just shows a quick info (you can skip this)

src/load.js

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

0 commit comments

Comments
 (0)