Move directories-to-copy from build.pl to publish.xml.
authorCameron McCormack <cam@mcc.id.au>
Fri, 05 Apr 2013 16:57:36 +1100
changeset 71 03c2ca802c74
parent 70 1ec0dc40d161
child 72 59efecca3a36
Move directories-to-copy from build.pl to publish.xml.
build.py
publish/config.js
publish/publish.js
--- a/build.py	Fri Apr 05 14:17:08 2013 +1100
+++ b/build.py	Fri Apr 05 16:57:36 2013 +1100
@@ -10,19 +10,9 @@
 '''
 '''
 
-# It would be good if "tocopy" list could be extracted from
-# publish.xml instead of being hard coded here.
-
-tocopy = """
-  style
-  images
-  examples
-""".split()
-
-
-
 import os, sys, signal, commands
 from os.path import isfile, abspath, getmtime, exists, join, normpath
+from xml.dom import minidom
 import shutil
 
 def exit(code, *message):
@@ -115,7 +105,7 @@
       os.rmdir(join(parent, dir))
   sys.exit(0)
 
-# Get all the pages from publish.xml:
+# Get all the pages and resources from publish.xml:
 
 os.chdir(master_dir)
 status, output = getstatusoutput("node \"" +
@@ -126,6 +116,15 @@
 
 all = output.split()
 
+os.chdir(master_dir)
+status, output = getstatusoutput("node \"" +
+    native_path(join(tools_dir, "publish/publish.js")) + "\" --list-resources")
+os.chdir(repo_dir)
+if status != 0:
+  exit(1, 'FAIL: could not get list of resources')
+
+resources = output.split()
+
 # Build chapters as required:
 
 deps = [
@@ -186,7 +185,7 @@
   os.chdir(repo_dir) # chdir back
 
 # Copy over anything else that needs to be copied to 'publish':
-for f in tocopy:
+for f in resources:
   tocopypath = join(master_dir, f)
   if os.path.exists(tocopypath):
     copyto = os.path.join(publish_dir,os.path.basename(tocopypath))
--- a/publish/config.js	Fri Apr 05 14:17:08 2013 +1100
+++ b/publish/config.js	Fri Apr 05 16:57:36 2013 +1100
@@ -147,6 +147,13 @@
   }
   this.definitions = definitions.load(definitionsFilenamesAndBases.reverse());
 
+  this.resources = [];
+  for (var n = root.firstChild; n; n = n.nextSibling) {
+    if (n.nodeName == 'resource') {
+      this.resources.push(n.getAttribute('href'));
+    }
+  }
+
   this.interfacesFile = attr(root, 'interfaces', 'idl');
   this.pages = { };
   this.pageOrder = [];
--- a/publish/publish.js	Fri Apr 05 14:17:08 2013 +1100
+++ b/publish/publish.js	Fri Apr 05 16:57:36 2013 +1100
@@ -12,6 +12,8 @@
   console.error('');
   console.error('Options:');
   console.error('  --list-pages            Print the names of all pages of the specification.');
+  console.error('  --list-resources        Print the names of all resource files/directories');
+  console.error('                            to be copied to the publish directory.');
   console.error('  --build [PAGE ...]      Builds the specified pages, or all pages if');
   console.error('                            none specified.');
   console.error('  --build-single-page     Builds the single page version of the specification.');
@@ -26,6 +28,9 @@
       case '--list-pages':
         opts.listPages = true;
         break;
+      case '--list-resources':
+        opts.listResources = true;
+        break;
       case '--build':
         opts.build = true;
         break;
@@ -53,6 +58,10 @@
   console.log(conf.pageOrder.join('\n'));
 }
 
+function listResources() {
+  console.log(conf.resources.join('\n'));
+}
+
 function checkAllPagesValid(pages) {
   for (var i = 0; i < pages.length; i++) {
     if (!conf.pages[pages[i]]) {
@@ -193,7 +202,7 @@
 }
 
 var opts = parseOptions();
-if (opts.help || (!!opts.listPages + !!opts.build + !!opts.buildSinglePage) != 1) {
+if (opts.help || (!!opts.listPages + !!opts.listResources + !!opts.build + !!opts.buildSinglePage) != 1) {
   syntax();
   process.exit(opts.help ? 0 : 1);
 } else {
@@ -201,6 +210,8 @@
   conf.localStyleSheets = opts.localStyle;
   if (opts.listPages) {
     listPages();
+  } else if (opts.listResources) {
+    listResources();
   } else if (opts.build) {
     buildPages(opts.rest);
   } else if (opts.buildSinglePage) {