From 347a0758e0b825377d53e77ea7e9a49792b3fa9a Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sun, 11 Aug 2024 22:59:13 +0800 Subject: [PATCH] update --- package.json | 2 ++ src/CliFunc/project.ts | 6 ++++++ src/Tools/ConstructGlobal.ts | 6 +++--- src/Tools/GlobalStack.ts | 22 ++++++++++++++++++++++ tests/test1/index.ts | 9 --------- 5 files changed, 33 insertions(+), 12 deletions(-) create mode 100644 src/Tools/GlobalStack.ts diff --git a/package.json b/package.json index 927b4bb..03c71a9 100644 --- a/package.json +++ b/package.json @@ -19,11 +19,13 @@ "author": "Zengtudor", "license": "MIT", "devDependencies": { + "@types/lodash": "^4.17.7", "@types/minimist": "^1.2.5", "@types/node": "^22.2.0", "typescript": "^5.5.4" }, "dependencies": { + "lodash": "^4.17.21", "minimist": "^1.2.8", "ts-node": "^10.9.2" } diff --git a/src/CliFunc/project.ts b/src/CliFunc/project.ts index 3d0aef3..c28acb7 100644 --- a/src/CliFunc/project.ts +++ b/src/CliFunc/project.ts @@ -1,8 +1,14 @@ +import { cloneDeep } from "lodash" +import NmakeGlobal from "../interface/NmakeGlobal" import printDebug from "../Tools/DebugPrint" const project = (name:string,callback:Function) =>{ + const oldGlobal = (global as any).nmake as unknown as NmakeGlobal + const nGlobal = cloneDeep(((global as any).nmake as unknown as NmakeGlobal)); + (global as any).nmake = nGlobal printDebug("adding project :"+name) callback() + (global as any).nmake = oldGlobal } export default project \ No newline at end of file diff --git a/src/Tools/ConstructGlobal.ts b/src/Tools/ConstructGlobal.ts index 8190774..2d3cdc6 100644 --- a/src/Tools/ConstructGlobal.ts +++ b/src/Tools/ConstructGlobal.ts @@ -1,9 +1,9 @@ import NmakeGlobal from "../interface/NmakeGlobal" +import { getGlobalNmake, Global } from "./GlobalStack" const constructGlobal = ()=>{ - (global as any).projects = []; - const nmakeGlobal = global as unknown as NmakeGlobal - + Global.nmake = {} + Global.nmake.projects = {} as NmakeGlobal[] } export default constructGlobal \ No newline at end of file diff --git a/src/Tools/GlobalStack.ts b/src/Tools/GlobalStack.ts new file mode 100644 index 0000000..efdacee --- /dev/null +++ b/src/Tools/GlobalStack.ts @@ -0,0 +1,22 @@ +import { cloneDeep } from "lodash" +import NmakeGlobal from "../interface/NmakeGlobal" +import printDebug from "./DebugPrint" + +export const Global = global as any +let globalNmakeStacks = Global.globalStacks as NmakeGlobal[] + +export const pushGlobalStack = () =>{ + if(!Global.globalStacks){Global.globalStacks = [];globalNmakeStacks = Global.globalStacks as NmakeGlobal[]} + printDebug("pushing global stack") + globalNmakeStacks.push(Global.nmake) + Global.nmake = cloneDeep(Global.nmake) +} + +export const popGlobalStack = ()=>{ + Global.nmake = globalNmakeStacks[globalNmakeStacks.length-1] + globalNmakeStacks.pop() +} + +export const getGlobalNmake=():NmakeGlobal=>{ + return Global.nmake +} \ No newline at end of file diff --git a/tests/test1/index.ts b/tests/test1/index.ts index b8dad80..e69de29 100644 --- a/tests/test1/index.ts +++ b/tests/test1/index.ts @@ -1,9 +0,0 @@ -import { execSync } from "child_process"; -import GppCompiler from "../../src/Compiler/GppCompiler"; - - -(global as any).isDebug=true; -// const a = new GppCompiler() -// console.log(a.compilerVersion) -console.log(execSync("g++ -v").toLocaleString()) -// console.log(execSync("g++ --version").toString().trim())