@elysiumjs/styx 0.5.0 → 0.6.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.
@@ -1,78 +0,0 @@
1
- // Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { Command, CommandArgumentType } from '@elysiumjs/core';
16
- import prompts from 'prompts';
17
-
18
- import { parseProjectConfig } from '../config';
19
- import { createModule } from '../utils';
20
-
21
- /**
22
- * Command for renaming Elysium.js modules.
23
- * @author Axel Nana <axel.nana@workbud.com>
24
- */
25
- export class ModuleRenameCommand extends Command {
26
- public static readonly command: string = 'module:rename';
27
- public static readonly description: string = 'Renames a module.';
28
-
29
- @Command.arg({
30
- description: 'The module to rename',
31
- type: CommandArgumentType.STRING
32
- })
33
- private module?: string;
34
-
35
- @Command.arg({
36
- description: 'The new name of the module',
37
- type: CommandArgumentType.STRING
38
- })
39
- private name?: string;
40
-
41
- public override async run(): Promise<void> {
42
- const config = await parseProjectConfig();
43
-
44
- if (config.mono) {
45
- return this.error('This operation is not supported for mono-module projects.');
46
- }
47
-
48
- if (!this.module) {
49
- const { module } = await prompts({
50
- type: 'text',
51
- name: 'module',
52
- message: 'Module to rename:',
53
- validate: (value) => value.length > 0
54
- });
55
-
56
- this.module = module as string;
57
- }
58
-
59
- if (!this.name) {
60
- const { name } = await prompts({
61
- type: 'text',
62
- name: 'name',
63
- message: 'New module name:',
64
- initial: this.module,
65
- validate: (value) => value.length > 0
66
- });
67
-
68
- this.name = name as string;
69
- }
70
-
71
- if (this.module === this.name) {
72
- return this.info('Module name is the same as the current name.');
73
- }
74
-
75
- await createModule(this.name!, this.module!);
76
- this.success(`Module '${this.module}' renamed to '${this.name}'.`);
77
- }
78
- }
package/src/config.ts DELETED
@@ -1,101 +0,0 @@
1
- // Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { join } from 'node:path';
16
-
17
- import { getProjectPath } from './utils';
18
-
19
- /**
20
- * Describes the Elysium project's configuration.
21
- * @author Axel Nana <axel.nana@workbud.com>
22
- */
23
- export interface ProjectConfig {
24
- /**
25
- * The name of the Elysium project.
26
- */
27
- projectName: string;
28
-
29
- /**
30
- * Whether the Elysium project is a mono module.
31
- */
32
- mono: boolean;
33
-
34
- /**
35
- * A map of module names to their paths.
36
- *
37
- * Only used if the Elysium project is not a mono module.
38
- */
39
- modules?: Record<string, string>;
40
- }
41
-
42
- /**
43
- * Parses the Elysium project's configuration file.
44
- * @author Axel Nana <axel.nana@workbud.com>
45
- * @throws If the Elysium config file is not found.
46
- * @returns The Elysium project's configuration.
47
- */
48
- export const parseProjectConfig = async (): Promise<ProjectConfig> => {
49
- const file = Bun.file(join(getProjectPath(), '.elysiumrc'));
50
- if (!file.exists()) {
51
- throw new Error('Elysium config file not found.');
52
- }
53
-
54
- return file.json();
55
- };
56
-
57
- /**
58
- * Writes the Elysium project's configuration file.
59
- * @author Axel Nana <axel.nana@workbud.com>
60
- * @param config The Elysium project's configuration.
61
- */
62
- export const writeProjectConfig = async (config: ProjectConfig) => {
63
- const file = Bun.file(join(getProjectPath(), '.elysiumrc'));
64
- await file.write(JSON.stringify(config, null, 2));
65
- };
66
-
67
- /**
68
- * Checks if the Elysium project is a mono-module project.
69
- * @author Axel Nana <axel.nana@workbud.com>
70
- * @returns Whether the Elysium project is a mono module.
71
- */
72
- export const isMonoModule = async () => {
73
- const config = await parseProjectConfig();
74
- return config.mono;
75
- };
76
-
77
- /**
78
- * Gets the path of a module.
79
- * @author Axel Nana <axel.nana@workbud.com>
80
- * @param moduleName The name of the module.
81
- * @returns The path of the module.
82
- */
83
- export const getModulePath = async (moduleName: string) => {
84
- const config = await parseProjectConfig();
85
- if (config.mono) {
86
- return './src';
87
- }
88
-
89
- return config.modules![moduleName];
90
- };
91
-
92
- /**
93
- * Checks if a module exists.
94
- * @author Axel Nana <axel.nana@workbud.com>
95
- * @param moduleName The name of the module.
96
- * @returns Whether the module exists.
97
- */
98
- export const moduleExists = async (moduleName: string) => {
99
- const path = await getModulePath(moduleName);
100
- return Bun.file(path).exists();
101
- };
package/src/styx.ts DELETED
@@ -1,54 +0,0 @@
1
- #!/usr/bin/env bun
2
- // Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
3
- //
4
- // Licensed under the Apache License, Version 2.0 (the "License");
5
- // you may not use this file except in compliance with the License.
6
- // You may obtain a copy of the License at
7
- //
8
- // http://www.apache.org/licenses/LICENSE-2.0
9
- //
10
- // Unless required by applicable law or agreed to in writing, software
11
- // distributed under the License is distributed on an "AS IS" BASIS,
12
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- // See the License for the specific language governing permissions and
14
- // limitations under the License.
15
- import 'reflect-metadata';
16
-
17
- import {
18
- MakeCommandCommand,
19
- MakeControllerCommand,
20
- MakeJobCommand,
21
- MakeMiddlewareCommand,
22
- MakeModelCommand,
23
- MakeRepositoryCommand,
24
- MakeServiceCommand,
25
- MakeValidatorCommand,
26
- MigrationGenerateCommand,
27
- MigrationRunCommand,
28
- ModuleNewCommand,
29
- ModuleRenameCommand
30
- } from './commands';
31
- import { getProjectPath } from './utils';
32
-
33
- const projectPath = getProjectPath();
34
- const { App } = await import(`${projectPath}/src/app`);
35
-
36
- @App.register({
37
- commands: [
38
- MakeCommandCommand,
39
- MakeControllerCommand,
40
- MakeJobCommand,
41
- MakeMiddlewareCommand,
42
- MakeModelCommand,
43
- MakeRepositoryCommand,
44
- MakeServiceCommand,
45
- MakeValidatorCommand,
46
- MigrationGenerateCommand,
47
- MigrationRunCommand,
48
- ModuleNewCommand,
49
- ModuleRenameCommand
50
- ]
51
- })
52
- class StyxApp extends App {}
53
-
54
- new StyxApp();
package/src/utils.ts DELETED
@@ -1,148 +0,0 @@
1
- // Copyright (c) 2025-present Workbud Technologies Inc. All rights reserved.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
-
15
- import { existsSync } from 'node:fs';
16
- import { mkdir, readdir, rename } from 'node:fs/promises';
17
- import { dirname, extname, join } from 'node:path';
18
-
19
- /**
20
- * Gets the root path of the styx package.
21
- * @author Axel Nana <axel.nana@workbud.com>
22
- */
23
- export const getRootPath = () => {
24
- return dirname(Bun.fileURLToPath(import.meta.url));
25
- };
26
-
27
- /**
28
- * Gets the root path of the Elysium.js project.
29
- * @author Axel Nana <axel.nana@workbud.com>
30
- *
31
- * @returns The detected project path.
32
- */
33
- export const getProjectPath = () => {
34
- let startPath = process.cwd(),
35
- dir = startPath;
36
-
37
- while (true) {
38
- if (existsSync(join(dir, '.elysiumrc'))) return dir;
39
-
40
- const parentDir = dirname(dir);
41
- if (dir === parentDir) break;
42
-
43
- dir = parentDir;
44
- }
45
-
46
- return startPath;
47
- };
48
-
49
- /**
50
- * Creates a new module or rename an existing module.
51
- * @author Axel Nana <axel.nana@workbud.com>
52
- *
53
- * @param name The name of the module to create or rename.
54
- * @param oldName The old name of the module to rename.
55
- */
56
- export const createModule = async (name: string, oldName?: string) => {
57
- const root = getProjectPath();
58
-
59
- // Create module directory
60
- {
61
- const moduleDir = join(root, 'src', 'modules', name);
62
- await mkdir(moduleDir, { recursive: true });
63
-
64
- if (oldName) {
65
- if (oldName === 'root') {
66
- const entries = await readdir(join(root, 'src'));
67
- for (const entry of entries) {
68
- if (['app.ts', 'env.ts', 'database', 'modules'].includes(entry)) continue;
69
- const oldPath = join(root, 'src', entry);
70
- const newPath = join(moduleDir, entry === 'main.module.ts' ? `${name}.module.ts` : entry);
71
- await rename(oldPath, newPath);
72
- }
73
- } else {
74
- const oldModuleDir = join(root, 'src', 'modules', oldName);
75
- await rename(oldModuleDir, moduleDir);
76
- }
77
- }
78
- }
79
-
80
- // Update package.json imports
81
- {
82
- const pkg = await Bun.file(join(root, 'package.json')).json();
83
-
84
- pkg.imports = pkg.imports ?? {};
85
- pkg.imports[`#${name}/*`] = `./src/modules/${name}/*.ts`;
86
-
87
- if (oldName && oldName !== 'root') {
88
- delete pkg.imports[`#${oldName}/*`];
89
- }
90
-
91
- await Bun.write(join(root, 'package.json'), JSON.stringify(pkg, null, 2));
92
- }
93
-
94
- // Update .elysiumrc
95
- {
96
- const rc = await Bun.file(join(root, '.elysiumrc')).json();
97
-
98
- rc.mono = false;
99
- rc.modules = rc.modules ?? {};
100
- rc.modules[name] = `./src/modules/${name}`;
101
-
102
- if (oldName) {
103
- delete rc.modules[oldName];
104
- }
105
-
106
- await Bun.write(join(root, '.elysiumrc'), JSON.stringify(rc, null, 2));
107
- }
108
-
109
- // Update imports in all modules
110
- if (oldName) {
111
- const rewriteImports = async (dir: string) => {
112
- const entries = await readdir(dir, { withFileTypes: true });
113
-
114
- for (const entry of entries) {
115
- const fullPath = join(dir, entry.name);
116
-
117
- if (entry.isDirectory()) {
118
- await rewriteImports(fullPath);
119
- } else if (extname(entry.name) === '.ts') {
120
- let text = await Bun.file(fullPath).text();
121
-
122
- if (oldName === 'root') {
123
- text = text.replace(
124
- new RegExp(`(['"])#${oldName}/((?!(env|app|database(?:/|$))).*?)(['"])`, 'g'),
125
- `$1#${name}/$2$4`
126
- );
127
- } else {
128
- text = text.replace(new RegExp(`(['"])#${oldName}/`, 'g'), `$1#${name}/`);
129
- }
130
-
131
- text = text.replace(
132
- new RegExp(`(['"])#${oldName}/main\\.module(['"])/g`, 'g'),
133
- `$1#${name}/${name}.module$2`
134
- );
135
-
136
- text = text.replace(
137
- new RegExp(`(['"])#${oldName}/main\\.module\\.ts(['"])?/g`, 'g'),
138
- `$1#${name}/${name}.module$2`
139
- );
140
-
141
- await Bun.write(fullPath, text);
142
- }
143
- }
144
- };
145
-
146
- await rewriteImports(root);
147
- }
148
- };