Parcourir la source

fix bazel file finding

Getty Ritter il y a 3 ans
Parent
commit
56ce33fcc5
3 fichiers modifiés avec 31 ajouts et 13 suppressions
  1. 11 1
      BUILD.bazel
  2. 12 11
      generate.py
  3. 8 1
      projects.yaml

+ 11 - 1
BUILD.bazel

@@ -11,6 +11,16 @@ py_binary(
     ]
     ]
 )
 )
 
 
+filegroup(
+    name="static",
+    srcs=glob(["static/*"]),
+)
+
+filegroup(
+    name="templates",
+    srcs=glob(["templates/*"]),
+)
+
 genrule(
 genrule(
     name = "out",
     name = "out",
     srcs = [
     srcs = [
@@ -20,5 +30,5 @@ genrule(
     ],
     ],
     tools = [":generate"],
     tools = [":generate"],
     outs = ["output"],
     outs = ["output"],
-    cmd = "$(location :generate) $(location :projects.yaml) $(location :static) $(location :templates) $(location output)",
+    cmd = "$(location :generate) $(location output) $(location :projects.yaml) $(locations :static) $(locations :templates)",
 )
 )

+ 12 - 11
generate.py

@@ -9,7 +9,14 @@ import sys
 import tempfile
 import tempfile
 import yaml
 import yaml
 
 
-def main(projects_yaml, static_dir, template_dir, output_file=None):
+def find_asset(name, assets):
+    for a in assets:
+        if os.path.basename(a) == name:
+            return a
+    raise Exception(f"Unable to find {name} in assets")
+
+def main(output_file, projects_yaml, *assets):
+
     with open(projects_yaml) as f:
     with open(projects_yaml) as f:
         project_data = yaml.safe_load(f)
         project_data = yaml.safe_load(f)
 
 
@@ -19,12 +26,12 @@ def main(projects_yaml, static_dir, template_dir, output_file=None):
         for s in p.get('stuff', ()):
         for s in p.get('stuff', ()):
             s['text'] = markdown.markdown(s['text'])
             s['text'] = markdown.markdown(s['text'])
 
 
-    with open(os.path.join(static_dir, 'main.css')) as f:
+    with open(find_asset('main.css', assets)) as f:
         css = f.read()
         css = f.read()
-    with open(os.path.join(static_dir, 'main.js')) as f:
+    with open(find_asset('main.js', assets)) as f:
         javascript = f.read()
         javascript = f.read()
 
 
-    with open(os.path.join(template_dir, 'main.mustache')) as f:
+    with open(find_asset('main.mustache', assets)) as f:
         template = f.read()
         template = f.read()
 
 
     year = datetime.datetime.now().year
     year = datetime.datetime.now().year
@@ -47,17 +54,11 @@ def main(projects_yaml, static_dir, template_dir, output_file=None):
         with open(os.path.join(tmpdir, 'index.html'), 'w') as f:
         with open(os.path.join(tmpdir, 'index.html'), 'w') as f:
             print(index_html, file=f)
             print(index_html, file=f)
         shutil.copyfile(
         shutil.copyfile(
-            os.path.join(static_dir, 'raleway.ttf'),
+            find_asset('raleway.ttf', assets),
             os.path.join(tmpdir, 'raleway.ttf'),
             os.path.join(tmpdir, 'raleway.ttf'),
         )
         )
         shutil.make_archive('output', 'zip', tmpdir)
         shutil.make_archive('output', 'zip', tmpdir)
         shutil.move('output.zip', output_file)
         shutil.move('output.zip', output_file)
 
 
 if __name__ == '__main__':
 if __name__ == '__main__':
-    if len(sys.argv) not in (4, 5):
-        print(
-            f"{sys.argv[0]}: [project.yaml] [static/] [templates/] [output-zip]",
-            file=sys.stderr,
-        )
-        sys.exit(1)
     main(*sys.argv[1:])
     main(*sys.argv[1:])

+ 8 - 1
projects.yaml

@@ -50,6 +50,12 @@ projects:
       related, and others that are about designing physical objects
       related, and others that are about designing physical objects
       for my own use. As of right now, much of my physical design work
       for my own use. As of right now, much of my physical design work
       is done with the help of a laser-cutter.
       is done with the help of a laser-cutter.
+    stuff:
+      - name: cocktail.graphics
+        text: >
+          [cocktail.graphics](https://cocktail.graphics/) is an
+          information design project aimed at doing visual graph-style
+          recipes for cocktails.
   - name: writing
   - name: writing
     text: >
     text: >
       I write a lot of non-fiction blog posts, and I also write some
       I write a lot of non-fiction blog posts, and I also write some
@@ -63,4 +69,5 @@ projects:
       forward.
       forward.
     stuff:
     stuff:
       - name: Logomancy
       - name: Logomancy
-        text: blah
+        text: >
+          A tiny party game inspired by [The Adventure Zone]().