Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use git log know a documents last modified date #1573

Merged
merged 12 commits into from
Dec 2, 2020
Merged
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,5 @@ yarn-error.log*
fake-v1-api/
mdn-yari-*.tgz
function.zip

testing/content/files/en-us/_githistory.json
4 changes: 3 additions & 1 deletion build/git-history.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ function getFromGit(contentRoot = CONTENT_ROOT) {
],
{
cwd: repoRoot,
}
},
repoRoot
);

const map = new Map();
Expand All @@ -40,6 +41,7 @@ function getFromGit(contentRoot = CONTENT_ROOT) {
}
return map;
}

function gather(contentRoot, previousFile = null) {
const map = new Map();
if (previousFile) {
Expand Down
11 changes: 10 additions & 1 deletion content/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ function execGit(args, opts = {}, root = null) {
args,
{
cwd: gitRoot,
// Default is 1MB
// That's rarely big enough for what we're using Yari for.
maxBuffer: 1024 * 1024 * 100, // 100MB

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps worth to pull the 100 to the front, since that eases reading.

}
);
if (error || status !== 0) {
throw new Error(`git command failed:\n${stderr.toString()}`);
if (stderr) {
console.error(stderr);
}
if (error) {
throw error;
}
throw new Error(`git command failed: ${error.toString()}`);
}
return stdout.toString().trim();
}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"test": "yarn prettier-check && yarn test:client && yarn test:kumascript && yarn test:testing",
"build:client": "cd client && cross-env INLINE_RUNTIME_CHUNK=false react-scripts build",
"build:ssr": "cd ssr && webpack --config webpack.config.js --mode=production",
"prepare-build": "yarn build:client && yarn build:ssr && yarn tool gather-git-history",
"build": "cd build && cross-env NODE_ENV=production node cli.js",
"prepare-build": "yarn build:client && yarn build:ssr && yarn tool gather-git-history --verbose",
"build": "cross-env NODE_ENV=production node build/cli.js",
"start": "(test -f client/build/index.html || yarn build:client) && (test -f ssr/dist/main.js || yarn build:ssr) && nf -j Procfile.start start",
"dev": "yarn build:client && yarn build:ssr && nf -j Procfile.dev start",
"start:client": "cd client && cross-env BROWSER=none PORT=3000 react-scripts start",
Expand Down
4 changes: 2 additions & 2 deletions testing/.env
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
# The relative path trick is necessary because `yarn build` will
# be running from the `./build/` directory.

CONTENT_ROOT=../testing/content/files
CONTENT_ARCHIVED_ROOT=../testing/archived-content/files
CONTENT_ROOT=testing/content/files
CONTENT_ARCHIVED_ROOT=testing/archived-content/files

# Because you never benefit from the progressbar when doing mass builds in
# testing environment. And in CI, it's always disabled anyway.
Expand Down
42 changes: 39 additions & 3 deletions tool/cli.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node
const fs = require("fs");
const path = require("path");
const os = require("os");
Expand All @@ -11,7 +10,7 @@ const open = require("open");

const { DEFAULT_LOCALE, VALID_LOCALES } = require("../libs/constants");
const { CONTENT_ROOT, Redirect, Document, buildURL } = require("../content");
const { gatherGitHistory } = require("../build");
const { buildDocument, gatherGitHistory } = require("../build");

const PORT = parseInt(process.env.SERVER_PORT || "5000");

Expand Down Expand Up @@ -303,12 +302,49 @@ program
);
console.log(
chalk.green(
`Wrote ${Object.keys(
`Saved ${Object.keys(
allHistory
).length.toLocaleString()} paths into ${saveHistory}`
)
);
})
)

.command("flaws", "Find (and fix) flaws in a document")
.argument("<slug>", "Slug of the document in question")
.argument("[locale]", "Locale", {
default: DEFAULT_LOCALE,
validator: [...VALID_LOCALES.values()],
})
.option("-y, --yes", "Assume yes", { default: false })
.action(
tryOrExit(async ({ args, options }) => {
const { slug, locale } = args;
const { yes } = options;
const document = Document.findByURL(buildURL(locale, slug));
if (!document) {
throw new Error(`Slug ${slug} does not exist for ${locale}`);
}
const { doc } = await buildDocument(document, {
fixFlaws: true,
fixFlawsDryRun: true,
});

const flaws = Object.values(doc.flaws)
.map((a) => a.filter((f) => f.fixable).length || 0)
.reduce((a, b) => a + b);
const { run } = yes
? { run: true }
: await prompts({
type: "confirm",
message: `Proceed fixing ${flaws} flaws?`,
name: "run",
initial: true,
});
if (run) {
buildDocument(document, { fixFlaws: true, fixFlawsVerbose: true });
}
})
);

program.run();