-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
port from the exma project. this is effectively a rebrand.
- Loading branch information
1 parent
581afb2
commit efe4659
Showing
102 changed files
with
19,168 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
plugin "./dist/make-enums" { | ||
ts true | ||
output "./src/enums.ts" | ||
} | ||
|
||
enum Roles { | ||
ADMIN "ADMIN" | ||
MANAGER "MANAGER" | ||
USER "USER" | ||
} | ||
|
||
prop RoleProps { | ||
options [ | ||
{ label "Admin" value "ADMIN" } | ||
{ label "Manager" value "MANAGER" } | ||
{ label "User" value "USER" } | ||
] | ||
} | ||
|
||
type Address @label("Address" "Addresses") { | ||
street String @field.text @list.hide | ||
city String? @field.text | ||
country String @field.country @list.uppercase @view.uppercase | ||
postal String @field.text | ||
} | ||
|
||
model User @label("User" "Users") { | ||
id String @label("ID") @db.char(21) @id @default("cuid()") | ||
username String @label("Username") @db.varchar(255) @unique @searchable @field.text | ||
companyId String? @label("Company") @db.char(21) @relation("Company" "id" "name") @field.modelcomplete("Company" "id" "name") | ||
name String @label("Name") @db.varchar(255) @searchable @field.text | ||
role Roles @label("Role") @db.varchar(255) @default("USER") @filterable @field.select(RoleProps) @list.lowercase @view.lowercase | ||
active Boolean @label("Active") @default(true) @filterable @field.switch @list.yesno @view.yesno | ||
lastLogin Datetime @label("Last Login") @default("now()") @list.date | ||
created Datetime @label("Created") @default("now()") @filterable @sortable @list.date | ||
updated Datetime @label("Updated") @default("now()") @updated @filterable @sortable @list.date | ||
} | ||
|
||
model Company @label("Company" "Companies") { | ||
id String @label("ID") @db.char(21) @id @default("cuid()") | ||
name String @label("Name") @db.varchar(255) @unique @searchable @field.text | ||
country String @label("Country") @db.char(2) @filterable @field.country | ||
address Address @label("Address") @field.fieldset("Address" false) @list.hide @view.table | ||
contact String? @label("Contact") @db.varchar(255) @field.text | ||
email String? @label("Email") @db.varchar(255) @field.email @list.email @view.email | ||
phone String? @label("Phone") @db.varchar(255) @field.phone @list.phone @view.phone | ||
files String[] @label("Files") @field.filelist @list.hide @view.line | ||
references Hash? @label("References") @field.metadata @list.hide @view.metadata | ||
supplier Boolean @label("Supplier") @default(false) @field.switch @list.yesno @view.yesno | ||
approved Boolean @label("Approved") @default(false) @field.switch @list.yesno @view.yesno | ||
active Boolean @label("Active") @default(true) @filterable @field.switch @list.yesno @view.yesno | ||
created Datetime @label("Created") @default("now()") @filterable @sortable @list.date | ||
updated Datetime @label("Updated") @default("now()") @updated @filterable @sortable @list.date | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "idea-with-node", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"transform": "idea", | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "20.2.5", | ||
"@ossph/idea": "0.1.0", | ||
"ts-morph": "22.0.0", | ||
"ts-node": "10.9.1", | ||
"typescript": "5.0.4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import type { PluginProps, EnumConfig } from '@ossph/idea'; | ||
|
||
import path from 'path'; | ||
import { Project, IndentationText } from 'ts-morph'; | ||
import { Loader } from '@ossph/idea'; | ||
|
||
export default function generate({ config, schema, cli }: PluginProps) { | ||
// 1. Config | ||
//we need to know where to put this code... | ||
if (!config.output) { | ||
return cli.terminal.error('No output directory specified'); | ||
} | ||
//code in typescript or javascript? | ||
const lang = config.lang || 'ts'; | ||
// 2. Project | ||
//find the absolute path from the output config | ||
const destination = Loader.absolute(config.output as string); | ||
//output directory from the destination | ||
const dirname = path.dirname(destination); | ||
//file name from the destination | ||
const filename = path.basename(destination); | ||
//start a ts-morph project | ||
const project = new Project({ | ||
tsConfigFilePath: path.resolve(__dirname, '../tsconfig.json'), | ||
skipAddingFilesFromTsConfig: true, | ||
compilerOptions: { | ||
outDir: dirname, | ||
// Generates corresponding '.d.ts' file. | ||
declaration: true, | ||
// Generates a sourcemap for each corresponding '.d.ts' file. | ||
declarationMap: true, | ||
// Generates corresponding '.map' file. | ||
sourceMap: true, | ||
}, | ||
manipulationSettings: { | ||
indentationText: IndentationText.TwoSpaces | ||
} | ||
}); | ||
//create the directory if it does not exist | ||
const directory = project.createDirectory(dirname); | ||
//create a source file to manually populate later... | ||
const source = directory.createSourceFile(filename, '', { overwrite: true }); | ||
// 3. Enum | ||
//if there are enums... | ||
if (typeof schema.enum === 'object') { | ||
// Enums in schema object will look like this... | ||
// { | ||
// "plugin": { ... }, | ||
// "enum": { | ||
// "Roles": { | ||
// "ADMIN": "Admin", | ||
// "MANAGER": "Manager", | ||
// "USER": "User" | ||
// } | ||
// }, | ||
// "type": { ... }, | ||
// "model": { ... } | ||
// } | ||
//loop through enums | ||
for (const name in schema.enum) { | ||
//get enum | ||
const enums = schema.enum as Record<string, EnumConfig>; | ||
//get all the possible enum members ("ADMIN", "MANAGER", "USER") | ||
const members = Object.keys(enums[name]); | ||
//add enum using ts-morph | ||
source.addEnum({ | ||
name: name, | ||
isExported: true, | ||
// { name: "ADMIN", value: "Admin" } | ||
members: members.map(key => ({ | ||
name: key, | ||
value: enums[name][key] as string | ||
})) | ||
}); | ||
} | ||
} | ||
// 4. Save | ||
source.formatText(); | ||
//if you want ts, tsx files | ||
if (lang == 'ts') { | ||
project.saveSync(); | ||
//if you want js, d.ts files | ||
} else { | ||
project.emit(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"declaration": true, | ||
"esModuleInterop": true, | ||
"lib": [ "es2021", "es7", "es6", "dom" ], | ||
"module": "commonjs", | ||
"noUnusedLocals": true, | ||
"outDir": "./dist/", | ||
"preserveConstEnums": true, | ||
"resolveJsonModule": true, | ||
"removeComments": true, | ||
"sourceMap": false, | ||
"strict": true, | ||
"target": "es6", | ||
"skipLibCheck": true | ||
}, | ||
"include": [ "src/**/*.ts" ], | ||
"exclude": [ "dist", "docs", "node_modules", "test"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"private": true, | ||
"workspaces": [ | ||
"packages/*", | ||
"example" | ||
], | ||
"scripts": { | ||
"build": "yarn build:parser && yarn build:transformer && yarn build:idea && yarn build:example", | ||
"build:parser": "yarn --cwd packages/idea-parser build", | ||
"build:language": "yarn --cwd packages/idea-language build", | ||
"build:transformer": "yarn --cwd packages/idea-transformer build", | ||
"build:idea": "yarn --cwd packages/idea build", | ||
"build:example": "yarn --cwd example build", | ||
"transform": "yarn --cwd example transform -i ./my.idea", | ||
"test": "yarn --cwd packages/idea-parser test" | ||
}, | ||
"devDependencies": { | ||
"concurrently": "7.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
node_modules/** | ||
client/node_modules/** | ||
client/out/** | ||
server/node_modules/** | ||
server/out/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/**@type {import('eslint').Linter.Config} */ | ||
// eslint-disable-next-line no-undef | ||
module.exports = { | ||
root: true, | ||
parser: '@typescript-eslint/parser', | ||
plugins: [ | ||
'@typescript-eslint', | ||
], | ||
extends: [ | ||
'eslint:recommended', | ||
'plugin:@typescript-eslint/recommended', | ||
], | ||
rules: { | ||
'semi': [2, "always"], | ||
'no-useless-escape': 0, | ||
'@typescript-eslint/no-extra-semi': 0, | ||
'@typescript-eslint/no-unused-vars': 0, | ||
'@typescript-eslint/no-explicit-any': 0, | ||
'@typescript-eslint/explicit-module-boundary-types': 0, | ||
'@typescript-eslint/no-non-null-assertion': 0, | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
out | ||
node_modules | ||
client/server | ||
.vscode-test | ||
archives |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. | ||
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp | ||
|
||
// List of extensions which should be recommended for users of this workspace. | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint" | ||
] | ||
} |
Oops, something went wrong.