-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reimplement vendor_build.py and vendor_license.py in JS.
- Loading branch information
Showing
6 changed files
with
129 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
const YAML = require("yamljs"); | ||
const { copyFileSync, readdirSync, statSync, mkdirSync } = require("fs"); | ||
const { join, basename, dirname } = require("path"); | ||
const firstBy = require("thenby"); | ||
|
||
function isDirectory(file) { | ||
return statSync(file).isDirectory(); | ||
} | ||
|
||
function copyOverwrite(src, dst) { | ||
if (isDirectory(src)) { | ||
readdirSync(src).forEach(file => | ||
copyOverwrite(join(src, file), join(dst, file)) | ||
); | ||
} else { | ||
let dstFile, dstDir; | ||
if (dst.endsWith("/")) { | ||
dstDir = dst; | ||
dstFile = join(dst, basename(src)); | ||
} else { | ||
dstDir = dirname(dst); | ||
dstFile = dst; | ||
} | ||
console.log(" copying", src, "to", dstFile); | ||
mkdirSync(dstDir, { recursive: true }); | ||
copyFileSync(src, dstFile); | ||
} | ||
} | ||
|
||
function main() { | ||
const vendor = YAML.load("vendor.yaml"); | ||
const sortedLibs = Object.entries(vendor["libs"]).sort( | ||
firstBy(([, lib]) => lib["priority"]) | ||
); | ||
for (const [libName, lib] of sortedLibs) { | ||
if (!lib["npmDir"] || !lib["files"]) { | ||
continue; | ||
} | ||
console.log("Processing:", libName); | ||
const distDir = `./lib/_npm/${lib["distDir"] || lib["npmDir"]}/`; | ||
for (let file of lib["files"]) { | ||
const allFilesInDir = file.endsWith("/*"); | ||
if (allFilesInDir) { | ||
file = file.replace("/*", ""); | ||
} | ||
|
||
srcPattern = `./node_modules/${lib["npmDir"]}/${file}`; | ||
if (isDirectory(srcPattern) && !allFilesInDir) { | ||
copyOverwrite(srcPattern, join(distDir, file)); | ||
} else { | ||
copyOverwrite(srcPattern, distDir); | ||
} | ||
} | ||
} | ||
|
||
require("./vendor_license"); | ||
} | ||
|
||
main(); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const YAML = require("yamljs"); | ||
const { readdirSync, readFileSync, writeFileSync, statSync } = require("fs"); | ||
const { join, basename } = require("path"); | ||
const firstBy = require("thenby"); | ||
|
||
function isLicenseFilename(name) { | ||
const fn = basename(name); | ||
return fn.startsWith("LICENSE") || fn.startsWith("license"); | ||
} | ||
|
||
function findLicenses(dst) { | ||
return readdirSync(dst) | ||
.map(file => join(dst, file)) | ||
.filter(isLicenseFilename); | ||
} | ||
|
||
function main() { | ||
const vendor = YAML.load("vendor.yaml"); | ||
let licResult = ""; | ||
let wikiResult = "# 3rd-party libraries\n\n"; | ||
const sortedLibs = Object.entries(vendor["libs"]).sort( | ||
firstBy(([libName]) => libName) | ||
); | ||
for (const [libName, lib] of sortedLibs) { | ||
console.log("Processing", libName); | ||
const distDir = `lib/${lib["npmDir"] ? "_npm/" : ""}${lib["distDir"] || lib["npmDir"]}/`; | ||
const licFns = findLicenses(distDir); | ||
|
||
if (licFns.length != 1) { | ||
console.log(`License not found: ${distDir}:`, licFns); | ||
continue; | ||
} | ||
|
||
licResult += "=".repeat(80) + "\n"; | ||
licResult += " ".repeat(((80 - libName.length) / 2) | 0) + libName + "\n"; | ||
licResult += "\n"; | ||
licResult += `License name: ${lib["licenseName"]}\n`; | ||
licResult += ` License URL: ${lib["licenseUrl"]}\n`; | ||
licResult += ` License applies to files under the folder ${distDir}\n`; | ||
licResult += "\n"; | ||
|
||
wikiResult += `## ${libName}\n`; | ||
|
||
if (lib["website"]) { | ||
licResult += `Website: ${lib["website"]}\n`; | ||
wikiResult += `Website: ${lib["website"]}\n\n`; | ||
} | ||
|
||
if (lib["source"]) { | ||
licResult += `Source: ${lib["source"]}\n`; | ||
wikiResult += `Source: ${lib["source"]}\n\n`; | ||
} | ||
|
||
wikiResult += `License: ${lib["licenseName"]} (${lib["licenseUrl"]})\n\n`; | ||
|
||
licResult += "=".repeat(80) + "\n"; | ||
licResult += | ||
readFileSync(licFns[0], { encoding: "utf-8" }) | ||
.trim() | ||
.replace(/\r\n/g, "\n") + "\n"; | ||
licResult += "=".repeat(80) + "\n\n"; | ||
} | ||
|
||
writeFileSync("LICENSE-3RD-PARTY.txt", licResult.trim()); | ||
writeFileSync("docs/wiki/3rd-party-libraries.md", wikiResult.trim()); | ||
} | ||
|
||
main(); |
This file was deleted.
Oops, something went wrong.