Browse Source

Fix generators to work on windows;

bjorn 1 day ago
parent
commit
a11220b40f
2 changed files with 15 additions and 11 deletions
  1. 8 10
      api/generators/cats.lua
  2. 7 1
      api/generators/typescript.lua

+ 8 - 10
api/generators/cats.lua

@@ -14,20 +14,10 @@ local function getPath(filename, sep)
   return filename:match("(.*" .. sep .. ")")
 end
 
-local function ensureDirectoryExists(path)
-  os.execute("mkdir -p " .. path)
-end
-
 --- Writes `contents` into a file identified by `filename`.
 local function writeFile(filename, contents)
   local fullpath = ('%s/cats/%s'):format(root, filename)
 
-  -- make sure the directory exists
-  local path = getPath(fullpath)
-  if path then
-    ensureDirectoryExists(path)
-  end
-
   local file = io.open(fullpath, "w")
   if not file then
     print("Failed to open file for writing: " .. fullpath)
@@ -386,6 +376,14 @@ local function generateGlobalsDocumentation()
 end
 
 return function(api)
+  local library = root .. "/cats/library"
+
+  if lovr.system.getOS() == "Windows" then
+    os.execute("mkdir " .. library:gsub("/", "\\"))
+  else
+    os.execute("mkdir -p " .. library)
+  end
+
   generateModuleDocumentation(api)
   generateCallbackDocumentation(api)
   generateAddonConfig()

+ 7 - 1
api/generators/typescript.lua

@@ -216,7 +216,13 @@ declare interface Mat4 {
 
 return function (api)
   local path = lovr.filesystem.getSource() .. '/typescript'
-  os.execute("mkdir -p " .. path)
+
+  if lovr.system.getOS() == 'Windows' then
+    os.execute('mkdir ' .. path:gsub('/', '\\'))
+  else
+    os.execute('mkdir -p ' .. path)
+  end
+
   local out = io.open(path .. '/lovr-api.d.ts', 'w')
   assert(out)