all repos — py-vite @ 5c4e42963e9466364eefcdb25240909e88a77c8b

the original vite, written in python

BREAKING: Rework `new` option

* `init` behaves like the old `new`
* `new` now creates a path under `pages`
Anirudh icyph0x@pm.me
Fri, 05 Apr 2019 00:53:47 +0530
commit

5c4e42963e9466364eefcdb25240909e88a77c8b

parent

089bb4080c0b1ad59034f972dd972202bec76f36

2 files changed, 35 insertions(+), 7 deletions(-)

jump to
M vite/cli.pyvite/cli.py

@@ -11,18 +11,27 @@ usage = lightblue('vite') + ' [options]'

parser = argparse.ArgumentParser(description=desc, usage=usage) parser.add_argument('-v', '--version', action='version', version='{version}'.format(version=__version__)) sp = parser.add_subparsers(dest='cmd', help='Options to help create, build and serve your project.') - spp = sp.add_parser('new') + #for cmd in ['init', 'new']: + sp_init = sp.add_parser('init') + sp_new = sp.add_parser('new') for cmd in ['build', 'serve']: sp.add_parser(cmd) - spp.add_argument('path') + sp_init.add_argument('path') + sp_new.add_argument('path') args = parser.parse_args() if len(sys.argv) == 1: parser.print_help() sys.exit(1) + elif args.cmd == 'init': + if args.path: + vite.create_project(args.path) + else: + parser.print_help() elif args.cmd == 'new': if args.path: - vite.create_project(args.path) + vite.import_config() + vite.create_path(args.path) else: parser.print_help() elif args.cmd == 'build':
M vite/vite.pyvite/vite.py

@@ -12,6 +12,7 @@ import time

import http.server import socketserver import shutil +import datetime from markdown2 import markdown_path from huepy import *

@@ -52,6 +53,27 @@ except FileExistsError:

print(bad('Error: specified path exists.')) +def create_path(path): + head, tail = os.path.split(path) + now = datetime.datetime.now() + today = now.strftime('%Y-%m-%d') + + try: + os.makedirs(os.path.join(PAGES_PATH, head)) + except FileExistsError: + pass + if os.path.exists(os.path.join(PAGES_PATH, head, tail)): + print(bad('Error: specified path exists.')) + else: + with open(os.path.join(PAGES_PATH, head, tail), 'w') as f: + f.write(f"""--- + template: + title: + date: {today} + ---\n""") + print(good('Created %s.') % (os.path.join(PAGES_PATH, head, tail))) + + def create_config(path): with open(os.path.join(path, 'config.py'), 'w') as f: f.write("""# config.py - Vite's configuration script

@@ -60,8 +82,7 @@ title = ''

author = '' header = '' footer = '' -template = 'index.html' # default is index.html - """) +template = 'index.html' # default is index.html\n""") def create_template(path):

@@ -181,8 +202,6 @@ sys.exit(1)

def clean(): - #shutil.rmtree(BUILD_PATH) - #os.makedirs(BUILD_PATH) for f in os.listdir(BUILD_PATH): fpath = os.path.join(BUILD_PATH, f) try: