@elysiumjs/styx 0.8.2 → 0.9.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.
Files changed (54) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +52 -41
  3. package/dist/assets.d.ts +31 -0
  4. package/dist/cli/app.d.ts +15 -0
  5. package/dist/cli/route.d.ts +51 -0
  6. package/dist/cli.d.ts +2 -0
  7. package/dist/cli.js +200 -0
  8. package/dist/commands/index.d.ts +1 -0
  9. package/dist/commands/routes_generate.command.d.ts +11 -0
  10. package/dist/config.d.ts +5 -0
  11. package/dist/create/code.d.ts +77 -0
  12. package/dist/create/create.command.d.ts +60 -0
  13. package/dist/create/names.d.ts +42 -0
  14. package/dist/create/versions.d.ts +7 -0
  15. package/dist/index.js +9 -3
  16. package/dist/routes/collect.d.ts +20 -0
  17. package/dist/routes/render.d.ts +39 -0
  18. package/package.json +13 -10
  19. package/stubs/http.controller.stub +1 -1
  20. package/stubs/ws.controller.stub +1 -1
  21. package/templates/feature-hephaestus/.specs +7 -0
  22. package/templates/feature-hephaestus/hephaestus.config.ts +7 -0
  23. package/templates/feature-prettier/.prettierignore +5 -0
  24. package/templates/feature-prettier/.prettierrc +23 -0
  25. package/templates/feature-prettier/.specs +13 -0
  26. package/templates/plugin-sentry/.env.example +2 -0
  27. package/templates/plugin-sentry/.specs +12 -0
  28. package/templates/shared-module/commands/.gitkeep +0 -0
  29. package/templates/shared-module/controllers/http/.gitkeep +0 -0
  30. package/templates/shared-module/controllers/wamp/.gitkeep +0 -0
  31. package/templates/shared-module/controllers/ws/.gitkeep +0 -0
  32. package/templates/shared-module/jobs/.gitkeep +0 -0
  33. package/templates/shared-module/middlewares/.gitkeep +0 -0
  34. package/templates/shared-module/models/.gitkeep +0 -0
  35. package/templates/shared-module/repositories/.gitkeep +0 -0
  36. package/templates/shared-module/services/.gitkeep +0 -0
  37. package/templates/shared-module/utils/.gitkeep +0 -0
  38. package/templates/shared-module/validators/.gitkeep +0 -0
  39. package/templates/template-multi/.gitattributes +15 -0
  40. package/templates/template-multi/README.md +20 -0
  41. package/templates/template-multi/gitignore +45 -0
  42. package/templates/template-multi/index.ts +10 -0
  43. package/templates/template-multi/package.json +8 -0
  44. package/templates/template-multi/src/modules/.gitkeep +0 -0
  45. package/templates/template-multi/tsconfig.json +32 -0
  46. package/templates/template-multi/types.d.ts +5 -0
  47. package/templates/template-single/.gitattributes +15 -0
  48. package/templates/template-single/README.md +20 -0
  49. package/templates/template-single/gitignore +45 -0
  50. package/templates/template-single/index.ts +10 -0
  51. package/templates/template-single/package.json +8 -0
  52. package/templates/template-single/tsconfig.json +32 -0
  53. package/templates/template-single/types.d.ts +5 -0
  54. package/dist/styx.js +0 -11
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@elysiumjs/styx",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "license": "Apache-2.0",
5
- "description": "The CLI tool for the Elysium.js framework.",
5
+ "description": "The command line tool of the Elysium.js framework: creates projects, generates code and runs app commands.",
6
6
  "private": false,
7
7
  "author": "Workbud Technologies Inc.",
8
8
  "repository": {
@@ -17,13 +17,14 @@
17
17
  "scripts": {
18
18
  "format": "prettier --write \"./src/**/*.ts\"",
19
19
  "clean": "rimraf dist",
20
- "build:js": "bun build ./src/styx.ts ./src/index.ts --outdir ./dist --target bun -e @elysiumjs/* --root ./src --minify-syntax --minify-whitespace",
20
+ "build:js": "bun build ./src/cli.ts ./src/index.ts --outdir ./dist --target bun -e @elysiumjs/* --root ./src --minify-syntax --minify-whitespace",
21
21
  "build:ts": "tsc",
22
22
  "build": "bun run clean && bun run build:js && bun run build:ts",
23
23
  "typecheck": "tsc --noEmit",
24
24
  "prepublishOnly": "bun run build",
25
25
  "test": "bun test",
26
- "test:coverage": "bun test --coverage"
26
+ "test:coverage": "bun test --coverage",
27
+ "build:bin": "bun scripts/build-bin.ts"
27
28
  },
28
29
  "keywords": [
29
30
  "elysium",
@@ -36,26 +37,28 @@
36
37
  "type": "module",
37
38
  "sideEffects": false,
38
39
  "bin": {
39
- "styx": "dist/styx.js"
40
+ "styx": "dist/cli.js"
40
41
  },
41
42
  "module": "dist/index.js",
42
43
  "types": "dist/index.d.ts",
43
44
  "files": [
44
45
  "dist",
45
46
  "stubs",
47
+ "templates",
46
48
  "CHANGELOG.md"
47
49
  ],
48
50
  "devDependencies": {
49
- "@elysiumjs/core": "0.10.0",
50
- "@elysiumjs/heracles": "0.7.2",
51
+ "@elysiumjs/core": "0.11.0",
52
+ "@elysiumjs/hephaestus": "0.4.0",
53
+ "@elysiumjs/runtime-bun": "0.1.0",
51
54
  "@types/prompts": "^2.4.9",
52
55
  "@types/string-template": "^1.0.7",
53
56
  "prompts": "^2.4.2",
54
57
  "radash": "^12.1.1",
55
58
  "string-template": "^1.0.0"
56
59
  },
57
- "peerDependencies": {
58
- "@elysiumjs/core": "^0.10.0",
59
- "@elysiumjs/heracles": "^0.7.2"
60
+ "dependencies": {
61
+ "@elysiumjs/core": "^0.11.0",
62
+ "@elysiumjs/runtime-bun": "^0.1.0"
60
63
  }
61
64
  }
@@ -1,6 +1,6 @@
1
1
  import { Http, HttpControllerScope } from '@elysiumjs/core';
2
2
 
3
- @Http.controller({ path: '{path}', scope: HttpControllerScope.{scope} })
3
+ @Http.controller('{path}', { scope: HttpControllerScope.{scope} })
4
4
  export class {name} {
5
5
  @Http.get()
6
6
  public async get() {
@@ -2,7 +2,7 @@ import type { WS, WSError } from '@elysiumjs/core';
2
2
 
3
3
  import { Websocket } from '@elysiumjs/core';
4
4
 
5
- @Websocket.controller({ path: '{path}' })
5
+ @Websocket.controller('{path}')
6
6
  export class {name} {
7
7
  @Websocket.onOpen()
8
8
  private onOpen() {
@@ -0,0 +1,7 @@
1
+ {
2
+ "packages": {
3
+ "dev": [
4
+ "@elysiumjs/hephaestus"
5
+ ]
6
+ }
7
+ }
@@ -0,0 +1,7 @@
1
+ import type { HephaestusConfig } from '@elysiumjs/hephaestus';
2
+
3
+ export default {
4
+ output: {
5
+ name: '{PROJECT_NAME}'
6
+ }
7
+ } satisfies HephaestusConfig;
@@ -0,0 +1,5 @@
1
+ # Package Managers
2
+ package-lock.json
3
+ pnpm-lock.yaml
4
+ yarn.lock
5
+ bun.lock
@@ -0,0 +1,23 @@
1
+ {
2
+ "useTabs": true,
3
+ "singleQuote": true,
4
+ "trailingComma": "none",
5
+ "printWidth": 100,
6
+ "plugins": ["@ianvs/prettier-plugin-sort-imports"],
7
+ "importOrder": [
8
+ "<TYPES>^(node:)",
9
+ "<TYPES>",
10
+ "<TYPES>^[.]",
11
+ "",
12
+ "<BUILTIN_MODULES>",
13
+ "",
14
+ "<THIRD_PARTY_MODULES>",
15
+ "",
16
+ "^\\#",
17
+ "",
18
+ "^[.]"
19
+ ],
20
+ "importOrderParserPlugins": ["typescript", "decorators-legacy"],
21
+ "importOrderTypeScriptVersion": "5.8.0",
22
+ "overrides": []
23
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "packages": {
3
+ "dev": [
4
+ "@ianvs/prettier-plugin-sort-imports",
5
+ "prettier"
6
+ ]
7
+ },
8
+ "patch": {
9
+ "scripts": {
10
+ "format": "prettier --write \"./**/*.ts\""
11
+ }
12
+ }
13
+ }
@@ -0,0 +1,2 @@
1
+ # Required by SentryModule: boot fails without a DSN.
2
+ SENTRY_DSN=
@@ -0,0 +1,12 @@
1
+ {
2
+ "packages": {
3
+ "prod": [
4
+ "@elysiumjs/plugin-sentry"
5
+ ]
6
+ },
7
+ "module": {
8
+ "name": "@elysiumjs/plugin-sentry",
9
+ "import": "SentryModule",
10
+ "expression": "SentryModule.with({})"
11
+ }
12
+ }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,15 @@
1
+ # Set default behavior to automatically normalize line endings
2
+ * text=auto eol=lf
3
+
4
+ # Denote all files that are truly binary and should not be modified.
5
+ *.png binary
6
+ *.jpg binary
7
+ *.jpeg binary
8
+ *.gif binary
9
+ *.ico binary
10
+ *.woff binary
11
+ *.woff2 binary
12
+ *.ttf binary
13
+ *.eot binary
14
+ *.pdf binary
15
+ *.zip binary
@@ -0,0 +1,20 @@
1
+ # {PROJECT_NAME}
2
+
3
+ A web application built with Elysium.
4
+
5
+ ## Getting Started
6
+
7
+ Install the dependencies, then start the app in development:
8
+
9
+ ```bash
10
+ {INSTALL}
11
+ {RUN} dev
12
+ ```
13
+
14
+ You can now access the application at http://localhost:3000.
15
+
16
+ To list the `styx` commands, run:
17
+
18
+ ```bash
19
+ styx
20
+ ```
@@ -0,0 +1,45 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.js
7
+
8
+ # testing
9
+ /coverage
10
+
11
+ # next.js
12
+ /.next/
13
+ /out/
14
+
15
+ # production
16
+ /build
17
+
18
+ # misc
19
+ .DS_Store
20
+ *.pem
21
+
22
+ # debug
23
+ npm-debug.log*
24
+ yarn-debug.log*
25
+ yarn-error.log*
26
+
27
+ # local env files
28
+ .env.local
29
+ .env.development.local
30
+ .env.test.local
31
+ .env.production.local
32
+
33
+ # vercel
34
+ .vercel
35
+
36
+ **/*.trace
37
+ **/*.zip
38
+ **/*.tar.gz
39
+ **/*.tgz
40
+ **/*.log
41
+ package-lock.json
42
+ **/*.bun
43
+
44
+ # route types written by `styx routes:generate`
45
+ src/routes.gen.ts
@@ -0,0 +1,10 @@
1
+ import type { LifecycleEvent } from '@elysiumjs/core';
2
+
3
+ import { Lifecycle } from '@elysiumjs/core';
4
+ import { App } from '#root/app';
5
+
6
+ Lifecycle.on('elysium:error', (e: LifecycleEvent<Error>) => {
7
+ console.error(JSON.stringify(e));
8
+ });
9
+
10
+ await App.start();
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "{PROJECT_NAME}",
3
+ "type": "module",
4
+ "private": true,
5
+ "imports": {
6
+ "#root/*": "./src/*.ts"
7
+ }
8
+ }
File without changes
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": [
5
+ "ESNext"
6
+ ],
7
+ "target": "ESNext",
8
+ "module": "ESNext",
9
+ "moduleDetection": "force",
10
+ "allowJs": true,
11
+ "types": [
12
+ "bun-types" // add Bun global
13
+ ],
14
+ "experimentalDecorators": true,
15
+ "emitDecoratorMetadata": true,
16
+ // Bundler mode
17
+ "moduleResolution": "bundler",
18
+ "allowImportingTsExtensions": true,
19
+ "verbatimModuleSyntax": true,
20
+ "noEmit": true,
21
+ // Best practices
22
+ "strict": true,
23
+ "skipLibCheck": true,
24
+ "noFallthroughCasesInSwitch": true,
25
+ "noUncheckedIndexedAccess": false,
26
+ "forceConsistentCasingInFileNames": true,
27
+ // Some stricter flags (disabled by default)
28
+ "noUnusedLocals": true,
29
+ "noUnusedParameters": true,
30
+ "noPropertyAccessFromIndexSignature": false,
31
+ }
32
+ }
@@ -0,0 +1,5 @@
1
+ import '@elysiumjs/core';
2
+
3
+ declare module '@elysiumjs/core' {
4
+ type AppEnv = typeof import('./src/app').env.static;
5
+ }
@@ -0,0 +1,15 @@
1
+ # Set default behavior to automatically normalize line endings
2
+ * text=auto eol=lf
3
+
4
+ # Denote all files that are truly binary and should not be modified.
5
+ *.png binary
6
+ *.jpg binary
7
+ *.jpeg binary
8
+ *.gif binary
9
+ *.ico binary
10
+ *.woff binary
11
+ *.woff2 binary
12
+ *.ttf binary
13
+ *.eot binary
14
+ *.pdf binary
15
+ *.zip binary
@@ -0,0 +1,20 @@
1
+ # {PROJECT_NAME}
2
+
3
+ A web application built with Elysium.
4
+
5
+ ## Getting Started
6
+
7
+ Install the dependencies, then start the app in development:
8
+
9
+ ```bash
10
+ {INSTALL}
11
+ {RUN} dev
12
+ ```
13
+
14
+ You can now access the application at http://localhost:3000.
15
+
16
+ To list the `styx` commands, run:
17
+
18
+ ```bash
19
+ styx
20
+ ```
@@ -0,0 +1,45 @@
1
+ # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2
+
3
+ # dependencies
4
+ /node_modules
5
+ /.pnp
6
+ .pnp.js
7
+
8
+ # testing
9
+ /coverage
10
+
11
+ # next.js
12
+ /.next/
13
+ /out/
14
+
15
+ # production
16
+ /build
17
+
18
+ # misc
19
+ .DS_Store
20
+ *.pem
21
+
22
+ # debug
23
+ npm-debug.log*
24
+ yarn-debug.log*
25
+ yarn-error.log*
26
+
27
+ # local env files
28
+ .env.local
29
+ .env.development.local
30
+ .env.test.local
31
+ .env.production.local
32
+
33
+ # vercel
34
+ .vercel
35
+
36
+ **/*.trace
37
+ **/*.zip
38
+ **/*.tar.gz
39
+ **/*.tgz
40
+ **/*.log
41
+ package-lock.json
42
+ **/*.bun
43
+
44
+ # route types written by `styx routes:generate`
45
+ src/routes.gen.ts
@@ -0,0 +1,10 @@
1
+ import type { LifecycleEvent } from '@elysiumjs/core';
2
+
3
+ import { Lifecycle } from '@elysiumjs/core';
4
+ import { App } from '#root/app';
5
+
6
+ Lifecycle.on('elysium:error', (e: LifecycleEvent<Error>) => {
7
+ console.error(JSON.stringify(e));
8
+ });
9
+
10
+ await App.start();
@@ -0,0 +1,8 @@
1
+ {
2
+ "name": "{PROJECT_NAME}",
3
+ "type": "module",
4
+ "private": true,
5
+ "imports": {
6
+ "#root/*": "./src/*.ts"
7
+ }
8
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": [
5
+ "ESNext"
6
+ ],
7
+ "target": "ESNext",
8
+ "module": "ESNext",
9
+ "moduleDetection": "force",
10
+ "allowJs": true,
11
+ "types": [
12
+ "bun-types" // add Bun global
13
+ ],
14
+ "experimentalDecorators": true,
15
+ "emitDecoratorMetadata": true,
16
+ // Bundler mode
17
+ "moduleResolution": "bundler",
18
+ "allowImportingTsExtensions": true,
19
+ "verbatimModuleSyntax": true,
20
+ "noEmit": true,
21
+ // Best practices
22
+ "strict": true,
23
+ "skipLibCheck": true,
24
+ "noFallthroughCasesInSwitch": true,
25
+ "noUncheckedIndexedAccess": false,
26
+ "forceConsistentCasingInFileNames": true,
27
+ // Some stricter flags (disabled by default)
28
+ "noUnusedLocals": true,
29
+ "noUnusedParameters": true,
30
+ "noPropertyAccessFromIndexSignature": false,
31
+ }
32
+ }
@@ -0,0 +1,5 @@
1
+ import '@elysiumjs/core';
2
+
3
+ declare module '@elysiumjs/core' {
4
+ type AppEnv = typeof import('./src/app').env.static;
5
+ }
package/dist/styx.js DELETED
@@ -1,11 +0,0 @@
1
- #!/usr/bin/env bun
2
- // @bun
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}