Skip to content

Commit

Permalink
Test build
Browse files Browse the repository at this point in the history
  • Loading branch information
balbatross committed Feb 18, 2024
1 parent 346f65c commit 3136f2e
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 61 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions packages/app/hivecommand-backend/__tests__/module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
var n = undefinedN;
64 changes: 64 additions & 0 deletions packages/app/hivecommand-backend/__tests__/transpile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { ModuleKind, ScriptTarget, transpile } from 'typescript'
import * as ts from 'typescript'

// const configFileName = __dirname + '/__tests__/tsconfig.json';

// if(!configFileName) throw new Error("No tsconfig found");

// const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
// const compilerOptions = ts.parseJsonConfigFileContent(
// configFile.config,
// ts.sys,
// "./"
// );

// const inputFileName = "module.ts";

// const sourceFile = ts.createSourceFile(
// inputFileName,
// `var oldName = undefinedN;`,
// {
// languageVersion: compilerOptions.options.target || ScriptTarget.ES2017
// }
// )


// const program = ts.createProgram({
// options: compilerOptions.options,
// rootNames: [inputFileName],
// projectReferences: compilerOptions.projectReferences,
// configFileParsingDiagnostics: compilerOptions.errors
// })

// // console.log(program.getSourceFiles().length)

// console.log(program.getSyntacticDiagnostics(sourceFile))
// console.log(program.getSemanticDiagnostics())


const text = ts.transpileModule(`
var oldName = undefinedN;
facke();
`, {

compilerOptions: {
target: ScriptTarget.ES2017,
module: ModuleKind.ESNext,
noImplicitAny: true,
strict: true,
strictNullChecks: true,
strictFunctionTypes: true,
strictBindCallApply: true,
strictPropertyInitialization: true,
noImplicitThis: true,
alwaysStrict: true,
noImplicitReturns: true,
declaration: true,
allowSyntheticDefaultImports: true
},
reportDiagnostics: true

});


console.log({text})
10 changes: 10 additions & 0 deletions packages/app/hivecommand-backend/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"target": "ES2017",
"module": "CommonJS",
"skipLibCheck": true
},
// "include": ["./__tests__/module.ts"],
// "exclude": ["node_modules/", "src/"],
// "files": ["./module.ts"]
}
4 changes: 3 additions & 1 deletion packages/app/hivecommand-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"build": "tsc -b",
"db:update": "prisma migrate dev --name init",
"db:generate": "prisma generate",
"db:seed": "prisma db seed"
"db:seed": "prisma db seed",
"test": "ts-node __tests__/transpile.ts"
},
"installConfig": {
"hoistingLimits": "dependencies"
Expand Down Expand Up @@ -56,6 +57,7 @@
"nanoid": "^3.1.30",
"pg": "^8.7.1",
"redis": "4.6.8",
"ts-morph": "^21.0.1",
"typed-graphql-subscriptions": "^0.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,45 @@ import { PrismaClient, ProgramTag, ProgramTagType } from "@hive-command/data";
import { nanoid } from "nanoid";
import { isStringType } from "../types/util";
import { LexoRank } from "lexorank";
import { JsxEmit, ModuleKind, ScriptTarget, transpile } from 'typescript';
import { Project } from 'ts-morph'

const canCompile = (tsCode: string) => {

// try{
// const proj = new Project({
// compilerOptions: {skipLibCheck: true}
// });

// const id = nanoid();
// console.time(`Create source file ${id}`)

// const sourceFile = proj.createSourceFile('module.ts', tsCode);
// console.timeEnd(`Create source file ${id}`)

// console.time(`Get source file diags ${id}`)

// // proj.getSema

// console.log(proj.getSourceFiles().length)

// const diagnostics = proj.getProgram().getSemanticDiagnostics(sourceFile)

// // getSemanticDiagnostics

// // const diagnostics = sourceFile.getPreEmitDiagnostics()
// console.timeEnd(`Get source file diags ${id}`)

// // const diagnostics = proj.()

// return diagnostics?.length <= 0;
// }catch(e){
// return false;
// }

return true;

}

export default (prisma: PrismaClient) => {

Expand Down Expand Up @@ -30,6 +69,8 @@ export default (prisma: PrismaClient) => {
title: String
script: String
compileError: Boolean
rank: String
createdAt: DateTime
Expand All @@ -49,13 +90,40 @@ export default (prisma: PrismaClient) => {
scope: String
script: String
compileError: Boolean
}
`

const resolvers = {

CommandProgramAlarmPathway: {
compileError: (root: any) => {
console.log(root.script, canCompile(root.script))
const id = nanoid();
console.time(`Compile error - ${id}`)
if(root.script){
const notCompiled = !canCompile(root.script)
console.timeEnd(`Compile error - ${id}`)

return notCompiled
}
return false;
}
},
CommandProgramAlarm: {
compileError: (root: any) => {
const id = nanoid();
console.time(`Compile error - ${id}`)
if(root.script){
const notCompiled = !canCompile(root.script)
console.timeEnd(`Compile error - ${id}`)
return notCompiled;
}
return false;
}
},
Mutation: {
createCommandProgramAlarm: async (root: any, args: { program: string, input: any }, context: any) => {

Expand Down Expand Up @@ -97,13 +165,22 @@ export default (prisma: PrismaClient) => {

if (!program) throw new Error("Program access not allowed");

let compiled;

try{
compiled = transpile(args.input.script, {module: ModuleKind.CommonJS, target: ScriptTarget.ES5})
}catch(err){

}

return await prisma.programAlarm.update({
where: {
id: args.id
},
data: {
title: args.input.title,
script: args.input.script
script: args.input.script,
compiledScript: compiled
}
})
},
Expand Down Expand Up @@ -135,13 +212,22 @@ export default (prisma: PrismaClient) => {
})
},
updateCommandProgramAlarmPathway: async (root: any, args: { program: string, id: string, input: any }, context: any) => {
let compiled;

try{
compiled = transpile(args.input.script, {module: ModuleKind.CommonJS, target: ScriptTarget.ES5})
}catch(err){

}

return await prisma.programAlarmPathway.update({
where: {
id: args.id
},
data: {
name: args.input.name,
script: args.input.script,
compiledScript: compiled,
scope: args.input.scope
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "ProgramAlarm" ADD COLUMN "compiledScript" TEXT;

-- AlterTable
ALTER TABLE "ProgramAlarmPathway" ADD COLUMN "compiledScript" TEXT;
2 changes: 2 additions & 0 deletions packages/app/hivecommand-db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ model ProgramAlarm {
title String?
script String?
compiledScript String?
rank String?
Expand All @@ -356,6 +357,7 @@ model ProgramAlarmPathway {
name String
scope String @default("REMOTE")
script String?
compiledScript String?
program Program @relation(name: "hasAlarmPathway", references: [id], fields: [programId])
programId String
Expand Down
9 changes: 8 additions & 1 deletion packages/app/hivecommand-frontend/src/views/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import qs from 'qs';
import { matchPath, Outlet, useLocation, useMatch, useNavigate, useParams, useResolvedPath } from 'react-router-dom';
//const Editor = lazy(() => import('@hive-flow/editor'));
import { Home } from './pages/home'
import { KeyboardArrowLeft as ArrowLeft, Menu } from '@mui/icons-material'
import { KeyboardArrowLeft as ArrowLeft, Menu, Error } from '@mui/icons-material'

import { Routes, Route } from 'react-router-dom';
import {Controls} from './pages/controls'
Expand Down Expand Up @@ -107,12 +107,17 @@ export const EditorPage: React.FC<EditorProps> = (props) => {
name
script
scope
compileError
}
alarms {
id
title
script
compileError
rank
}
Expand Down Expand Up @@ -430,6 +435,7 @@ export const EditorPage: React.FC<EditorProps> = (props) => {
name: 'Alarm Pathways',
children: program?.alarmPathways?.map((pathway) => ({
id: pathway.id,
icon: pathway.compileError ? <Error fontSize="small" sx={{color: 'red'}} /> : null,
name: pathway.name
})),
editor: <AlarmPathwayEditor />
Expand All @@ -440,6 +446,7 @@ export const EditorPage: React.FC<EditorProps> = (props) => {
name: 'Alarms',
children: program?.alarms?.map((alarm) => ({
id: alarm.id,
icon: alarm.compileError ? <Error fontSize="small" sx={{color: 'red'}} /> : null,
name: alarm.title
})),
// children: [
Expand Down
Loading

0 comments on commit 3136f2e

Please sign in to comment.