bin/serve-stub
[mdref/mdref] / bin / stub2ref
index 78c7d1799b64b714399f7df48b2fefc84a9ac8ec..b1753dc9cbda3eaf2287f2b276f0d953844a2ac0 100755 (executable)
@@ -19,9 +19,19 @@ if (!is_dir($destination)) {
        mkdir($destination) || exit -1;
 }
 if (!file_exists("$destination/$namespace.mdref")) {
-       fprintf(STDERR, "Missing $destination/$namespace.mdref; generated default.\n");
+       fprintf(STDERR, "Missing $destination/$namespace.mdref; generating default.\n");
        file_put_contents("$destination/$namespace.mdref", "./%s") || exit -2;
 }
+if (!file_exists("$destination/$namespace.md")) {
+       fprintf(STDERR, "Missing $destination/$namespace.mdref; generating default from README.\n");
+       $readme = dirname($argv[2]) . "/README.md";
+       if (!file_exists($readme))  {
+               fprintf(STDERR, "Missing $readme; creating empty $namespace.md");
+               touch("$destination/$namespace.md");
+       } else {
+               link(realpath($readme), "$destination/$namespace.md");
+       }
+}
 
 $inspector = new Inspector;
 $inspector->inspectNamespace($namespace);