@elysiumjs/styx 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/README.md +13 -1
- package/dist/commands/index.d.ts +0 -2
- package/dist/config.d.ts +9 -0
- package/dist/index.d.ts +1 -7
- package/dist/index.js +79 -85
- package/dist/styx.js +9 -1
- package/dist/styx.module.d.ts +7 -0
- package/dist/utils.d.ts +17 -0
- package/package.json +7 -6
- package/stubs/job.stub +1 -1
- package/stubs/model.stub +5 -3
- package/stubs/repository.stub +3 -2
- package/stubs/service.stub +2 -1
- package/dist/commands/migration_generate.command.d.ts +0 -11
- package/dist/commands/migration_run.command.d.ts +0 -13
package/dist/styx.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{
|
|
3
|
+
import{ElysiumError as ElysiumError2}from"@elysiumjs/core";import{existsSync}from"fs";import{mkdir,readdir,rename}from"fs/promises";import{dirname,extname,join}from"path";import{Application,ElysiumError}from"@elysiumjs/core";var capitalize=(str)=>{if(!str||str.length===0)return"";let lower=str.toLowerCase();return lower.substring(0,1).toUpperCase()+lower.substring(1,lower.length)};var snake=(str,options)=>{let parts=str?.replace(/([A-Z])+/g,capitalize).split(/(?=[A-Z])|[\.\-\s_]/).map((x)=>x.toLowerCase())??[];if(parts.length===0)return"";if(parts.length===1)return parts[0];let result=parts.reduce((acc,part)=>`${acc}_${part.toLowerCase()}`);return options?.splitOnNumber===!1?result:result.replace(/([A-Za-z]{1}[0-9]{1})/,(val)=>`${val[0]}_${val[1]}`)};var pascal=(str)=>{let parts=str?.split(/[\.\-\s_]/).map((x)=>x.toLowerCase())??[];if(parts.length===0)return"";return parts.map((str2)=>str2.charAt(0).toUpperCase()+str2.slice(1)).join("")};var trim=(str,charsToTrim=" ")=>{if(!str)return"";let toTrim=charsToTrim.replace(/[\W]{1}/g,"\\$&"),regex=new RegExp(`^[${toTrim}]+|[${toTrim}]+$`,"g");return str.replace(regex,"")};class AppEntryNotFoundError extends ElysiumError{path;constructor(path){super(`Could not find an exported Application class in ${path}`);this.path=path}}var resolveAppEntry=async(projectPath)=>{let appFile=join(projectPath,"src","app.ts"),entry=existsSync(appFile)?appFile:join(projectPath,"index.ts"),exports=await import(entry);for(let value of Object.values(exports))if(typeof value==="function"&&value.prototype instanceof Application)return value;throw new AppEntryNotFoundError(entry)},getRootPath=()=>dirname(Bun.fileURLToPath(import.meta.url)),getProjectPath=()=>{let startPath=process.cwd(),dir=startPath;while(!0){if(existsSync(join(dir,".elysiumrc")))return dir;let parentDir=dirname(dir);if(dir===parentDir)break;dir=parentDir}return startPath},createModule=async(name,oldName)=>{let root=getProjectPath();{let moduleDir=join(root,"src","modules",name);if(await mkdir(moduleDir,{recursive:!0}),!oldName){let moduleFile=join(moduleDir,`${name}.module.ts`);if(!existsSync(moduleFile)){let className=`${pascal(name)}Module`;await Bun.write(moduleFile,`import { Module } from '@elysiumjs/core';
|
|
4
|
+
|
|
5
|
+
@Module.register({
|
|
6
|
+
services: [],
|
|
7
|
+
controllers: [],
|
|
8
|
+
commands: []
|
|
9
|
+
})
|
|
10
|
+
export class ${className} extends Module {}
|
|
11
|
+
`)}}if(oldName)if(oldName==="root"){let entries=await readdir(join(root,"src"));for(let entry of entries){if(["app.ts","env.ts","database","modules"].includes(entry))continue;let oldPath=join(root,"src",entry),newPath=join(moduleDir,entry==="main.module.ts"?`${name}.module.ts`:entry);await rename(oldPath,newPath)}}else{let oldModuleDir=join(root,"src","modules",oldName);await rename(oldModuleDir,moduleDir)}}{let pkg=await Bun.file(join(root,"package.json")).json();if(pkg.imports=pkg.imports??{},pkg.imports[`#${name}/*`]=`./src/modules/${name}/*.ts`,oldName&&oldName!=="root")delete pkg.imports[`#${oldName}/*`];await Bun.write(join(root,"package.json"),JSON.stringify(pkg,null,2))}{let rc=await Bun.file(join(root,".elysiumrc")).json();if(rc.mono=!1,rc.modules=rc.modules??{},rc.modules[name]=`./src/modules/${name}`,oldName)delete rc.modules[oldName];await Bun.write(join(root,".elysiumrc"),JSON.stringify(rc,null,2))}if(oldName){let rewriteImports=async(dir)=>{let entries=await readdir(dir,{withFileTypes:!0});for(let entry of entries){let fullPath=join(dir,entry.name);if(entry.isDirectory())await rewriteImports(fullPath);else if(extname(entry.name)===".ts"){let text=await Bun.file(fullPath).text();if(oldName==="root")text=text.replace(new RegExp(`(['"])#${oldName}/((?!(env|app|database(?:/|$))).*?)(['"])`,"g"),`$1#${name}/$2$4`);else text=text.replace(new RegExp(`(['"])#${oldName}/`,"g"),`$1#${name}/`);text=text.replace(new RegExp(`(['"])#${oldName}/main\\.module(['"])/g`,"g"),`$1#${name}/${name}.module$2`),text=text.replace(new RegExp(`(['"])#${oldName}/main\\.module\\.ts(['"])?/g`,"g"),`$1#${name}/${name}.module$2`),await Bun.write(fullPath,text)}}};await rewriteImports(root)}};try{await(await resolveAppEntry(getProjectPath())).start()}catch(error){if(error instanceof ElysiumError2)console.error(error.message),process.exit(1);throw error}
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import { Application, ElysiumError } from '@elysiumjs/core';
|
|
2
|
+
/**
|
|
3
|
+
* Thrown when the project entry point exports no `Application` subclass.
|
|
4
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
5
|
+
*/
|
|
6
|
+
export declare class AppEntryNotFoundError extends ElysiumError {
|
|
7
|
+
readonly path: string;
|
|
8
|
+
constructor(path: string);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Loads the project entry (`src/app.ts`, else `index.ts`) and returns its exported `Application` subclass.
|
|
12
|
+
* @author Axel Nana <axel.nana@workbud.com>
|
|
13
|
+
*
|
|
14
|
+
* @param projectPath The root path of the project.
|
|
15
|
+
* @throws {AppEntryNotFoundError} When the entry exports no `Application` subclass.
|
|
16
|
+
*/
|
|
17
|
+
export declare const resolveAppEntry: (projectPath: string) => Promise<typeof Application>;
|
|
1
18
|
/**
|
|
2
19
|
* Gets the root path of the styx package.
|
|
3
20
|
* @author Axel Nana <axel.nana@workbud.com>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elysiumjs/styx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "The CLI tool for the Elysium.js framework.",
|
|
6
6
|
"private": false,
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"format": "prettier --write \"./src/**/*.ts\"",
|
|
15
15
|
"clean": "rimraf dist",
|
|
16
|
-
"build:js": "bun build ./src/styx.ts ./src/index.ts --outdir ./dist --target bun -e @elysiumjs/*
|
|
16
|
+
"build:js": "bun build ./src/styx.ts ./src/index.ts --outdir ./dist --target bun -e @elysiumjs/* --root ./src --minify-syntax --minify-whitespace",
|
|
17
17
|
"build:ts": "tsc",
|
|
18
18
|
"build": "bun run clean && bun run build:js && bun run build:ts",
|
|
19
19
|
"typecheck": "tsc --noEmit",
|
|
@@ -28,14 +28,15 @@
|
|
|
28
28
|
"cli"
|
|
29
29
|
],
|
|
30
30
|
"type": "module",
|
|
31
|
+
"sideEffects": false,
|
|
31
32
|
"bin": {
|
|
32
33
|
"styx": "dist/styx.js"
|
|
33
34
|
},
|
|
34
35
|
"module": "dist/index.js",
|
|
35
36
|
"types": "dist/index.d.ts",
|
|
36
37
|
"devDependencies": {
|
|
37
|
-
"@elysiumjs/core": "0.
|
|
38
|
-
"@elysiumjs/heracles": "0.
|
|
38
|
+
"@elysiumjs/core": "0.8.0",
|
|
39
|
+
"@elysiumjs/heracles": "0.7.0",
|
|
39
40
|
"@types/prompts": "^2.4.9",
|
|
40
41
|
"@types/string-template": "^1.0.7",
|
|
41
42
|
"prompts": "^2.4.2",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"string-template": "^1.0.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"@elysiumjs/core": "^0.
|
|
47
|
-
"@elysiumjs/heracles": "^0.
|
|
47
|
+
"@elysiumjs/core": "^0.8.0",
|
|
48
|
+
"@elysiumjs/heracles": "^0.7.0"
|
|
48
49
|
}
|
|
49
50
|
}
|
package/stubs/job.stub
CHANGED
package/stubs/model.stub
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DrizzleModel, pgTable } from '@elysiumjs/mnemosyne-drizzle';
|
|
2
2
|
import { uuid } from 'drizzle-orm/pg-core';
|
|
3
3
|
|
|
4
|
-
export
|
|
4
|
+
export const {canonicalName}Table = pgTable('{table}', {
|
|
5
5
|
id: uuid().primaryKey().defaultRandom(),
|
|
6
|
-
})
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export class {name} extends DrizzleModel({canonicalName}Table) {
|
|
7
9
|
public static readonly supportTenancy = {supportTenancy};
|
|
8
10
|
}
|
|
9
11
|
|
package/stubs/repository.stub
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Service, ServiceScope } from '@elysiumjs/core';
|
|
2
|
+
import { DrizzleRepository } from '@elysiumjs/mnemosyne-drizzle';
|
|
2
3
|
|
|
3
4
|
import { {model} } from '#{module}/models/{model_name}.model';
|
|
4
5
|
|
|
5
6
|
@Service.register({ name: '{alias}', scope: ServiceScope.{scope} })
|
|
6
|
-
export class {name} extends
|
|
7
|
+
export class {name} extends DrizzleRepository({model}) {}
|
package/stubs/service.stub
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Service, ServiceScope } from '@elysiumjs/core';
|
|
2
|
+
import { HermesLogger } from '@elysiumjs/hermes';
|
|
2
3
|
|
|
3
4
|
@Service.register({ name: '{alias}', scope: ServiceScope.{scope} })
|
|
4
5
|
export class {name} {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from './base.command';
|
|
2
|
-
/**
|
|
3
|
-
* Generates migration files.
|
|
4
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
5
|
-
*/
|
|
6
|
-
export declare class MigrationGenerateCommand extends BaseCommand {
|
|
7
|
-
static readonly command: string;
|
|
8
|
-
static readonly description: string;
|
|
9
|
-
private name?;
|
|
10
|
-
run(): Promise<void>;
|
|
11
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseCommand } from './base.command';
|
|
2
|
-
/**
|
|
3
|
-
* Execute migration files.
|
|
4
|
-
* @author Axel Nana <axel.nana@workbud.com>
|
|
5
|
-
*/
|
|
6
|
-
export declare class MigrationRunCommand extends BaseCommand {
|
|
7
|
-
static readonly command: string;
|
|
8
|
-
static readonly description: string;
|
|
9
|
-
private tenant;
|
|
10
|
-
private connection;
|
|
11
|
-
private fresh;
|
|
12
|
-
run(): Promise<void>;
|
|
13
|
-
}
|