From 6fad021d901520981d69eef02eb2090bf39367a7 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Thu, 12 Aug 2021 14:33:33 -0600 Subject: [PATCH] close #36 --- kiss/src/kiss/CompilerTools.hx | 30 +++++++++++++++++++- kiss/src/test/cases/CompilerToolsTestCase.hx | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/kiss/src/kiss/CompilerTools.hx b/kiss/src/kiss/CompilerTools.hx index 3503ae23..913bfa91 100644 --- a/kiss/src/kiss/CompilerTools.hx +++ b/kiss/src/kiss/CompilerTools.hx @@ -134,7 +134,35 @@ class CompilerTools { case JavaScript: command = "node"; scriptExt = "js"; - // npm install outputfolder + // npm install outputfolder + if (args.langProjectFile != null) { + // This can only be done in the current working directory, so the project file needs to be moved here + // Move existing package.json, package-lock.json, node_modules out of the way: + function move(file, newName) { + if (FileSystem.exists(file)) { + FileSystem.rename(file, newName); + } + } + move("package.json", "package.json.temp"); + move("package-lock.json", "package-lock.json.temp"); + move("node_modules", "node_modules.temp"); + + File.copy(args.langProjectFile, "package.json"); + + if (Sys.systemName() == "Windows") { + Prelude.assertProcess("cmd.exe", ["/c", 'npm', 'install']); + } else { + Prelude.assertProcess("npm", ['install']); + } + + FileSystem.deleteFile("package.json"); + move("node_modules", Prelude.joinPath(args.outputFolder, "node_modules")); + move("package-lock.json", Prelude.joinPath(args.outputFolder, "package-lock.json")); + + move("package.json.temp", "package.json"); + move("package-lock.json.temp", "package-lock.json"); + move("node_modules.temp", "node_modules"); + } case Python: command = "python"; scriptExt = "py"; diff --git a/kiss/src/test/cases/CompilerToolsTestCase.hx b/kiss/src/test/cases/CompilerToolsTestCase.hx index 64a652e2..096cd8ba 100644 --- a/kiss/src/test/cases/CompilerToolsTestCase.hx +++ b/kiss/src/test/cases/CompilerToolsTestCase.hx @@ -29,7 +29,7 @@ class CompilerToolsTestCase extends Test { return CompilerTools.compileFileToScript( "kiss/template/src/template/Main.kiss", JavaScript, { outputFolder: "bin/helloWorldJsTestWithPackageJson", - // langProjectFile: "kiss/src/test/files/package.json" + langProjectFile: "kiss/src/test/files/package.json" }); }