mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
Replace diff with string comparison (#230)
This commit is contained in:
parent
76c1dace46
commit
420d2e86fb
3 changed files with 14 additions and 21 deletions
|
@ -9,7 +9,6 @@ const CWD = process.cwd();
|
|||
const glob = require("glob");
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const diff = require("diff");
|
||||
const assert = require("assert");
|
||||
|
||||
const siteConfig = require(CWD + "/siteConfig.js");
|
||||
|
@ -66,7 +65,10 @@ function extractMetadata(content) {
|
|||
for (let i = 0; i < lines.length - 1; ++i) {
|
||||
const keyvalue = lines[i].split(":");
|
||||
const key = keyvalue[0].trim();
|
||||
let value = keyvalue.slice(1).join(":").trim();
|
||||
let value = keyvalue
|
||||
.slice(1)
|
||||
.join(":")
|
||||
.trim();
|
||||
try {
|
||||
value = JSON.parse(value);
|
||||
} catch (e) {}
|
||||
|
@ -95,18 +97,20 @@ files.forEach(file => {
|
|||
const metadata = res.metadata;
|
||||
|
||||
if (!metadata.original_id) {
|
||||
console.error(`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`);
|
||||
console.error(
|
||||
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
throw new Error(
|
||||
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
}
|
||||
if (!metadata.id) {
|
||||
console.error(`No 'id' field found in ${file}.`);
|
||||
throw new Error(
|
||||
`No 'id' field found in ${file}.`
|
||||
throw new Error(`No 'id' field found in ${file}.`);
|
||||
} else if (metadata.id.indexOf("version-") === -1) {
|
||||
console.error(
|
||||
`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
} else if (metadata.id.indexOf('version-') === -1) {
|
||||
console.error(`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`);
|
||||
throw new Error(
|
||||
`The 'id' field in ${file} is missing the expected 'version-XX-' prefix. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||
);
|
||||
|
@ -174,16 +178,10 @@ function diffLatestDoc(file, id) {
|
|||
return true;
|
||||
}
|
||||
|
||||
const diffs = diff.diffChars(
|
||||
extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent,
|
||||
extractMetadata(fs.readFileSync(file, "utf8")).rawContent
|
||||
return (
|
||||
extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent.trim() !==
|
||||
extractMetadata(fs.readFileSync(file, "utf8")).rawContent.trim()
|
||||
);
|
||||
diffs.forEach(part => {
|
||||
if (part.added || part.removed) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
// return metadata for a versioned file given the file, its version (requested),
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
"classnames": "^2.2.5",
|
||||
"commander": "^2.11.0",
|
||||
"crowdin-cli": "^0.3.0",
|
||||
"diff": "^3.3.0",
|
||||
"escape-string-regexp": "^1.0.5",
|
||||
"express": "^4.15.3",
|
||||
"feed": "^1.1.0",
|
||||
|
|
|
@ -808,10 +808,6 @@ detect-indent@^4.0.0:
|
|||
dependencies:
|
||||
repeating "^2.0.0"
|
||||
|
||||
diff@^3.3.0:
|
||||
version "3.4.0"
|
||||
resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c"
|
||||
|
||||
ecc-jsbn@~0.1.1:
|
||||
version "0.1.1"
|
||||
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue