vite.py (view raw)
1"""
2Vite - A simple and minimal static site generator.
3"""
4
5import sys
6import argparse
7import errno
8import pathlib
9import os
10import shutil
11
12parser = argparse.ArgumentParser(description='A simple and mnml static site generator.')
13parser.add_argument('action', choices=['new', 'build'])
14# TODO: add help for each action
15parser.add_argument('path', nargs='*')
16
17if len(sys.argv) == 1:
18 parser.print_help()
19 sys.exit(1)
20
21args = parser.parse_args()
22project_path = args.path[0]
23
24def create_project(path):
25 try:
26 abs_path = pathlib.Path(path).resolve()
27 pathlib.Path(path + '/pages').mkdir(parents=True, exist_ok=False)
28 pathlib.Path(path + '/build').mkdir(exist_ok=False)
29 shutil.copy('make.py', path)
30 print('Created project directory at %s.' % (abs_path))
31 except FileExistsError as e:
32 print('Error: specified path exists.')
33
34def build_project(path):
35 try:
36 sys.path.append(path)
37 os.chdir(path)
38 import make
39 except FileNotFoundError as e:
40 print('Error: no such file or directory: %s' % (path))
41
42def main():
43 if(args.action == 'new'):
44 create_project(project_path)
45 elif(args.action == 'build'):
46 build_project(project_path)
47
48if __name__ == "__main__":
49 main()