mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-14 17:47:40 +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 glob = require("glob");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const diff = require("diff");
|
|
||||||
const assert = require("assert");
|
const assert = require("assert");
|
||||||
|
|
||||||
const siteConfig = require(CWD + "/siteConfig.js");
|
const siteConfig = require(CWD + "/siteConfig.js");
|
||||||
|
@ -66,7 +65,10 @@ function extractMetadata(content) {
|
||||||
for (let i = 0; i < lines.length - 1; ++i) {
|
for (let i = 0; i < lines.length - 1; ++i) {
|
||||||
const keyvalue = lines[i].split(":");
|
const keyvalue = lines[i].split(":");
|
||||||
const key = keyvalue[0].trim();
|
const key = keyvalue[0].trim();
|
||||||
let value = keyvalue.slice(1).join(":").trim();
|
let value = keyvalue
|
||||||
|
.slice(1)
|
||||||
|
.join(":")
|
||||||
|
.trim();
|
||||||
try {
|
try {
|
||||||
value = JSON.parse(value);
|
value = JSON.parse(value);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
@ -95,18 +97,20 @@ files.forEach(file => {
|
||||||
const metadata = res.metadata;
|
const metadata = res.metadata;
|
||||||
|
|
||||||
if (!metadata.original_id) {
|
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(
|
throw new Error(
|
||||||
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
`No 'original_id' field found in ${file}. Perhaps you forgot to add it when importing prior versions of your docs?`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!metadata.id) {
|
if (!metadata.id) {
|
||||||
console.error(`No 'id' field found in ${file}.`);
|
console.error(`No 'id' field found in ${file}.`);
|
||||||
throw new Error(
|
throw new Error(`No 'id' field found in ${file}.`);
|
||||||
`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(
|
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?`
|
`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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const diffs = diff.diffChars(
|
return (
|
||||||
extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent,
|
extractMetadata(fs.readFileSync(latestFile, "utf8")).rawContent.trim() !==
|
||||||
extractMetadata(fs.readFileSync(file, "utf8")).rawContent
|
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),
|
// return metadata for a versioned file given the file, its version (requested),
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
"classnames": "^2.2.5",
|
"classnames": "^2.2.5",
|
||||||
"commander": "^2.11.0",
|
"commander": "^2.11.0",
|
||||||
"crowdin-cli": "^0.3.0",
|
"crowdin-cli": "^0.3.0",
|
||||||
"diff": "^3.3.0",
|
|
||||||
"escape-string-regexp": "^1.0.5",
|
"escape-string-regexp": "^1.0.5",
|
||||||
"express": "^4.15.3",
|
"express": "^4.15.3",
|
||||||
"feed": "^1.1.0",
|
"feed": "^1.1.0",
|
||||||
|
|
|
@ -808,10 +808,6 @@ detect-indent@^4.0.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
repeating "^2.0.0"
|
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:
|
ecc-jsbn@~0.1.1:
|
||||||
version "0.1.1"
|
version "0.1.1"
|
||||||
resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505"
|
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