From e43cd81e7ce1690c3a77c0349f599e7864c0739b Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Mon, 12 Aug 2024 12:22:49 +0800 Subject: [PATCH] update --- src/Project/CppProject.ts | 18 +++++++++++++++--- src/Project/interface/SourceFiles.ts | 5 ++++- src/Tools/AddProject.ts | 11 +++++++++++ src/Tools/GlobalNmake.ts | 8 ++++++++ src/Tools/NmakeDir.ts | 9 +++++++++ src/Tools/NmakePath.ts | 17 +++++++++++++++++ src/Tools/PrintErrorOrDebug.ts | 2 +- src/Tools/Projects.ts | 9 +++++++++ src/index.ts | 4 ++++ tests/test2/nmake.ts | 10 ++++++---- 10 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 src/Tools/AddProject.ts create mode 100644 src/Tools/GlobalNmake.ts create mode 100644 src/Tools/NmakeDir.ts create mode 100644 src/Tools/NmakePath.ts create mode 100644 src/Tools/Projects.ts diff --git a/src/Project/CppProject.ts b/src/Project/CppProject.ts index cffc044..2d4e7eb 100644 --- a/src/Project/CppProject.ts +++ b/src/Project/CppProject.ts @@ -1,18 +1,30 @@ +import path from "path"; import GppCompiler from "../Compiler/GppCompiler"; import printDebug from "../Tools/DebugPrint"; -import { getDefaultCompiler, setDefaultCompiler } from "../Tools/DefaultCompiler"; -import setGetDefaultCompiler from "../Tools/setGetDefaultCompiler"; +import setGetDefaultCompiler from "../Tools/SetGetDefaultCompiler"; import HaveCompiler from "./interface/HaveCompiler"; import Optimize from "./interface/Optimize"; import SourceFiles from "./interface/SourceFiles"; import Project from "./Project"; +import { getNmakePath } from "../Tools/NmakePath"; +import { getNmakeDir } from "../Tools/NmakeDir"; export default class CppProject implements Project , SourceFiles,HaveCompiler,Optimize { name: string; compiler: GppCompiler; - sourceFiles: string[]=[]; + sourceFilesPath: string[]=[]; optimize: "fast" | "fastest" | "normal" = "fast" typeName: string = "cpp"; + addFiles = (...files: string[]):CppProject =>{ + printDebug("adding source files "+files) + files.forEach(v=>{ + this.sourceFilesPath.push( + path.join(getNmakeDir(),v) + ) + }); + printDebug("all files in "+this.name+" :"+this.sourceFilesPath) + return this + }; constructor(name:string) constructor(name:string,compiler:GppCompiler) diff --git a/src/Project/interface/SourceFiles.ts b/src/Project/interface/SourceFiles.ts index 74684ae..cb2b322 100644 --- a/src/Project/interface/SourceFiles.ts +++ b/src/Project/interface/SourceFiles.ts @@ -1,3 +1,6 @@ +import Project from "../Project" + export default interface SourceFiles{ - sourceFiles:string[] + sourceFilesPath:string[] + addFiles:{(...files:string[]):Project} } \ No newline at end of file diff --git a/src/Tools/AddProject.ts b/src/Tools/AddProject.ts new file mode 100644 index 0000000..262515a --- /dev/null +++ b/src/Tools/AddProject.ts @@ -0,0 +1,11 @@ +import Project from "../Project/Project"; +import printErrorOrDebug from "./PrintErrorOrDebug"; +import { getGlobalProjects } from "./Projects"; + +export const addProject = (f:{():Project}) =>{ + const project = f() + if(getGlobalProjects()[project.name]){ + printErrorOrDebug(`the project ${project.name} was used please rename it`) + } + getGlobalProjects()[project.name] = project +} \ No newline at end of file diff --git a/src/Tools/GlobalNmake.ts b/src/Tools/GlobalNmake.ts new file mode 100644 index 0000000..5ef4835 --- /dev/null +++ b/src/Tools/GlobalNmake.ts @@ -0,0 +1,8 @@ +const Global = (global as any) + +export const getGlobalNmake = ():any=>{ + if(Global.nmake==undefined){ + Global.nmake={} + } + return Global.nmake +} \ No newline at end of file diff --git a/src/Tools/NmakeDir.ts b/src/Tools/NmakeDir.ts new file mode 100644 index 0000000..eb06402 --- /dev/null +++ b/src/Tools/NmakeDir.ts @@ -0,0 +1,9 @@ +import path from "path" +import { getNmakePath } from "./NmakePath" +import printDebug from "./DebugPrint" + +export const getNmakeDir =():string=>{ + let nmakeDir = path.join(getNmakePath(),"../") + printDebug("getting nmake dir "+nmakeDir) + return nmakeDir +} \ No newline at end of file diff --git a/src/Tools/NmakePath.ts b/src/Tools/NmakePath.ts new file mode 100644 index 0000000..9a3b61f --- /dev/null +++ b/src/Tools/NmakePath.ts @@ -0,0 +1,17 @@ +import printDebug from "./DebugPrint"; +import { getGlobalNmake } from "./GlobalNmake" +import printErrorOrDebug from "./PrintErrorOrDebug"; + + +export const setNmakePath = (path:string)=>{ + printDebug("setting nmake path "+path) + getGlobalNmake().nmakePath = path; +} + +export const getNmakePath = ():string=>{ + printDebug("getting nmake path") + if(getGlobalNmake().nmakePath==undefined){ + printErrorOrDebug("cannot get nmake path") + } + return getGlobalNmake().nmakePath +} \ No newline at end of file diff --git a/src/Tools/PrintErrorOrDebug.ts b/src/Tools/PrintErrorOrDebug.ts index 620195e..ff9a5ca 100644 --- a/src/Tools/PrintErrorOrDebug.ts +++ b/src/Tools/PrintErrorOrDebug.ts @@ -8,7 +8,7 @@ const printErrorOrDebug = (...m:string[])=>{ if((global as any).isDebug){ throw Error(str) }else{ - console.error(`error :${str}`) + console.error(`[Error] :${str}`) exit(-1) } } diff --git a/src/Tools/Projects.ts b/src/Tools/Projects.ts new file mode 100644 index 0000000..e613ef5 --- /dev/null +++ b/src/Tools/Projects.ts @@ -0,0 +1,9 @@ +import Project from "../Project/Project" +import { getGlobalNmake } from "./GlobalNmake" + +export const getGlobalProjects = ():{[key:string]:Project}=>{ + if(getGlobalNmake().projects==undefined){ + getGlobalNmake().projects = [] + } + return getGlobalNmake().projects as {[key:string]:Project} +} diff --git a/src/index.ts b/src/index.ts index cd6bd99..7dc626b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import path from "path"; import printDebug from "./Tools/DebugPrint"; import { existsSync } from "fs"; import printErrorOrDebug from "./Tools/PrintErrorOrDebug"; +import { setNmakePath } from "./Tools/NmakePath"; const argv = require('minimist')(process.argv.slice(2)) @@ -17,11 +18,14 @@ printDebug("finding nmake file at "+nmakeFilePath) if(!existsSync(nmakeFilePath))printErrorOrDebug(`cannot find file ${nmakeFilePath}`) printDebug("found nmake file") +setNmakePath(nmakeFilePath) + printDebug("adding ts-node") require("ts-node").register() printDebug("adding global values") +console.log("running nmake file "+nmakeFilePath) printDebug(`running file ${nmakeFilePath}`) require(nmakeFilePath) printDebug(`run completion!`,nmakeFilePath) diff --git a/tests/test2/nmake.ts b/tests/test2/nmake.ts index c4e216d..4e8c235 100644 --- a/tests/test2/nmake.ts +++ b/tests/test2/nmake.ts @@ -1,10 +1,12 @@ -import GppCompiler from "../../src/Compiler/GppCompiler"; import CppProject from "../../src/Project/CppProject"; +import { addProject } from "../../src/Tools/AddProject"; // const compiler = new GppCompiler() -new CppProject("hello"); +addProject(()=>{ + return new CppProject("hello") +}) -new CppProject("hello"); +new CppProject("hello") -new CppProject("hello"); +new CppProject("hello")