This commit is contained in:
Zengtudor 2024-08-11 16:59:49 +08:00
parent 6245631894
commit bdbfec40f9
12 changed files with 70 additions and 9 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"cSpell.words": [
"Zengtudor"
]
}

View File

@ -24,6 +24,7 @@
"typescript": "^5.5.4"
},
"dependencies": {
"minimist": "^1.2.8"
"minimist": "^1.2.8",
"ts-node": "^10.9.2"
}
}

View File

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

View File

@ -2,5 +2,4 @@ import Compiler from "../Compiler/Compiler"
export default interface Project{
name:string
compiler:Compiler
}

View File

@ -0,0 +1,5 @@
import Compiler from "../../Compiler/Compiler";
export default interface HaveCompiler{
compiler:Compiler
}

View File

@ -0,0 +1,3 @@
export default interface Optimize{
optimize:"fast"|"fastest"|"normal"
}

View File

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

View File

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

View File

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

View File

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

View File

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

1
tests/test2/nmake.ts Normal file
View File

@ -0,0 +1 @@
console.log("hello world")