Skip to content

Commit

Permalink
Edit buildDocs to remove outdated documentation (closes palantir#3185) (
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr authored and ajafff committed Sep 22, 2017
1 parent 126836c commit bf60bea
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"@types/mocha": "^2.2.35",
"@types/node": "^7.0.29",
"@types/resolve": "^0.0.4",
"@types/rimraf": "^2.0.2",
"@types/semver": "^5.3.30",
"chai": "^3.5.0",
"github": "^8.2.1",
Expand Down
28 changes: 24 additions & 4 deletions scripts/buildDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import * as glob from "glob";
import stringify = require("json-stringify-pretty-compact");
import * as yaml from "js-yaml";
import * as path from "path";
import * as rimraf from "rimraf";

import {IFormatterMetadata} from "../lib/language/formatter/formatter";
import {IRuleMetadata} from "../lib/language/rule/rule";
Expand Down Expand Up @@ -111,15 +112,34 @@ const formatterDocumentation: IDocumentation = {
*/
function buildDocumentation(documentation: IDocumentation) {
// Create each module's documentation file.
const paths = glob.sync(documentation.globPattern);
const metadataJson = paths.map((path: string) => {
return buildSingleModuleDocumentation(documentation, path);
});
const modulePaths = glob.sync(documentation.globPattern);
const metadataJson = modulePaths.map((modulePath: string) =>
buildSingleModuleDocumentation(documentation, modulePath));

// Delete outdated directories
const rulesDirs = metadataJson.map((metadata: any) => metadata[documentation.nameMetadataKey]);
deleteOutdatedDocumentation(documentation.subDirectory, rulesDirs);

// Create a data file with details of every module.
buildDocumentationDataFile(documentation, metadataJson);
}

/**
* Deletes directories which are outdated
* @param directory Path from which outdated subdirectories have to be checked and removed
* @param rulesDirs The names of the current and new rules documentation directories
*/
function deleteOutdatedDocumentation(directory: string, rulesDirs: string[]) {
// find if the thing at particular location is a directory
const isDirectory = (source: string) => fs.lstatSync(source).isDirectory();
// get all subdirectories in source directory
const getDirectories = (source: string) => fs.readdirSync(source).filter((name) => isDirectory(path.join(source, name)));

const subDirs = getDirectories(directory);
const outdatedDirs = subDirs.filter((dir) => rulesDirs.indexOf(dir) < 0);
outdatedDirs.forEach((outdatedDir) => rimraf.sync(path.join(directory, outdatedDir)));
}

/**
* Produces documentation for a single file/module.
*/
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
version "3.2.0"
resolved "https://registry.yarnpkg.com/@types/diff/-/diff-3.2.0.tgz#2cf019a98b4cca072102cb48af5675502b5a831f"

"@types/glob@*":
version "5.0.32"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-5.0.32.tgz#aec5cfe987c72f099fdb1184452986aa506d5e8f"
dependencies:
"@types/minimatch" "*"
"@types/node" "*"

"@types/glob@^5.0.30":
version "5.0.30"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-5.0.30.tgz#1026409c5625a8689074602808d082b2867b8a51"
Expand Down Expand Up @@ -53,6 +60,13 @@
dependencies:
"@types/node" "*"

"@types/rimraf@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-2.0.2.tgz#7f0fc3cf0ff0ad2a99bb723ae1764f30acaf8b6e"
dependencies:
"@types/glob" "*"
"@types/node" "*"

"@types/semver@^5.3.30":
version "5.3.31"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-5.3.31.tgz#b999d7d935f43f5207b01b00d3de20852f4ca75f"
Expand Down

0 comments on commit bf60bea

Please sign in to comment.