Skip to content

Commit

Permalink
Manifest Class
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte committed Aug 20, 2017
1 parent 7c382bb commit 748691e
Showing 1 changed file with 89 additions and 33 deletions.
122 changes: 89 additions & 33 deletions wasp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,90 @@ import os
import subprocess


class Manifest:
def __init__(self, details: dict):
self.details = details

def generate(self):
manifest = {
"name": self.details['name'],
"short_name": self.details['short_name'],
"theme_color": self.details['theme_color'],
"background_color": self.details['background_color'],
"start_url": self.details['start_url'],
"display": self.details['display'],
"lang": self.details['lang'],
"orientation": self.details['orientation'],
}

with open('manifest.json', 'w') as fp:
json.dump(manifest, fp, sort_keys=True, indent=4, separators=(',', ': '))

def set(self):
self.short_name()
self.theme_color()
self.background_color()
self.display()
self.start_url()
self.lang()
self.orientation()

def short_name(self):
self.details['short_name'] = input("Short Name (" + self.details['name'][0:12] + "): ")
if self.details['short_name'] == '':
self.details['short_name'] = self.details['name'][0:12]

def theme_color(self):
# TODO: Default
# TODO: Validation
self.details['theme_color'] = input("Theme Color: ")

def background_color(self):
# TODO: Default
# TODO: Validation
self.details['background_color'] = input("Background Color: ")

def start_url(self):
# TODO: Default
self.details['start_url'] = input("Starting URL: ")

def lang(self):
# TODO: Default
# TODO: Validation
self.details['lang'] = input("Language: ")

def display(self):
self.details['display'] = input("Display (minimal-ui): ")
if self.details['display'].lower() == "minimal-ui" \
or self.details['display'].lower() == "browser" \
or self.details['display'].lower() == "standalone" \
or self.details['display'].lower() == "fullscreen":
self.details['display'] = self.details['display'].lower()
elif self.details['orientation'] == '':
self.details['orientation'] = "minimal-ui"
else:
print("Please enter one of the options from https://developer.mozilla.org/en-US/docs/Web/Manifest#display")
self.display()

def orientation(self):
self.details['orientation'] = input("Display Orientation (any): ")
if self.details['orientation'].lower() == "any" \
or self.details['orientation'].lower() == "natural" \
or self.details['orientation'].lower() == "landscape" \
or self.details['orientation'].lower() == "landscape-primary" \
or self.details['orientation'].lower() == "landscape-secondary" \
or self.details['orientation'].lower() == "portrait" \
or self.details['orientation'].lower() == "portrait-primary" \
or self.details['orientation'].lower() == "portrait-secondary":
self.details['orientation'] = self.details['orientation'].lower()
elif self.details['orientation'] == '':
self.details['orientation'] = "any"
else:
print(
"Please enter one of the options from https://developer.mozilla.org/en-US/docs/Web/Manifest#orientation")
self.orientation()


def privacy():
input_val = input("Privacy (private): ")
if input_val.lower() == "public" or input_val.lower() == "private":
Expand All @@ -17,36 +101,18 @@ def privacy():
privacy()


def manifest(details: dict):
manifest = {
"name": details['name'],
"short_name": details['short_name'],
"theme_color": details['theme_color'],
"background_color": details['background_color'],
"start_url": details['start_url'],
"display": details['display'],
"lang": details['lang'],
"orientation": details['orientation'],
}

with open('manifest.json', 'w') as fp:
json.dump(manifest, fp, sort_keys=True, indent=4, separators=(',', ': '))


try:
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('task', metavar='task', type=str, help='A task to perform. Options : init, update, tag')
parser.add_argument('-m', '--manifest', action='store_true', help='Generate a manifest.json for your project')
parser.add_argument('-b', '--bower', action='store_true', help='Generate a bower.json for your project')

args = parser.parse_args()
print(args)

directory = os.path.basename(os.path.dirname(os.path.realpath(__file__)))

process = subprocess.Popen(["git", "config", "--get", "user.name"], stdout=subprocess.PIPE)
output = (process.communicate()[0]).decode("utf-8").strip().split('\n')[0]
print(output)
author = (process.communicate()[0]).decode("utf-8").strip().split('\n')[0]

if args.task == 'init':
details = {}
Expand All @@ -58,26 +124,16 @@ try:
details['name'] = directory[0:45]
details['description'] = input("Description: ")
details['keywords'] = input("Keywords: ")
details['authors'] = input("Authors: ")
details['authors'] = input("Authors (" + author + "): ")
if details['authors'] == '':
details['authors'] = author
details['licence'] = input("Licence: ")
details['website'] = input("Website: ")
details['privacy'] = privacy()

if args.manifest:
print("\nNow let's collect some Manifest Information\n")
details['short_name'] = input("Short Name (" + details['name'][0:12] + "): ")
if details['short_name'] == '':
details['short_name'] = details['name'][0:12]
details['theme_color'] = input("Theme Color: ")
details['background_color'] = input("Background Color: ")
details['display'] = input("Display (minimal-ui): ")
if details['display'] == '':
details['display'] = "minimal-ui"
details['start_url'] = input("Starting URL: ")
details['lang'] = input("Language: ")
details['orientation'] = input("Display Orientation: ")

manifest(details)
Manifest(details).set()

with open('.wasp.json', 'w') as fp:
json.dump(details, fp, sort_keys=True, indent=4, separators=(',', ': '))
Expand Down

0 comments on commit 748691e

Please sign in to comment.