diff --git a/src/CliFunc/project.ts b/src/CliFunc/project.ts index c28acb7..da607fd 100644 --- a/src/CliFunc/project.ts +++ b/src/CliFunc/project.ts @@ -1,14 +1,13 @@ import { cloneDeep } from "lodash" import NmakeGlobal from "../interface/NmakeGlobal" import printDebug from "../Tools/DebugPrint" +import { popGlobalStack, pushGlobalStack } from "../Tools/GlobalStack" 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 + pushGlobalStack() printDebug("adding project :"+name) callback() - (global as any).nmake = oldGlobal + popGlobalStack() } export default project \ No newline at end of file diff --git a/src/Tools/GlobalStack.ts b/src/Tools/GlobalStack.ts index efdacee..3c7737d 100644 --- a/src/Tools/GlobalStack.ts +++ b/src/Tools/GlobalStack.ts @@ -6,17 +6,19 @@ 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") + if(!Global.globalStacks){Global.globalStacks = [];globalNmakeStacks = Global.globalStacks as NmakeGlobal[]} globalNmakeStacks.push(Global.nmake) Global.nmake = cloneDeep(Global.nmake) } export const popGlobalStack = ()=>{ + printDebug("popping global stack") Global.nmake = globalNmakeStacks[globalNmakeStacks.length-1] globalNmakeStacks.pop() } export const getGlobalNmake=():NmakeGlobal=>{ + printDebug("getting global nmake") return Global.nmake } \ No newline at end of file diff --git a/tests/test2/nmake.ts b/tests/test2/nmake.ts index b607159..749c880 100644 --- a/tests/test2/nmake.ts +++ b/tests/test2/nmake.ts @@ -1,5 +1,3 @@ -import {project} from "../../src/CliFunc/tools"; +import CppProject from "../../src/Project/CppProject"; -project("hello",()=>{ - -}) \ No newline at end of file +new CppProject("hello");