@cyklang/cli 0.7.3 → 0.7.5

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/build/Cmd.js CHANGED
@@ -154,7 +154,7 @@ exports.runShellCommand = runShellCommand;
154
154
  function spawnCommand(command, args) {
155
155
  console.log();
156
156
  console.log([command, ...args, '...'].join(' '));
157
- const child_process = (0, child_process_1.spawn)(command, args, { stdio: 'inherit' });
157
+ const child_process = (0, child_process_1.spawn)(command, args, { stdio: 'inherit', shell: process.platform === 'win32' });
158
158
  return new Promise((resolve, reject) => {
159
159
  child_process.on('close', (code) => {
160
160
  if (code === 0) {
@@ -176,7 +176,7 @@ exports.spawnCommand = spawnCommand;
176
176
  */
177
177
  function spawnCommandData(command, args) {
178
178
  let result = '';
179
- const child_process = (0, child_process_1.spawn)(command, args);
179
+ const child_process = (0, child_process_1.spawn)(command, args, { shell: process.platform === 'win32' });
180
180
  return new Promise((resolve, reject) => {
181
181
  child_process.stdout.on('data', (data) => {
182
182
  result += String(data);
@@ -1,5 +1,5 @@
1
1
  import { Cmd } from "./Cmd";
2
2
  export declare class OpenCommand extends Cmd {
3
3
  constructor(name: string);
4
- openBrowser(module: string, options: any): Promise<void>;
4
+ openBrowser(module_path: string, options: any): Promise<void>;
5
5
  }
@@ -12,17 +12,23 @@ class OpenCommand extends Cmd_1.Cmd {
12
12
  constructor(name) {
13
13
  super(name);
14
14
  this.description('open browser').version('0.1')
15
- .argument('<module>', 'module to execute')
16
- .action(async (module, options) => {
17
- await this.openBrowser(module, options);
15
+ .argument('<module_path>', 'module to execute or pathname')
16
+ .action(async (module_path, options) => {
17
+ await this.openBrowser(module_path, options);
18
18
  });
19
19
  }
20
- async openBrowser(module, options) {
20
+ async openBrowser(module_path, options) {
21
21
  try {
22
22
  await this.prologue(options);
23
23
  if (process.env.DBREMOTE_URL === undefined)
24
24
  throw 'DBREMOTE_URL undefined';
25
- const url = process.env.DBREMOTE_URL + '/cyk/#/run/' + module;
25
+ let url = process.env.DBREMOTE_URL;
26
+ if (module_path.startsWith('/')) {
27
+ url += module_path;
28
+ }
29
+ else {
30
+ url += '/cyk/#/run/' + module_path;
31
+ }
26
32
  const open = await import('open');
27
33
  open.default(url);
28
34
  }
package/build/index.js CHANGED
@@ -73,32 +73,40 @@ async function startServer() {
73
73
  if (orchestrator === 'kubernetes') {
74
74
  // apply resource files
75
75
  await (0, Cmd_1.spawnCommand)('kubectl', ['apply', '-f', path_1.default.join(process.cwd(), 'k8s')]);
76
+ // port-forward
77
+ const portForwardPath = path_1.default.join(process.cwd(), 'k8s', 'port-forward');
78
+ if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
79
+ throw portForwardPath + ' file not found';
80
+ const portForwardContent = JSON.parse(fs.readFileSync(portForwardPath).toString());
76
81
  // wait for the services to be available
77
82
  while (true) {
78
- const services = await (0, Cmd_1.spawnCommandData)('kubectl', ['get', 'svc', '-o', 'name']);
79
- if (services.includes('service/nodejs') && services.includes('service/postgres')) {
80
- const availNodejs = await serviceAvailable('nodejs');
81
- const availPostgres = await serviceAvailable('postgres');
82
- if (availNodejs && availPostgres)
83
+ const declared_services = await (0, Cmd_1.spawnCommandData)('kubectl', ['get', 'svc', '-o', 'name']);
84
+ let ok = true;
85
+ for (const service in portForwardContent) {
86
+ if (!Object.prototype.hasOwnProperty.call(portForwardContent, service))
87
+ continue;
88
+ if (!declared_services.includes(`service/${service}`)) {
89
+ ok = false;
90
+ break;
91
+ }
92
+ const avail = await serviceAvailable(service);
93
+ if (!avail) {
94
+ ok = false;
83
95
  break;
96
+ }
84
97
  }
98
+ if (ok)
99
+ break;
85
100
  // wait for 1 second
86
101
  logger.info('Wait for nodejs and postgres services...');
87
102
  await new Promise((resolve) => setTimeout(() => {
88
103
  resolve();
89
104
  }, 1000));
90
105
  }
91
- // port-forward
92
- const portForwardPath = path_1.default.join(process.cwd(), 'k8s', 'port-forward');
93
- if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
94
- throw portForwardPath + ' file not found';
95
- const config = JSON.parse(fs.readFileSync(portForwardPath).toString());
96
- if (!config.postgres || !config.nodejs)
97
- throw portForwardPath + ' : file format incorrect';
98
- (0, Cmd_1.spawnCommand)('kubectl', ['port-forward', 'svc/postgres', config.postgres + ':5432']);
99
- logger.info('Postgresql proxy at localhost:' + config.postgres);
100
- (0, Cmd_1.spawnCommand)('kubectl', ['port-forward', 'svc/nodejs', config.nodejs + ':3000']);
101
- logger.info('Nodejs proxy at localhost:' + config.nodejs);
106
+ for (const service in portForwardContent) {
107
+ (0, Cmd_1.spawnCommand)('kubectl', ['port-forward', `svc/${service}`, portForwardContent[service]]);
108
+ logger.info(`${service} proxy via localhost ${portForwardContent[service].split(':')[0]}`);
109
+ }
102
110
  }
103
111
  if (!orchestrator) {
104
112
  logger.error('No cyk server is defined in current folder ' + process.cwd());
@@ -173,7 +181,7 @@ class StopCommand extends commander_1.Command {
173
181
  */
174
182
  const program = new commander_1.Command();
175
183
  program.name('cyk').description('cyklang CLI')
176
- .version('0.7.3');
184
+ .version('0.7.5');
177
185
  program.addCommand(new StartCommand('start'));
178
186
  program.addCommand(new StopCommand('stop'));
179
187
  program.addCommand(new InstallCommand_1.InstallCommand('install'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.7.3",
3
+ "version": "0.7.5",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/Cmd.ts CHANGED
@@ -145,7 +145,7 @@ export async function runShellCommand(command: string, args: string[]) {
145
145
  export function spawnCommand(command: string, args: string[]): Promise<void> {
146
146
  console.log()
147
147
  console.log([command, ...args, '...'].join(' '))
148
- const child_process = spawn(command, args, { stdio: 'inherit' })
148
+ const child_process = spawn(command, args, { stdio: 'inherit', shell: process.platform === 'win32' })
149
149
  return new Promise((resolve, reject) => {
150
150
  child_process.on('close', (code) => {
151
151
  if (code === 0) {
@@ -167,7 +167,7 @@ export function spawnCommand(command: string, args: string[]): Promise<void> {
167
167
  */
168
168
  export function spawnCommandData(command: string, args: string[]): Promise<string> {
169
169
  let result = ''
170
- const child_process = spawn(command, args)
170
+ const child_process = spawn(command, args, { shell: process.platform === 'win32' })
171
171
  return new Promise((resolve, reject) => {
172
172
  child_process.stdout.on('data', (data) => {
173
173
  result += String(data)
@@ -8,18 +8,24 @@ export class OpenCommand extends Cmd {
8
8
  constructor(name: string) {
9
9
  super(name)
10
10
  this.description('open browser').version('0.1')
11
- .argument('<module>', 'module to execute')
12
- .action(async (module: any, options: any) => {
13
- await this.openBrowser(module, options)
11
+ .argument('<module_path>', 'module to execute or pathname')
12
+ .action(async (module_path: any, options: any) => {
13
+ await this.openBrowser(module_path, options)
14
14
  })
15
15
  }
16
16
 
17
- async openBrowser(module: string, options: any) {
17
+ async openBrowser(module_path: string, options: any) {
18
18
  try {
19
19
  await this.prologue(options)
20
20
 
21
21
  if (process.env.DBREMOTE_URL === undefined) throw 'DBREMOTE_URL undefined'
22
- const url = process.env.DBREMOTE_URL + '/cyk/#/run/' + module;
22
+ let url = process.env.DBREMOTE_URL
23
+ if (module_path.startsWith('/')) {
24
+ url += module_path
25
+ }
26
+ else {
27
+ url += '/cyk/#/run/' + module_path
28
+ }
23
29
  const open = await import('open');
24
30
  open.default(url)
25
31
  }
package/src/index.ts CHANGED
@@ -52,18 +52,35 @@ async function startServer() {
52
52
  // apply resource files
53
53
  await spawnCommand('kubectl', ['apply', '-f', path.join(process.cwd(), 'k8s')])
54
54
 
55
+ // port-forward
56
+ const portForwardPath = path.join(process.cwd(), 'k8s', 'port-forward')
57
+ if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
58
+ throw portForwardPath + ' file not found'
59
+ const portForwardContent = JSON.parse(fs.readFileSync(portForwardPath).toString())
60
+
55
61
  // wait for the services to be available
56
62
 
57
63
  while (true) {
58
64
 
59
- const services = await spawnCommandData('kubectl', ['get', 'svc', '-o', 'name'])
60
-
61
- if (services.includes('service/nodejs') && services.includes('service/postgres')) {
62
- const availNodejs = await serviceAvailable('nodejs')
63
- const availPostgres = await serviceAvailable('postgres')
64
- if (availNodejs && availPostgres) break
65
+ const declared_services = await spawnCommandData('kubectl', ['get', 'svc', '-o', 'name'])
66
+
67
+ let ok = true
68
+
69
+ for(const service in portForwardContent) {
70
+ if (! Object.prototype.hasOwnProperty.call(portForwardContent, service)) continue
71
+ if (! declared_services.includes(`service/${service}`)) {
72
+ ok = false
73
+ break
74
+ }
75
+ const avail = await serviceAvailable(service)
76
+ if (! avail) {
77
+ ok = false
78
+ break
79
+ }
65
80
  }
66
-
81
+
82
+ if (ok) break
83
+
67
84
  // wait for 1 second
68
85
  logger.info('Wait for nodejs and postgres services...')
69
86
  await new Promise<void>((resolve) =>
@@ -73,17 +90,11 @@ async function startServer() {
73
90
  );
74
91
  }
75
92
 
76
- // port-forward
77
- const portForwardPath = path.join(process.cwd(), 'k8s', 'port-forward')
78
- if (!fs.existsSync(portForwardPath) || !fs.statSync(portForwardPath).isFile())
79
- throw portForwardPath + ' file not found'
80
- const config = JSON.parse(fs.readFileSync(portForwardPath).toString())
81
- if (!config.postgres || !config.nodejs)
82
- throw portForwardPath + ' : file format incorrect'
83
- spawnCommand('kubectl', ['port-forward', 'svc/postgres', config.postgres + ':5432'])
84
- logger.info('Postgresql proxy at localhost:' + config.postgres)
85
- spawnCommand('kubectl', ['port-forward', 'svc/nodejs', config.nodejs + ':3000'])
86
- logger.info('Nodejs proxy at localhost:' + config.nodejs)
93
+ for(const service in portForwardContent) {
94
+ spawnCommand('kubectl', ['port-forward', `svc/${service}`, portForwardContent[service]])
95
+ logger.info(`${service} proxy via localhost ${portForwardContent[service].split(':')[0]}`)
96
+ }
97
+
87
98
  }
88
99
  if (!orchestrator) {
89
100
  logger.error('No cyk server is defined in current folder ' + process.cwd())
@@ -100,12 +111,12 @@ async function startServer() {
100
111
  * @returns
101
112
  */
102
113
  async function serviceAvailable(service: string): Promise<boolean> {
103
-
114
+
104
115
  const descNodejs = await spawnCommandData('kubectl', ['describe', 'service', service])
105
116
  const lines = descNodejs.split('\n')
106
- for(const line of lines) {
117
+ for (const line of lines) {
107
118
  if (line.includes('Endpoints')) {
108
- return ! line.includes('<none>')
119
+ return !line.includes('<none>')
109
120
  }
110
121
  }
111
122
  return false
@@ -164,7 +175,7 @@ class StopCommand extends Command {
164
175
  */
165
176
  const program = new Command()
166
177
  program.name('cyk').description('cyklang CLI')
167
- .version('0.7.3')
178
+ .version('0.7.5')
168
179
  program.addCommand(new StartCommand('start'))
169
180
  program.addCommand(new StopCommand('stop'))
170
181
  program.addCommand(new InstallCommand('install'))