From bdbfec40f9262fa4ee66a15789d69b8ab108aa4c Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sun, 11 Aug 2024 16:59:49 +0800 Subject: [PATCH] update --- .vscode/settings.json | 5 +++++ package.json | 3 ++- src/Project/CppProject.ts | 6 +++++- src/Project/Project.ts | 1 - src/Project/interface/HaveCompiler.ts | 5 +++++ src/Project/interface/Optimize.ts | 3 +++ src/Tools/DebugPrint.ts | 6 ++++-- src/Tools/GetExecutablePathsFromEnv.ts | 6 ++++-- src/Tools/PrintErrorOrDebug.ts | 16 ++++++++++++++++ src/Tools/TryGetCompilerVersion.ts | 1 - src/index.ts | 26 +++++++++++++++++++++++++- tests/test2/nmake.ts | 1 + 12 files changed, 70 insertions(+), 9 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 src/Project/interface/HaveCompiler.ts create mode 100644 src/Project/interface/Optimize.ts create mode 100644 src/Tools/PrintErrorOrDebug.ts create mode 100644 tests/test2/nmake.ts diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..b91d7d1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cSpell.words": [ + "Zengtudor" + ] +} \ No newline at end of file diff --git a/package.json b/package.json index b759d90..927b4bb 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "typescript": "^5.5.4" }, "dependencies": { - "minimist": "^1.2.8" + "minimist": "^1.2.8", + "ts-node": "^10.9.2" } } diff --git a/src/Project/CppProject.ts b/src/Project/CppProject.ts index 664f4fb..0808190 100644 --- a/src/Project/CppProject.ts +++ b/src/Project/CppProject.ts @@ -1,11 +1,14 @@ import GppCompiler from "../Compiler/GppCompiler"; +import HaveCompiler from "./interface/HaveCompiler"; +import Optimize from "./interface/Optimize"; import SourceFiles from "./interface/SourceFiles"; import Project from "./Project"; -export default class CppProject implements Project , SourceFiles { +export default class CppProject implements Project , SourceFiles,HaveCompiler,Optimize { name: string; compiler: GppCompiler; sourceFiles: string[]=[]; + optimize: "fast" | "fastest" | "normal" = "fast" constructor(name:string) constructor(name:string,compiler:GppCompiler) @@ -17,5 +20,6 @@ export default class CppProject implements Project , SourceFiles { this.compiler=new GppCompiler() } this.name=name + } } \ No newline at end of file diff --git a/src/Project/Project.ts b/src/Project/Project.ts index 6a9475b..3195a0a 100644 --- a/src/Project/Project.ts +++ b/src/Project/Project.ts @@ -2,5 +2,4 @@ import Compiler from "../Compiler/Compiler" export default interface Project{ name:string - compiler:Compiler } \ No newline at end of file diff --git a/src/Project/interface/HaveCompiler.ts b/src/Project/interface/HaveCompiler.ts new file mode 100644 index 0000000..ac159f7 --- /dev/null +++ b/src/Project/interface/HaveCompiler.ts @@ -0,0 +1,5 @@ +import Compiler from "../../Compiler/Compiler"; + +export default interface HaveCompiler{ + compiler:Compiler +} \ No newline at end of file diff --git a/src/Project/interface/Optimize.ts b/src/Project/interface/Optimize.ts new file mode 100644 index 0000000..8a505fc --- /dev/null +++ b/src/Project/interface/Optimize.ts @@ -0,0 +1,3 @@ +export default interface Optimize{ + optimize:"fast"|"fastest"|"normal" +} \ No newline at end of file diff --git a/src/Tools/DebugPrint.ts b/src/Tools/DebugPrint.ts index 109861a..dfa15d9 100644 --- a/src/Tools/DebugPrint.ts +++ b/src/Tools/DebugPrint.ts @@ -1,6 +1,8 @@ -const printDebug = (m:string)=>{ +const printDebug = (...m:string[])=>{ if((global as any).isDebug){ - console.log(`[Debug] ${m}`) + m.forEach(e=>{ + console.log(`[Debug] ${e}`) + }) } } diff --git a/src/Tools/GetExecutablePathsFromEnv.ts b/src/Tools/GetExecutablePathsFromEnv.ts index 1efea02..e33aa59 100644 --- a/src/Tools/GetExecutablePathsFromEnv.ts +++ b/src/Tools/GetExecutablePathsFromEnv.ts @@ -2,8 +2,10 @@ import getPathsFromEnv from "./GetPathsFromEnv"; const getExecutablePathsFromEnv = (name:string):string[]=>{ const ret:string[]=[]; - getPathsFromEnv(name).forEach(e=>ret.push(e)) - getPathsFromEnv(`${name}.exe`).forEach(e=>ret.push(e)) + const suffixes:string[] = ["",".exe"] + suffixes.forEach(v=>{ + getPathsFromEnv(`${name}${v}`).forEach(e=>ret.push(e)) + }) return ret } export default getExecutablePathsFromEnv \ No newline at end of file diff --git a/src/Tools/PrintErrorOrDebug.ts b/src/Tools/PrintErrorOrDebug.ts new file mode 100644 index 0000000..620195e --- /dev/null +++ b/src/Tools/PrintErrorOrDebug.ts @@ -0,0 +1,16 @@ +import { exit } from "process" + +const printErrorOrDebug = (...m:string[])=>{ + let str = "" + m.forEach(v=>{ + str=str+"\n"+v + }) + if((global as any).isDebug){ + throw Error(str) + }else{ + console.error(`error :${str}`) + exit(-1) + } +} + +export default printErrorOrDebug \ No newline at end of file diff --git a/src/Tools/TryGetCompilerVersion.ts b/src/Tools/TryGetCompilerVersion.ts index 93d3100..e5f91dc 100644 --- a/src/Tools/TryGetCompilerVersion.ts +++ b/src/Tools/TryGetCompilerVersion.ts @@ -1,7 +1,6 @@ import { exec, execSync } from "child_process" import printDebug from "./DebugPrint"; import util from "util"; -const execPromise =util.promisify(exec); const tryGetCompilerVersion =(path:string,command:string):string=>{ const exec_command = `${path} ${command}` diff --git a/src/index.ts b/src/index.ts index ee7541a..4281113 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,26 @@ -const argv = require('minimist')(process.argv.slice(2)); +import path from "path"; +import printDebug from "./Tools/DebugPrint"; +import { existsSync } from "fs"; +import printErrorOrDebug from "./Tools/PrintErrorOrDebug"; + +const argv = require('minimist')(process.argv.slice(2)) + +let nmakeFileName = "nmake.ts" +if(argv["v"])(global as any).isDebug=true +if (argv["f"]) {nmakeFileName = argv["f"];printDebug(`setting nmake file name to ${argv["f"]}`)} + +const nmakeFilePath = path.join(process.cwd(),nmakeFileName) +printDebug(`file path is ${nmakeFilePath}`) + + +printDebug("finding nmake file at "+nmakeFilePath) +if(!existsSync(nmakeFilePath))printErrorOrDebug(`cannot find file ${nmakeFilePath}`) +printDebug("found nmake file") + +printDebug("adding ts-node") +require("ts-node").register() + +printDebug(`running file ${nmakeFilePath}`) +require(nmakeFilePath) +printDebug(`run completion!`,nmakeFilePath) diff --git a/tests/test2/nmake.ts b/tests/test2/nmake.ts new file mode 100644 index 0000000..ad21821 --- /dev/null +++ b/tests/test2/nmake.ts @@ -0,0 +1 @@ +console.log("hello world") \ No newline at end of file