all repos — py-vite @ ed07f57205cd75fbc5a914bbfb4d5a90f54005e0

the original vite, written in python

feat: integrate build into vite.py (not entirely working)
icyphox icyph0x@protonmail.com
Fri, 16 Mar 2018 12:04:33 +0530
commit

ed07f57205cd75fbc5a914bbfb4d5a90f54005e0

parent

2742e329085f5cad70a53ad7e77e4b36ddb677ee

1 files changed, 15 insertions(+), 6 deletions(-)

jump to
M vite.pyvite.py

@@ -6,10 +6,12 @@ import sys

import argparse import errno import pathlib +import os import shutil parser = argparse.ArgumentParser(description='A simple and mnml static site generator.') -parser.add_argument('action', choices=['new'], help='Create a new project.') +parser.add_argument('action', choices=['new', 'build']) +# TODO: add help for each action parser.add_argument('path', nargs='*') if len(sys.argv) == 1:

@@ -19,21 +21,28 @@

args = parser.parse_args() project_path = args.path[0] -def create_dirs(path): +def create_project(path): try: abs_path = pathlib.Path(path).resolve() pathlib.Path(path + '/pages').mkdir(parents=True, exist_ok=False) pathlib.Path(path + '/build').mkdir(exist_ok=False) - cp_make(path) + shutil.copy('make.py', path) print('Created project directory at %s.' % (abs_path)) except FileExistsError as e: print('Error: specified path exists.') -def cp_make(path): - shutil.copy('make.py', path) +def build_project(path): + try: + os.chdir(path) + import make.py + except FileNotFoundError as e: + print('Error: no such file or directory: %s' % (path)) def main(): - create_dirs(project_path) + if(args.action == 'new'): + create_project(project_path) + elif(args.action == 'build'): + build_project(project_path) if __name__ == "__main__": main()