Compare commits
No commits in common. "def17c7072271005f3d9d8cfdf2e134578f77916" and "4629cb17c56261c50a5a1faf918697d66eadc511" have entirely different histories.
def17c7072
...
4629cb17c5
3
.gitattributes
vendored
3
.gitattributes
vendored
@ -1,2 +1 @@
|
|||||||
* text eol=lf
|
* text eol=lf
|
||||||
*.pdf binary
|
|
75
cli.py
75
cli.py
@ -5,20 +5,6 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def updateIssue(issuePath: str, verbose = False):
|
|
||||||
if verbose:
|
|
||||||
print("get issues")
|
|
||||||
p = subprocess.run(["deno", "run", "-A","tools/getIssue.ts", "--path",issuePath])
|
|
||||||
p.check_returncode()
|
|
||||||
|
|
||||||
def printDocument(issuePath:str, outDir:str, watch = False, verbose = False):
|
|
||||||
if verbose:
|
|
||||||
print("build document")
|
|
||||||
cmd = ["deno", "run", "-A","tools/printDocument.ts", "--issue_path", issuePath, "--outDir", outDir]
|
|
||||||
if watch:
|
|
||||||
cmd.append("--watch")
|
|
||||||
p = subprocess.run(cmd)
|
|
||||||
p.check_returncode()
|
|
||||||
|
|
||||||
def build(args):
|
def build(args):
|
||||||
parser = argparse.ArgumentParser(description='Compiling the documentation', prog="cli.py build")
|
parser = argparse.ArgumentParser(description='Compiling the documentation', prog="cli.py build")
|
||||||
@ -33,26 +19,17 @@ def build(args):
|
|||||||
|
|
||||||
issuePath = os.path.join(args.outDir,"issues.json")
|
issuePath = os.path.join(args.outDir,"issues.json")
|
||||||
if args.update_issues:
|
if args.update_issues:
|
||||||
updateIssue(issuePath, args.verbose)
|
if args.verbose:
|
||||||
printDocument(issuePath, args.outDir, args.watch, args.verbose)
|
print("get issues")
|
||||||
|
p = subprocess.run(["deno", "run", "-A","tools/getIssue.ts", "--path",issuePath])
|
||||||
def serve(args):
|
p.check_returncode()
|
||||||
"""serve the documentation and reload on changes"""
|
|
||||||
parser = argparse.ArgumentParser(description='Serve the documentation and reload changes', prog="cli.py serve")
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode')
|
|
||||||
parser.add_argument('-p', '--port', default=3000, help='port')
|
|
||||||
parser.add_argument('--update_issues', action='store_true', help='update issues')
|
|
||||||
outDir = "build"
|
|
||||||
issuePath = os.path.join(outDir,"issues.json")
|
|
||||||
args = parser.parse_args(args)
|
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print("serve start")
|
print("build issues")
|
||||||
cmd = ["mdbook", "serve", "--port", str(args.port)]
|
cmd = ["deno", "run", "-A","tools/printDocument.ts", "--issue_path", issuePath, "--outDir", args.outDir]
|
||||||
p = subprocess.Popen(cmd)
|
if args.watch:
|
||||||
printDocument(issuePath, outDir, True, args.verbose)
|
cmd.append("--watch")
|
||||||
p.wait()
|
p = subprocess.run(cmd)
|
||||||
if p.returncode != 0:
|
p.check_returncode()
|
||||||
sys.exit(p.returncode)
|
|
||||||
|
|
||||||
def help(_args):
|
def help(_args):
|
||||||
global commandList
|
global commandList
|
||||||
@ -65,40 +42,16 @@ def issueUpdate(args):
|
|||||||
parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode')
|
parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode')
|
||||||
parser.add_argument('--outDir', default="build", help='output directory')
|
parser.add_argument('--outDir', default="build", help='output directory')
|
||||||
args = parser.parse_args(args)
|
args = parser.parse_args(args)
|
||||||
|
if args.verbose:
|
||||||
|
print("update issues")
|
||||||
issuePath = os.path.join(args.outDir,"issues.json")
|
issuePath = os.path.join(args.outDir,"issues.json")
|
||||||
updateIssue(issuePath, args.verbose)
|
p = subprocess.run(["deno", "run", "-A","tools/getIssue.ts", "--path",issuePath])
|
||||||
|
|
||||||
def buildPdf(args):
|
|
||||||
parser = argparse.ArgumentParser(description='Print to pdf', prog="cli.py buildPdf")
|
|
||||||
parser.add_argument('-v', '--verbose', action='store_true', help='verbose mode')
|
|
||||||
parser.add_argument('--outDir', default="build/doc.pdf", help='output directory')
|
|
||||||
parser.add_argument('--browser-path', help='path to the browser')
|
|
||||||
args = parser.parse_args(args)
|
|
||||||
absPath = os.path.normpath(os.path.join( os.getcwd(),'book' , 'print.html' )).replace('\\', '/')
|
|
||||||
url = f"file://{absPath}"
|
|
||||||
if args.verbose:
|
|
||||||
print("build start")
|
|
||||||
print("print url", url)
|
|
||||||
cmd = ["deno", "run","--no-check","--unstable" ,"-A","tools/printPdf.ts", "--outDir", args.outDir, "--url", url]
|
|
||||||
if args.browser_path:
|
|
||||||
cmd.append("--chromeDir")
|
|
||||||
cmd.append(args.browser_path)
|
|
||||||
if args.verbose:
|
|
||||||
print("cmd: ", " ".join(cmd))
|
|
||||||
p = subprocess.run(cmd)
|
|
||||||
p.check_returncode()
|
|
||||||
cmd = ["java", "-jar", "tools/pdfbox-app-2.0.26.jar", "PDFMerger", "cover.pdf", args.outDir, args.outDir]
|
|
||||||
if args.verbose:
|
|
||||||
print("merge cmd: ", " ".join(cmd))
|
|
||||||
p = subprocess.run(cmd)
|
|
||||||
p.check_returncode()
|
p.check_returncode()
|
||||||
|
|
||||||
commandList = {
|
commandList = {
|
||||||
'build': build,
|
'build': build,
|
||||||
'help': help,
|
'help': help,
|
||||||
'issueUpdate': issueUpdate,
|
'issueUpdate': issueUpdate
|
||||||
'serve': serve,
|
|
||||||
'buildPdf': buildPdf
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
import puppeteer from "https://deno.land/x/puppeteer@9.0.2/mod.ts";
|
|
||||||
import { parse as argParse } from "https://deno.land/std@0.136.0/flags/mod.ts";
|
|
||||||
import {join as pathJoin} from "https://deno.land/std@0.136.0/path/mod.ts";
|
|
||||||
|
|
||||||
const executablePathMap = {
|
|
||||||
windows: "C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
|
|
||||||
//"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
|
|
||||||
darwin: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
||||||
linux: "/usr/bin/chromium-browser",
|
|
||||||
};
|
|
||||||
|
|
||||||
function findChromeDir(){
|
|
||||||
const dir = executablePathMap[Deno.build.os];
|
|
||||||
if (Deno.build.os === "linux"){
|
|
||||||
const pathes = Deno.env.get("PATH")?.split(";");
|
|
||||||
if(!pathes){
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
for (const path of pathes){
|
|
||||||
const entries = [...Deno.readDirSync(path)];
|
|
||||||
const chrome = entries.find((entry) => entry.name === "chrome");
|
|
||||||
if(chrome) {
|
|
||||||
return pathJoin(path, chrome.name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function main() {
|
|
||||||
const args = argParse(Deno.args);
|
|
||||||
let { url, outDir, chromeDir } = args;
|
|
||||||
if (!url) {
|
|
||||||
console.error("No url provided.");
|
|
||||||
Deno.exit(1);
|
|
||||||
}
|
|
||||||
outDir = outDir ?? "out.pdf";
|
|
||||||
if(!chromeDir) {
|
|
||||||
console.log("No chromeDir provided. Try to find chrome.");
|
|
||||||
chromeDir = findChromeDir();
|
|
||||||
console.log(`chromeDir: ${chromeDir}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const browser = await puppeteer.launch({
|
|
||||||
product: "chrome",
|
|
||||||
headless: true,
|
|
||||||
executablePath: chromeDir,
|
|
||||||
});
|
|
||||||
|
|
||||||
const page = await browser.newPage();
|
|
||||||
console.log(`goto url ${url}`);
|
|
||||||
await page.goto(url, {
|
|
||||||
waitUntil: "networkidle2",
|
|
||||||
});
|
|
||||||
await page.pdf({
|
|
||||||
path: outDir,
|
|
||||||
margin: {
|
|
||||||
bottom: "1cm",
|
|
||||||
left: "1cm",
|
|
||||||
right: "1cm",
|
|
||||||
top: "1cm",
|
|
||||||
}
|
|
||||||
});
|
|
||||||
await browser.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
main();
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user