Skip to content

Commit

Permalink
port from the exma project. this is effectively a rebrand.
Browse files Browse the repository at this point in the history
  • Loading branch information
cblanquera committed Apr 13, 2024
1 parent 581afb2 commit efe4659
Show file tree
Hide file tree
Showing 102 changed files with 19,168 additions and 30 deletions.
70 changes: 42 additions & 28 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down Expand Up @@ -42,8 +41,8 @@ build/Release
node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo
Expand All @@ -54,9 +53,6 @@ web_modules/
# Optional eslint cache
.eslintcache

# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
Expand All @@ -72,41 +68,30 @@ web_modules/
# Yarn Integrity file
.yarn-integrity

# dotenv environment variable files
# dotenv environment variables file
.env
.env.development.local
.env.test.local
.env.production.local
.env.test
.env.local

# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache

# Next.js build output
.next
out

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# vuepress v2.x temp and cache directory
.temp
.cache

# Docusaurus cache and generated files
.docusaurus

# Serverless directories
.serverless/

Expand All @@ -119,12 +104,41 @@ dist
# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# production
build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env*.local

# vercel
.vercel
.swc

# typescript
*.tsbuildinfo
next-env.d.ts

cache/
archives/
coverages/

*.dbg.json
Session.vim
*keypair.json

#cockroachdb
cockroach-data

# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
#custom
archives
example/src/enums.ts
4 changes: 2 additions & 2 deletions docs/transform.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export default function generate({ config, schema, cli }: PluginProps) {
const lang = config.lang || 'ts';
// 2. Project
//find the absolute path from the output config
const destination = Loader.absolute(config.output);
const destination = Loader.absolute(config.output as string);
//output directory from the destination
const dirname = path.dirname(destination);
//file name from the destination
Expand Down Expand Up @@ -313,7 +313,7 @@ export default function generate({ config, schema, cli }: PluginProps) {
//get enum
const enums = schema.enum as Record<string, EnumConfig>;
//get all the possible enum members ("ADMIN", "MANAGER", "USER")
const members = Object.keys(enum[name]);
const members = Object.keys(enums[name]);
//add enum using ts-morph
source.addEnum({
name: name,
Expand Down
54 changes: 54 additions & 0 deletions example/my.idea
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
}
16 changes: 16 additions & 0 deletions example/package.json
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"
}
}
86 changes: 86 additions & 0 deletions example/src/make-enums.ts
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();
}
};
19 changes: 19 additions & 0 deletions example/tsconfig.json
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"]
}
20 changes: 20 additions & 0 deletions package.json
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"
}
}
5 changes: 5 additions & 0 deletions packages/idea-language/.eslintignore
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/**
22 changes: 22 additions & 0 deletions packages/idea-language/.eslintrc.js
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,
}
};
5 changes: 5 additions & 0 deletions packages/idea-language/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
out
node_modules
client/server
.vscode-test
archives
9 changes: 9 additions & 0 deletions packages/idea-language/.vscode/extensions.json
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"
]
}
Loading

0 comments on commit efe4659

Please sign in to comment.