@cloudnux/cli 0.10.0 → 0.12.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/dist/cli.mjs CHANGED
@@ -444,6 +444,19 @@ var devServerWatch = {
444
444
  const { workingDir, logger, eventEmitter } = params;
445
445
  const entryPath = path11.resolve(workingDir, "app.ts");
446
446
  await tsup2.build({
447
+ format: ["esm"],
448
+ banner: {
449
+ js: `
450
+ import __node_module from 'node:module';
451
+ import __node_url from 'node:url';
452
+ import __node_path from 'node:path';
453
+ const require = __node_module.createRequire(import.meta.url);
454
+ const __filename = __node_url.fileURLToPath(import.meta.url);
455
+ const __dirname = __node_path.dirname(__filename);
456
+ `.trim()
457
+ },
458
+ outExtension: () => ({ js: ".mjs" }),
459
+ //========================================
447
460
  entry: {
448
461
  index: entryPath
449
462
  },
@@ -451,7 +464,6 @@ var devServerWatch = {
451
464
  options.absWorkingDir = workingDir;
452
465
  return options;
453
466
  },
454
- format: ["cjs"],
455
467
  bundle: true,
456
468
  noExternal: [],
457
469
  sourcemap: true,
@@ -485,9 +497,7 @@ var devServerWatch = {
485
497
  }
486
498
  },
487
499
  startServerPlugin(logger, eventEmitter)
488
- ],
489
- silent: true
490
- // Prevent console output
500
+ ]
491
501
  });
492
502
  }
493
503
  };
@@ -537,7 +547,7 @@ function startServerPlugin(logger, eventEmitter) {
537
547
  errors.forEach(logger);
538
548
  return;
539
549
  }
540
- const main = outputFiles?.find((file) => file.path.endsWith(".js") || file.path.endsWith(".cjs"))?.path;
550
+ const main = outputFiles?.find((file) => file.path.endsWith(".js") || file.path.endsWith(".mjs"))?.path;
541
551
  child = startModule(main, ["--enable-source-maps"], logger, eventEmitter);
542
552
  });
543
553
  }
@@ -11,59 +11,7 @@ useCloudProvider(localCloudProvider);
11
11
  import <%=module%>Entries from "./<%=module%>"
12
12
  <%_ } _%>
13
13
 
14
-
15
- // Function to send logs to the parent process
16
- function sendMessage(type: string, payload: any) {
17
- if (process && process.send) {
18
- process.send({ type, payload: payload });
19
- } else {
20
- console.log(`[${type}]`, payload); // Fallback for non-parent process
21
- }
22
- }
23
-
24
- const router = createRouter();
25
-
26
- // Add fastify hooks
27
- //router.addHook('onRegister', async (instance, opts) => {
28
- // sendMessage("APP_REGISTERED", { prefix: instance.prefix, opts });
29
- //});
30
- //router.addHook('onRoute', (routeOptions) => {
31
- // sendMessage('ROUTE_REGISTERED', {
32
- // method: routeOptions.method,
33
- // url: routeOptions.url,
34
- // handler: routeOptions.handler.name,
35
- // });
36
- //});
37
- //
38
- //router.addHook('onListen', function (done) {
39
- // try{
40
- // sendMessage('LISTENING', {
41
- // port: 3000,
42
- // host:"::"
43
- // });
44
- // }catch(err){
45
- // sendMessage('ERROR', {err});
46
- // }finally{
47
- // const err = null; // to be updated later to handle crash errors
48
- // done(err)
49
- // }
50
- //});
51
- //
52
- //router.addHook('preHandler', (request, reply, done) => {
53
- // sendMessage('REQUEST', { id: request.id, params: request.params, query: request.query, requestBody: request.body, headers: request.headers, url: request.url, method:request.method, time: new Date().toLocaleTimeString() });
54
- // done();
55
- //});
56
- //
57
- //router.addHook('onSend', (request, reply,payload, done) => {
58
- // sendMessage('RESPONSE', { id: request.id, responseStatus: reply.statusCode, method:request.method, url:request.url, responseBody:JSON.parse(payload), time: new Date().toLocaleTimeString() });
59
- // done(null, payload);
60
- //});
61
- //
62
- //router.addHook('onError', (request, reply, error, done) => {
63
- // sendMessage('ERROR', {error, request, reply});
64
- // done();
65
- //});
66
-
14
+ const router = createRouter({logger : true});
67
15
 
68
16
  router.register(queuesPlugin, { prefix: "queues" });
69
17
  router.register(schedulerPlugin, { prefix: "schedules" });
@@ -74,6 +22,11 @@ router.register(websocketsPlugin, { prefix: "websockets" });
74
22
  router.register(<%=module%>Entries, { prefix: "api" });
75
23
  <%_ } _%>
76
24
 
77
- router.listen({ port: 3000, host : "::" }, () => {
78
- console.log(`Server listening on port ${router.server.address().port} ...`)
25
+ router.listen({ port: 3000, host: "::" }, (err) => {
26
+ if (err) {
27
+ console.error('Error starting server:', err);
28
+ process.exit(1);
29
+ }
30
+ else
31
+ console.log(`Server listening on port ${router?.server?.address()?.port} ...`)
79
32
  });
@@ -0,0 +1,165 @@
1
+ type TaskParamBase = Record<string, any>;
2
+ type TaskParam = {
3
+ modulesPath: string;
4
+ /**
5
+ * cloud provider package to use, any locally installed package can be used
6
+ * aws is an alias for @cloudnux/aws-cloud-provider
7
+ * azure is an alias for @cloudnux/azure-cloud-provider
8
+ * gcp is an alias for @cloudnux/gcp-cloud-provider
9
+ */
10
+ cloudProvider: string;
11
+ /**
12
+ * Path to store the current environment build artifacts
13
+ * @default '.nux/<environment>'
14
+ */
15
+ workingDir: string;
16
+ /**
17
+ * task title
18
+ * @note: this is set by the task manager
19
+ */
20
+ title?: string;
21
+ /**
22
+ * environment name
23
+ */
24
+ environment: string;
25
+ /**
26
+ * logger function to log messages
27
+ */
28
+ logger: (arg: any, data?: any) => void;
29
+ /**
30
+ * event emitter function to emit events
31
+ */
32
+ eventEmitter: (type: string, data?: any) => void;
33
+ children?: Task[];
34
+ [key: string]: any;
35
+ };
36
+ type TaskTitle = string | ((params: TaskParam) => string);
37
+ type Task<TTaskParams extends TaskParamBase = any> = {
38
+ title: string | ((params: TTaskParams) => string);
39
+ action: (params: TTaskParams) => any | Promise<any>;
40
+ skip?: (params: TTaskParams) => boolean;
41
+ children?: Task<TTaskParams>[];
42
+ };
43
+ type Environment<TTaskParams extends TaskParamBase = any> = {
44
+ /**
45
+ * tasks to be executed for this environment
46
+ */
47
+ tasks: Task<TTaskParams>[];
48
+ /**
49
+ * watch task
50
+ * if set, task will be executed and all logs will be routed to the watch view.
51
+ * This is useful for development environments where you want to see the logs in real-time
52
+ * @note: process will not exit until error or ctrl+c is pressed
53
+ * @default undefined
54
+ */
55
+ watch?: Task;
56
+ /**
57
+ * additional parameters for this environment
58
+ */
59
+ [key: string]: any;
60
+ };
61
+ type Config<TTaskParams extends TaskParamBase = any> = {
62
+ /**
63
+ * glob Path to find all modules (package.json) having entrypoints
64
+ * @default './packages/modules/**\/package.json'
65
+ */
66
+ modulesPath: string;
67
+ /**
68
+ * cloud provider package to use, any locally installed package can be used
69
+ * aws is an alias for @cloudnux/aws-cloud-provider
70
+ * azure is an alias for @cloudnux/azure-cloud-provider
71
+ * gcp is an alias for @cloudnux/gcp-cloud-provider
72
+ * @default 'aws'
73
+ */
74
+ cloudProvider: string;
75
+ /**
76
+ * Path to store the build artifacts for all environments
77
+ * @default './.nux'
78
+ */
79
+ workingDir: string;
80
+ /**
81
+ * environment configuration with key as environment name and value as Environment
82
+ * @default { develop: { tasks: [] }, prod: { tasks: [] } }
83
+ */
84
+ environments: Record<string, Environment<TTaskParams>>;
85
+ /**
86
+ * External packages to be used in the module build
87
+ * @default: ["aws-sdk", "@aws-sdk/*"]
88
+ */
89
+ externalPackages: string[];
90
+ };
91
+ type Args = {
92
+ inputs: {
93
+ env: string;
94
+ module?: string;
95
+ };
96
+ flags: {
97
+ configFile: string | undefined;
98
+ };
99
+ };
100
+ type AppProps = {
101
+ config: Config;
102
+ args: Args;
103
+ };
104
+ type Module = {
105
+ id: string;
106
+ name: string;
107
+ endpoints: any[];
108
+ data?: any;
109
+ };
110
+ type TaskStatus = 'pending' | 'running' | 'completed' | 'error' | 'skipped';
111
+ interface TaskState {
112
+ id: string;
113
+ title: string;
114
+ status: TaskStatus;
115
+ error?: string;
116
+ children: string[];
117
+ logs: any[];
118
+ parentId?: string;
119
+ }
120
+ interface TaskManagerStore {
121
+ tasks: Record<string, TaskState>;
122
+ currentTaskId: string | null;
123
+ environment: string;
124
+ isRunning: boolean;
125
+ tasksCount: number;
126
+ start: (config: Config, env: string) => Promise<void>;
127
+ addTask: (task: {
128
+ id: string;
129
+ title: string;
130
+ parentTaskId?: string;
131
+ }) => void;
132
+ updateTaskStatus: (taskId: string, status: TaskStatus, error?: string) => void;
133
+ addTaskLog: (taskId: string, log: any, data: any) => void;
134
+ }
135
+ interface Log {
136
+ url: string;
137
+ method: string;
138
+ status: number;
139
+ payload: any;
140
+ time: Date;
141
+ }
142
+ interface DevServerStore {
143
+ isRunning: boolean;
144
+ modules: Module[];
145
+ selectedModule: string | null;
146
+ selectedEndpoint: any | null;
147
+ port: string;
148
+ host: string;
149
+ logs: Array<any>;
150
+ pinoLogs: Array<any>;
151
+ watch: (config: Config, env: string) => Promise<void>;
152
+ addModule: (id: string, opts: any) => void;
153
+ addRoute: (route: any) => void;
154
+ addActionLog(id: string, data: any): void;
155
+ addPinoLog(id: string, data: any): void;
156
+ startListening: ({ host, port }: {
157
+ host: string;
158
+ port: string;
159
+ }) => void;
160
+ selectModule: (id: string) => void;
161
+ selectEndpoint: (endpoint: any) => void;
162
+ resetSelection: () => void;
163
+ }
164
+
165
+ export type { AppProps, Args, Config, DevServerStore, Environment, Log, Task, TaskManagerStore, TaskParam, TaskParamBase, TaskState, TaskStatus, TaskTitle };
package/dist/types.mjs ADDED
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "@cloudnux/cli",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "license": "MIT",
5
5
  "bin": {
6
6
  "nux": "dist/cli.mjs"
7
7
  },
8
8
  "main": "./dist/cli.js",
9
9
  "types": "./dist/cli.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/types.d.ts",
13
+ "import": "./dist/types.mjs"
14
+ }
15
+ },
10
16
  "type": "module",
11
17
  "engines": {
12
18
  "node": ">=22"
@@ -37,10 +43,10 @@
37
43
  "pino-pretty": "^13.0.0",
38
44
  "rechoir": "^0.8.0",
39
45
  "tsup": "^8.3.5",
40
- "@cloudnux/aws-cloud-provider": "0.10.0",
41
- "@cloudnux/local-cloud-provider": "0.10.0",
42
- "@cloudnux/cloud-sdk": "0.10.0",
43
- "@cloudnux/dev-console": "0.10.0"
46
+ "@cloudnux/aws-cloud-provider": "0.12.0",
47
+ "@cloudnux/local-cloud-provider": "0.12.0",
48
+ "@cloudnux/cloud-sdk": "0.12.0",
49
+ "@cloudnux/dev-console": "0.12.0"
44
50
  },
45
51
  "devDependencies": {
46
52
  "@types/ejs": "^3.1.5",