This commit is contained in:
Zengtudor 2024-08-12 12:22:49 +08:00
parent db5a419af8
commit e43cd81e7c
10 changed files with 84 additions and 9 deletions

View File

@ -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)

View File

@ -1,3 +1,6 @@
import Project from "../Project"
export default interface SourceFiles{
sourceFiles:string[]
sourceFilesPath:string[]
addFiles:{(...files:string[]):Project}
}

11
src/Tools/AddProject.ts Normal file
View File

@ -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
}

8
src/Tools/GlobalNmake.ts Normal file
View File

@ -0,0 +1,8 @@
const Global = (global as any)
export const getGlobalNmake = ():any=>{
if(Global.nmake==undefined){
Global.nmake={}
}
return Global.nmake
}

9
src/Tools/NmakeDir.ts Normal file
View File

@ -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
}

17
src/Tools/NmakePath.ts Normal file
View File

@ -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
}

View File

@ -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)
}
}

9
src/Tools/Projects.ts Normal file
View File

@ -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}
}

View File

@ -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)

View File

@ -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")