feat: add serve
This commit is contained in:
parent
4629cb17c5
commit
1f1e99e690
51
cli.py
51
cli.py
@ -5,6 +5,20 @@ 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")
|
||||||
@ -19,17 +33,26 @@ 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)
|
||||||
|
printDocument(issuePath, args.outDir, args.watch, args.verbose)
|
||||||
|
|
||||||
|
def serve(args):
|
||||||
|
"""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=8000, 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("get issues")
|
print("serve start")
|
||||||
p = subprocess.run(["deno", "run", "-A","tools/getIssue.ts", "--path",issuePath])
|
cmd = ["mdbook", "serve", "--port", str(args.port)]
|
||||||
p.check_returncode()
|
p = subprocess.Popen(cmd)
|
||||||
if args.verbose:
|
printDocument(issuePath, outDir, True, args.verbose)
|
||||||
print("build issues")
|
p.wait()
|
||||||
cmd = ["deno", "run", "-A","tools/printDocument.ts", "--issue_path", issuePath, "--outDir", args.outDir]
|
if p.returncode != 0:
|
||||||
if args.watch:
|
sys.exit(p.returncode)
|
||||||
cmd.append("--watch")
|
|
||||||
p = subprocess.run(cmd)
|
|
||||||
p.check_returncode()
|
|
||||||
|
|
||||||
def help(_args):
|
def help(_args):
|
||||||
global commandList
|
global commandList
|
||||||
@ -42,16 +65,14 @@ 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")
|
||||||
p = subprocess.run(["deno", "run", "-A","tools/getIssue.ts", "--path",issuePath])
|
updateIssue(issuePath, args.verbose)
|
||||||
p.check_returncode()
|
|
||||||
|
|
||||||
commandList = {
|
commandList = {
|
||||||
'build': build,
|
'build': build,
|
||||||
'help': help,
|
'help': help,
|
||||||
'issueUpdate': issueUpdate
|
'issueUpdate': issueUpdate,
|
||||||
|
'serve': serve
|
||||||
}
|
}
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
Loading…
Reference in New Issue
Block a user