Skip to content

Commit 8347451

Browse files
authored
Multiple src roots (#18)
* Upgrade to node 20, drop node 18 support * Allow multiple src paths to be given * Bump version number * Build
1 parent 6e80293 commit 8347451

File tree

22 files changed

+80
-72
lines changed

22 files changed

+80
-72
lines changed

.github/workflows/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
node-version: [18.x, 20.x, 22.x]
16+
node-version: [20.x, 22.x]
1717

1818
steps:
1919
- uses: actions/checkout@v3

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
lts/hydrogen
1+
lts/iron

lib/cjs/actions/check.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,13 @@ const consts_1 = require("./consts");
2222
* Compare the digest of the best practices against the stored digest to
2323
* see if the docs need to be updated.
2424
*/
25-
const checkAction = (_a) => __awaiter(void 0, [_a], void 0, function* ({ srcPath, generatedPath }) {
26-
const bestPractices = yield (0, parse_1.getAllBestPractices)(srcPath);
27-
const currentDigest = (0, digest_1.getBestPracticesDigest)(bestPractices);
25+
const checkAction = (_a) => __awaiter(void 0, [_a], void 0, function* ({ srcPath: srcPaths, generatedPath }) {
26+
const allBestPractices = [];
27+
for (const srcPath of srcPaths) {
28+
const bestPractices = yield (0, parse_1.getAllBestPractices)(srcPath);
29+
allBestPractices.push(...bestPractices);
30+
}
31+
const currentDigest = (0, digest_1.getBestPracticesDigest)(allBestPractices);
2832
const previousDigest = yield getPreviousBestPracticesDigest(generatedPath);
2933
if (currentDigest === previousDigest) {
3034
return;

lib/cjs/actions/write.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,13 @@ const consts_1 = require("./consts");
2828
* Generate best practices from source and write them out.
2929
*/
3030
function writeAction(_a) {
31-
return __awaiter(this, arguments, void 0, function* ({ srcPath, docsPath, generatedPath, codeUrl, extensionMappings, options, }) {
31+
return __awaiter(this, arguments, void 0, function* ({ srcPath: srcPaths, docsPath, generatedPath, codeUrl, extensionMappings, options, }) {
3232
const codeTypeMap = (0, codeType_1.buildCodeTypeMap)(extensionMappings !== null && extensionMappings !== void 0 ? extensionMappings : []);
33-
const allBestPractices = yield (0, parse_1.getAllBestPractices)(srcPath);
33+
const allBestPractices = [];
34+
for (const srcPath of srcPaths) {
35+
const bestPractices = yield (0, parse_1.getAllBestPractices)(srcPath);
36+
allBestPractices.push(...bestPractices);
37+
}
3438
let filteredBestPractices;
3539
if (docsPath) {
3640
// It's OK if the generatedPath is within docsPath, because we'll completely replace

lib/cjs/best-practices.js

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const write_1 = __importDefault(require("./actions/write"));
1010
const main = () => {
1111
commander_1.program
1212
.command('check')
13-
.requiredOption('-s, --src-path <srcPath>')
13+
.requiredOption('-s, --src-path <srcPath...>')
1414
.requiredOption('-g, --generated-path <generatedPath>')
1515
.action((args) => {
1616
(0, check_1.default)(args);
1717
});
1818
commander_1.program
1919
.command('write')
20-
.requiredOption('-s, --src-path <srcPath>')
20+
.requiredOption('-s, --src-path <srcPath...>')
2121
.option('-d, --docs-path <docsPath>')
2222
.requiredOption('-g, --generated-path <generatedPath>')
2323
.requiredOption('-u, --code-url <codeUrl>')

lib/cjs/index.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
1515
}) : function(o, v) {
1616
o["default"] = v;
1717
});
18-
var __importStar = (this && this.__importStar) || (function () {
19-
var ownKeys = function(o) {
20-
ownKeys = Object.getOwnPropertyNames || function (o) {
21-
var ar = [];
22-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23-
return ar;
24-
};
25-
return ownKeys(o);
26-
};
27-
return function (mod) {
28-
if (mod && mod.__esModule) return mod;
29-
var result = {};
30-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31-
__setModuleDefault(result, mod);
32-
return result;
33-
};
34-
})();
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
3525
var __importDefault = (this && this.__importDefault) || function (mod) {
3626
return (mod && mod.__esModule) ? mod : { "default": mod };
3727
};

lib/cjs/types/actions/check.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
type CheckArgs = {
2-
srcPath: string;
2+
srcPath: string[];
33
generatedPath: string;
44
};
55
/**
66
* Compare the digest of the best practices against the stored digest to
77
* see if the docs need to be updated.
88
*/
9-
declare const checkAction: ({ srcPath, generatedPath }: CheckArgs) => Promise<void>;
9+
declare const checkAction: ({ srcPath: srcPaths, generatedPath }: CheckArgs) => Promise<void>;
1010
export default checkAction;
1111
//# sourceMappingURL=check.d.ts.map

lib/cjs/types/actions/check.d.ts.map

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

lib/cjs/types/actions/write.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type WriteOptions = {
44
writeExtraMeta?: boolean;
55
};
66
type WriteArgs = {
7-
srcPath: string;
7+
srcPath: string[];
88
docsPath?: string;
99
generatedPath: string;
1010
codeUrl: string;
@@ -14,7 +14,7 @@ type WriteArgs = {
1414
/**
1515
* Generate best practices from source and write them out.
1616
*/
17-
export default function writeAction({ srcPath, docsPath, generatedPath, codeUrl, extensionMappings, options, }: WriteArgs): Promise<BestPractice[]>;
17+
export default function writeAction({ srcPath: srcPaths, docsPath, generatedPath, codeUrl, extensionMappings, options, }: WriteArgs): Promise<BestPractice[]>;
1818
/**
1919
* Writes best practices out to Markdown doc files.
2020
*/

lib/cjs/types/actions/write.d.ts.map

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

lib/esm/actions/check.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ const consts_1 = require("./consts");
1313
* Compare the digest of the best practices against the stored digest to
1414
* see if the docs need to be updated.
1515
*/
16-
const checkAction = async ({ srcPath, generatedPath }) => {
17-
const bestPractices = await (0, parse_1.getAllBestPractices)(srcPath);
18-
const currentDigest = (0, digest_1.getBestPracticesDigest)(bestPractices);
16+
const checkAction = async ({ srcPath: srcPaths, generatedPath }) => {
17+
const allBestPractices = [];
18+
for (const srcPath of srcPaths) {
19+
const bestPractices = await (0, parse_1.getAllBestPractices)(srcPath);
20+
allBestPractices.push(...bestPractices);
21+
}
22+
const currentDigest = (0, digest_1.getBestPracticesDigest)(allBestPractices);
1923
const previousDigest = await getPreviousBestPracticesDigest(generatedPath);
2024
if (currentDigest === previousDigest) {
2125
return;

lib/esm/actions/write.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ const consts_1 = require("./consts");
1818
/**
1919
* Generate best practices from source and write them out.
2020
*/
21-
async function writeAction({ srcPath, docsPath, generatedPath, codeUrl, extensionMappings, options, }) {
21+
async function writeAction({ srcPath: srcPaths, docsPath, generatedPath, codeUrl, extensionMappings, options, }) {
2222
const codeTypeMap = (0, codeType_1.buildCodeTypeMap)(extensionMappings ?? []);
23-
const allBestPractices = await (0, parse_1.getAllBestPractices)(srcPath);
23+
const allBestPractices = [];
24+
for (const srcPath of srcPaths) {
25+
const bestPractices = await (0, parse_1.getAllBestPractices)(srcPath);
26+
allBestPractices.push(...bestPractices);
27+
}
2428
let filteredBestPractices;
2529
if (docsPath) {
2630
// It's OK if the generatedPath is within docsPath, because we'll completely replace

lib/esm/best-practices.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ const write_1 = __importDefault(require("./actions/write"));
1010
const main = () => {
1111
commander_1.program
1212
.command('check')
13-
.requiredOption('-s, --src-path <srcPath>')
13+
.requiredOption('-s, --src-path <srcPath...>')
1414
.requiredOption('-g, --generated-path <generatedPath>')
1515
.action((args) => {
1616
(0, check_1.default)(args);
1717
});
1818
commander_1.program
1919
.command('write')
20-
.requiredOption('-s, --src-path <srcPath>')
20+
.requiredOption('-s, --src-path <srcPath...>')
2121
.option('-d, --docs-path <docsPath>')
2222
.requiredOption('-g, --generated-path <generatedPath>')
2323
.requiredOption('-u, --code-url <codeUrl>')

lib/esm/index.mjs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,13 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
1515
}) : function(o, v) {
1616
o["default"] = v;
1717
});
18-
var __importStar = (this && this.__importStar) || (function () {
19-
var ownKeys = function(o) {
20-
ownKeys = Object.getOwnPropertyNames || function (o) {
21-
var ar = [];
22-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23-
return ar;
24-
};
25-
return ownKeys(o);
26-
};
27-
return function (mod) {
28-
if (mod && mod.__esModule) return mod;
29-
var result = {};
30-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31-
__setModuleDefault(result, mod);
32-
return result;
33-
};
34-
})();
18+
var __importStar = (this && this.__importStar) || function (mod) {
19+
if (mod && mod.__esModule) return mod;
20+
var result = {};
21+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22+
__setModuleDefault(result, mod);
23+
return result;
24+
};
3525
var __importDefault = (this && this.__importDefault) || function (mod) {
3626
return (mod && mod.__esModule) ? mod : { "default": mod };
3727
};

lib/esm/types/actions/check.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
type CheckArgs = {
2-
srcPath: string;
2+
srcPath: string[];
33
generatedPath: string;
44
};
55
/**
66
* Compare the digest of the best practices against the stored digest to
77
* see if the docs need to be updated.
88
*/
9-
declare const checkAction: ({ srcPath, generatedPath }: CheckArgs) => Promise<void>;
9+
declare const checkAction: ({ srcPath: srcPaths, generatedPath }: CheckArgs) => Promise<void>;
1010
export default checkAction;
1111
//# sourceMappingURL=check.d.ts.map

lib/esm/types/actions/check.d.ts.map

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

lib/esm/types/actions/write.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type WriteOptions = {
44
writeExtraMeta?: boolean;
55
};
66
type WriteArgs = {
7-
srcPath: string;
7+
srcPath: string[];
88
docsPath?: string;
99
generatedPath: string;
1010
codeUrl: string;
@@ -14,7 +14,7 @@ type WriteArgs = {
1414
/**
1515
* Generate best practices from source and write them out.
1616
*/
17-
export default function writeAction({ srcPath, docsPath, generatedPath, codeUrl, extensionMappings, options, }: WriteArgs): Promise<BestPractice[]>;
17+
export default function writeAction({ srcPath: srcPaths, docsPath, generatedPath, codeUrl, extensionMappings, options, }: WriteArgs): Promise<BestPractice[]>;
1818
/**
1919
* Writes best practices out to Markdown doc files.
2020
*/

lib/esm/types/actions/write.d.ts.map

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@closeio/best-practices-documentation",
3-
"version": "0.5.0",
3+
"version": "0.6.0",
44
"description": "Tooling to document best practices in your code base.",
55
"author": "Trey Cucco",
66
"main": "index.js",

src/actions/check.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
import { readFile } from 'fs/promises';
22
import path from 'path';
3+
import type BestPractice from '../BestPractice';
34
import { getBestPracticesDigest } from '../utils/digest';
45
import { pathExists } from '../utils/fs';
56
import { getAllBestPractices } from '../utils/parse';
67
import { DIGEST_FILENAME } from './consts';
78

89
type CheckArgs = {
9-
srcPath: string;
10+
srcPath: string[];
1011
generatedPath: string;
1112
};
1213

1314
/**
1415
* Compare the digest of the best practices against the stored digest to
1516
* see if the docs need to be updated.
1617
*/
17-
const checkAction = async ({ srcPath, generatedPath }: CheckArgs) => {
18-
const bestPractices = await getAllBestPractices(srcPath);
18+
const checkAction = async ({ srcPath: srcPaths, generatedPath }: CheckArgs) => {
19+
const allBestPractices: BestPractice[] = [];
1920

20-
const currentDigest = getBestPracticesDigest(bestPractices);
21+
for (const srcPath of srcPaths) {
22+
const bestPractices = await getAllBestPractices(srcPath);
23+
allBestPractices.push(...bestPractices);
24+
}
25+
26+
const currentDigest = getBestPracticesDigest(allBestPractices);
2127
const previousDigest = await getPreviousBestPracticesDigest(generatedPath);
2228

2329
if (currentDigest === previousDigest) {

src/actions/write.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type WriteOptions = {
1414
};
1515

1616
type WriteArgs = {
17-
srcPath: string;
17+
srcPath: string[];
1818
docsPath?: string;
1919
generatedPath: string;
2020
codeUrl: string;
@@ -26,7 +26,7 @@ type WriteArgs = {
2626
* Generate best practices from source and write them out.
2727
*/
2828
export default async function writeAction({
29-
srcPath,
29+
srcPath: srcPaths,
3030
docsPath,
3131
generatedPath,
3232
codeUrl,
@@ -35,7 +35,13 @@ export default async function writeAction({
3535
}: WriteArgs) {
3636
const codeTypeMap = buildCodeTypeMap(extensionMappings ?? []);
3737

38-
const allBestPractices = await getAllBestPractices(srcPath);
38+
const allBestPractices: BestPractice[] = [];
39+
40+
for (const srcPath of srcPaths) {
41+
const bestPractices = await getAllBestPractices(srcPath);
42+
allBestPractices.push(...bestPractices);
43+
}
44+
3945
let filteredBestPractices: BestPractice[];
4046

4147
if (docsPath) {

src/best-practices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import writeAction from './actions/write';
66
const main = () => {
77
program
88
.command('check')
9-
.requiredOption('-s, --src-path <srcPath>')
9+
.requiredOption('-s, --src-path <srcPath...>')
1010
.requiredOption('-g, --generated-path <generatedPath>')
1111
.action((args) => {
1212
checkAction(args);
1313
});
1414

1515
program
1616
.command('write')
17-
.requiredOption('-s, --src-path <srcPath>')
17+
.requiredOption('-s, --src-path <srcPath...>')
1818
.option('-d, --docs-path <docsPath>')
1919
.requiredOption('-g, --generated-path <generatedPath>')
2020
.requiredOption('-u, --code-url <codeUrl>')

0 commit comments

Comments
 (0)