Skip to content

Commit

Permalink
allow specifying site title via wq create
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Apr 19, 2021
1 parent a70779a commit 954c4ce
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 8 deletions.
2 changes: 1 addition & 1 deletion django_project
2 changes: 1 addition & 1 deletion packages/cra-template/template/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React + @wq/app</title>
<title>{{ title }}</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
2 changes: 1 addition & 1 deletion packages/cra-template/template/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "{{ project_name }}",
"name": "{{ project_name }} Project",
"name": "{{ title }}",
"icons": [
{
"src": "favicon.ico",
Expand Down
33 changes: 29 additions & 4 deletions projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class StartProjectCommand(startproject.Command):
def add_arguments(self, parser):
super(StartProjectCommand, self).add_arguments(parser)
parser.add_argument('--domain', help="Web Domain")
parser.add_argument('--title', help="Site Title")
parser.add_argument('--with-gis', help="Enable GeoDjango")
parser.add_argument('--with-npm', help="Enable NPM")
parser.add_argument('--wq-create-version', help="wq create version")
Expand All @@ -35,14 +36,17 @@ def add_arguments(self, parser):
@click.option(
"-d", "--domain", help='Web domain (e.g. example.wq.io)'
)
@click.option(
"-t", "--title", help="Site title + App label"
)
@click.option(
"--with-gis/--without-gis", default=None, help="Enable GeoDjango"
)
@click.option(
"--with-npm/--without-npm", default=None,
help="Enable NPM (& Create React App)"
)
def create(project_name, destination, domain=None,
def create(project_name, destination, domain=None, title=None,
with_gis=None, with_npm=None):
"""
Start a new project with wq.app and wq.db. A new Django project will be
Expand All @@ -57,10 +61,10 @@ def create(project_name, destination, domain=None,
See https://wq.io/docs/setup for more tips on getting started with wq.
"""
do_create(project_name, destination, domain, with_gis, with_npm)
do_create(project_name, destination, domain, title, with_gis, with_npm)


def do_create(project_name, destination, domain, with_gis, with_npm):
def do_create(project_name, destination, domain, title, with_gis, with_npm):
any_prompts = False

if project_name is None:
Expand All @@ -83,6 +87,16 @@ def do_create(project_name, destination, domain, with_gis, with_npm):
default='{}.example.org'.format(project_name)
)

if title is None:
any_prompts = True
title = click.prompt(
'Site title + App label',
default='{} Project'.format(project_name)
)
elif title == '__old__':
title = '{} Project'.format(project_name)


if with_gis is None:
any_prompts = True
with_gis = click.confirm(
Expand All @@ -106,6 +120,7 @@ def do_create(project_name, destination, domain, with_gis, with_npm):
template=template,
extensions="py,yml,conf,html,sh,js,css,json,xml,gitignore".split(","),
domain=domain,
title=title,
wq_create_version=VERSION,
with_gis=with_gis,
with_npm=with_npm,
Expand All @@ -128,6 +143,16 @@ def do_create(project_name, destination, domain, with_gis, with_npm):
os.path.join(path, project_name),
os.path.join(path, 'app'),
)
for filename in ('index.html', 'manifest.json'):
filepath = os.path.join(path, 'app', 'public', filename)
with open(filepath) as f:
content = f.read()

content = content.replace('{{ title }}', title)
content = content.replace('{{ project_name }}', project_name)

with open(filepath, 'w') as f:
f.write(content)
else:
os.remove(os.path.join(path, 'app', 'README.md'))

Expand Down Expand Up @@ -180,4 +205,4 @@ def start(project_name, destination, domain=None,
(DEPRECATED) Alias for wq create.
"""
click.echo('This command is deprecated. Use "wq create" instead.')
do_create(project_name, destination, domain, with_gis, with_npm)
do_create(project_name, destination, domain, '__old__', with_gis, with_npm)
7 changes: 7 additions & 0 deletions tests/expected/config1.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"site_title": "test Project",
"pages": {
"index": {
"url": "",
"name": "index",
"verbose_name": "test Project",
"show_in_index": false
},
"login": {
"name": "login",
"url": "login"
Expand Down
7 changes: 7 additions & 0 deletions tests/expected/config2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"site_title": "test Project",
"pages": {
"index": {
"url": "",
"name": "index",
"verbose_name": "test Project",
"show_in_index": false
},
"location": {
"name": "location",
"verbose_name": "location",
Expand Down
7 changes: 7 additions & 0 deletions tests/expected/config3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"site_title": "test Project",
"pages": {
"index": {
"url": "",
"name": "index",
"verbose_name": "test Project",
"show_in_index": false
},
"location": {
"name": "location",
"verbose_name": "location",
Expand Down
2 changes: 1 addition & 1 deletion tests/test-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ else
NPM_FLAG="--without-npm"
fi;

wq create test_project ./test_project -d test.wq.io $NPM_FLAG $GIS_FLAG
wq create test_project ./test_project -d test.wq.io -t "test Project" $NPM_FLAG $GIS_FLAG

# Verify ./deploy.sh works
cd test_project
Expand Down

0 comments on commit 954c4ce

Please sign in to comment.