@cyklang/cli 0.5.0 → 0.5.1

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
@@ -24,7 +24,7 @@ class Cmd extends commander_1.Command {
24
24
  const structure = new core_1.Structure();
25
25
  if (process.env.DBREMOTE_URL === undefined)
26
26
  throw 'DBREMOTE_URL undefined';
27
- logger.debug('Cmd.DBREMOTE_URL ' + process.env.DBREMOTE_URL);
27
+ logger.info('Cyk server: ' + process.env.DBREMOTE_URL);
28
28
  const nodeCrypto = new NodeCrypto_1.NodeCrypto();
29
29
  this.dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
30
30
  const login = await this.dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
@@ -0,0 +1,10 @@
1
+ import { Cmd } from "./Cmd";
2
+ export declare class InstallCommand extends Cmd {
3
+ constructor(name: string);
4
+ install(node_package: string, options: any): Promise<void>;
5
+ /**
6
+ * method verifyPackageJson
7
+ * @param node_package
8
+ */
9
+ verifyPackageJson(node_package: string): Promise<void>;
10
+ }
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.InstallCommand = void 0;
30
+ const Cmd_1 = require("./Cmd");
31
+ const fs = __importStar(require("fs"));
32
+ const path = __importStar(require("path"));
33
+ const loglevel_1 = __importDefault(require("loglevel"));
34
+ const ModuleCommand_1 = require("./ModuleCommand");
35
+ const logger = loglevel_1.default.getLogger('InstallCommand.ts');
36
+ logger.setLevel('debug');
37
+ class InstallCommand extends Cmd_1.Cmd {
38
+ constructor(name) {
39
+ super(name);
40
+ this.description('upload Cyk modules to a Cyk server from a Node package downloaded by "npm install" ')
41
+ .argument('<node_package>', 'Node Package installed as dependency')
42
+ .action(async (node_package, options) => {
43
+ await this.install(node_package, options);
44
+ });
45
+ }
46
+ async install(node_package, options) {
47
+ try {
48
+ await this.prologue(options);
49
+ if (this.dbManager === undefined)
50
+ throw 'dbManager undefined';
51
+ await this.verifyPackageJson(node_package);
52
+ const xmlFolder = path.join('node_modules', node_package, 'xml');
53
+ if (!fs.existsSync(xmlFolder) || !fs.statSync(xmlFolder).isDirectory()) {
54
+ throw 'xml folder not found ( ' + xmlFolder + ' )';
55
+ }
56
+ const files = fs.readdirSync(xmlFolder);
57
+ for (let ind = 0; ind < files.length; ind++) {
58
+ const file = files[ind];
59
+ await (0, ModuleCommand_1.uploadModule)(path.join(xmlFolder, file), this.dbManager);
60
+ }
61
+ }
62
+ catch (err) {
63
+ logger.error(err);
64
+ }
65
+ }
66
+ /**
67
+ * method verifyPackageJson
68
+ * @param node_package
69
+ */
70
+ async verifyPackageJson(node_package) {
71
+ let packageJson;
72
+ try {
73
+ // Lecture du contenu du fichier package.json en tant que chaîne de caractères
74
+ const packageJsonContent = fs.readFileSync('package.json', 'utf8');
75
+ // Analyse du contenu en tant qu'objet JSON
76
+ packageJson = JSON.parse(packageJsonContent);
77
+ }
78
+ catch (error) {
79
+ console.error('Error loading package.json file :', error);
80
+ throw error;
81
+ }
82
+ if (!packageJson.dependencies || !packageJson.dependencies[node_package]) {
83
+ throw node_package + ' not installed in the current project. Install it first with "npm install"';
84
+ }
85
+ }
86
+ }
87
+ exports.InstallCommand = InstallCommand;
@@ -1,5 +1,12 @@
1
1
  #!/usr/bin/env ts-node
2
+ import { DBManager } from "@cyklang/core";
2
3
  import { Command } from 'commander';
3
4
  export declare class ModuleCommand extends Command {
4
5
  constructor(name: string);
5
6
  }
7
+ /**
8
+ *
9
+ * @param file
10
+ * @param dbManager
11
+ */
12
+ export declare function uploadModule(file: string, dbManager: DBManager): Promise<void>;
@@ -27,7 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  return (mod && mod.__esModule) ? mod : { "default": mod };
28
28
  };
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.ModuleCommand = void 0;
30
+ exports.uploadModule = exports.ModuleCommand = void 0;
31
31
  const core_1 = require("@cyklang/core");
32
32
  const fs = __importStar(require("fs"));
33
33
  const loglevel_1 = __importDefault(require("loglevel"));
@@ -135,30 +135,7 @@ class ModuleU extends Cmd_1.Cmd {
135
135
  else {
136
136
  for (let ind = 0; ind < files.length; ind++) {
137
137
  const file = files[ind];
138
- const dbname = getModuleDBName(file);
139
- const source = fs.readFileSync(file).toString();
140
- const tag = (0, core_1.parseXML)(dbname, source);
141
- const dbModuleExist = await this.dbManager.dbModuleExist(dbname);
142
- if (dbModuleExist === undefined) {
143
- // insert
144
- const dbModule = new core_1.DBModule();
145
- dbModule.source = source;
146
- dbModule.dbname = dbname;
147
- dbModule.access = tag.attributes.ACCESS;
148
- dbModule.description = tag.attributes.DESCRIPTION;
149
- logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description);
150
- const id = await this.dbManager.dbModuleInsert(dbModule);
151
- logger.info('module ' + dbname + ' added with ID ' + id);
152
- }
153
- else {
154
- // update
155
- dbModuleExist.source = source;
156
- dbModuleExist.access = tag.attributes.ACCESS;
157
- dbModuleExist.description = tag.attributes.DESCRIPTION;
158
- logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description);
159
- await this.dbManager.dbModuleUpdate(dbModuleExist);
160
- logger.info('module ' + dbname + ' updated');
161
- }
138
+ await uploadModule(file, this.dbManager);
162
139
  }
163
140
  }
164
141
  }
@@ -167,6 +144,38 @@ class ModuleU extends Cmd_1.Cmd {
167
144
  }
168
145
  }
169
146
  }
147
+ /**
148
+ *
149
+ * @param file
150
+ * @param dbManager
151
+ */
152
+ async function uploadModule(file, dbManager) {
153
+ const dbname = getModuleDBName(file);
154
+ const source = fs.readFileSync(file).toString();
155
+ const tag = (0, core_1.parseXML)(dbname, source);
156
+ const dbModuleExist = await dbManager.dbModuleExist(dbname);
157
+ if (dbModuleExist === undefined) {
158
+ // insert
159
+ const dbModule = new core_1.DBModule();
160
+ dbModule.source = source;
161
+ dbModule.dbname = dbname;
162
+ dbModule.access = tag.attributes.ACCESS;
163
+ dbModule.description = tag.attributes.DESCRIPTION;
164
+ // logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description)
165
+ const id = await dbManager.dbModuleInsert(dbModule);
166
+ logger.info('module ' + dbname + ' added with ID ' + id);
167
+ }
168
+ else {
169
+ // update
170
+ dbModuleExist.source = source;
171
+ dbModuleExist.access = tag.attributes.ACCESS;
172
+ dbModuleExist.description = tag.attributes.DESCRIPTION;
173
+ // logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description)
174
+ await dbManager.dbModuleUpdate(dbModuleExist);
175
+ logger.info('module ' + dbname + ' updated');
176
+ }
177
+ }
178
+ exports.uploadModule = uploadModule;
170
179
  class ModuleDownload extends Cmd_1.Cmd {
171
180
  constructor(name, description) {
172
181
  super(name);
@@ -1,5 +1,5 @@
1
1
  import { Cmd } from "./Cmd";
2
2
  export declare class OpenCommand extends Cmd {
3
- constructor();
3
+ constructor(name: string);
4
4
  openBrowser(module: string, options: any): Promise<void>;
5
5
  }
@@ -9,8 +9,8 @@ const loglevel_1 = __importDefault(require("loglevel"));
9
9
  const logger = loglevel_1.default.getLogger('OpenCommand.ts');
10
10
  logger.setLevel('debug');
11
11
  class OpenCommand extends Cmd_1.Cmd {
12
- constructor() {
13
- super('open');
12
+ constructor(name) {
13
+ super(name);
14
14
  this.description('open browser').version('0.1')
15
15
  .argument('<module>', 'module to execute')
16
16
  .action(async (module, options) => {
@@ -1,5 +1,5 @@
1
1
  import { Cmd } from "./Cmd";
2
2
  export declare class RunCommand extends Cmd {
3
- constructor();
3
+ constructor(name: string);
4
4
  runFiles(files: string[], options: any): Promise<void>;
5
5
  }
@@ -36,8 +36,8 @@ const Cmd_1 = require("./Cmd");
36
36
  loglevel_1.default.setLevel('debug');
37
37
  const logger = loglevel_1.default.getLogger('RunCommand.ts');
38
38
  class RunCommand extends Cmd_1.Cmd {
39
- constructor() {
40
- super('run');
39
+ constructor(name) {
40
+ super(name);
41
41
  this.description('run module').version('0.2')
42
42
  .argument('<files...>', 'local module file(s) to run')
43
43
  .action(async (files, options) => {
package/build/index.js CHANGED
@@ -12,7 +12,7 @@ const QueryCommand_1 = require("./QueryCommand");
12
12
  const TableCommand_1 = require("./TableCommand");
13
13
  const TestCommand_1 = require("./TestCommand");
14
14
  const RunCommand_1 = require("./RunCommand");
15
- const InitCommand_1 = require("./InitCommand");
15
+ const InstallCommand_1 = require("./InstallCommand");
16
16
  const AssetCommand_1 = require("./AssetCommand");
17
17
  const OpenCommand_1 = require("./OpenCommand");
18
18
  const logger = loglevel_1.default.getLogger("index.ts");
@@ -20,7 +20,8 @@ logger.setLevel("debug");
20
20
  const program = new commander_1.Command();
21
21
  program.name('cyk').description('cyklang CLI')
22
22
  .version('0.2');
23
- program.addCommand(new InitCommand_1.InitCommand('init'));
23
+ program.addCommand(new InstallCommand_1.InstallCommand('install'));
24
+ program.addCommand(new InstallCommand_1.InstallCommand('i'));
24
25
  program.addCommand(new AssetCommand_1.AssetCommand('asset', 'manage assets'));
25
26
  program.addCommand(new AssetCommand_1.AssetCommand('a', 'manage assets'));
26
27
  program.addCommand(new ModuleCommand_1.ModuleCommand('module'));
@@ -32,6 +33,8 @@ program.addCommand(new QueryCommand_1.QueryCommand('q'));
32
33
  program.addCommand(new TableCommand_1.TableCommand('table'));
33
34
  program.addCommand(new TableCommand_1.TableCommand('t'));
34
35
  program.addCommand(new TestCommand_1.TestCommand());
35
- program.addCommand(new RunCommand_1.RunCommand());
36
- program.addCommand(new OpenCommand_1.OpenCommand());
36
+ program.addCommand(new RunCommand_1.RunCommand('run'));
37
+ program.addCommand(new RunCommand_1.RunCommand('r'));
38
+ program.addCommand(new OpenCommand_1.OpenCommand('open'));
39
+ program.addCommand(new OpenCommand_1.OpenCommand('o'));
37
40
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
package/src/Cmd.ts CHANGED
@@ -23,7 +23,7 @@ export class Cmd extends Command {
23
23
 
24
24
  const structure = new Structure()
25
25
  if (process.env.DBREMOTE_URL === undefined) throw 'DBREMOTE_URL undefined'
26
- logger.debug('Cmd.DBREMOTE_URL ' + process.env.DBREMOTE_URL)
26
+ logger.info('Cyk server: ' + process.env.DBREMOTE_URL)
27
27
  const nodeCrypto = new NodeCrypto()
28
28
  this.dbRemote = new DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto)
29
29
  const login = await this.dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD)
@@ -0,0 +1,71 @@
1
+ import { Cmd } from "./Cmd";
2
+ import * as fs from "fs"
3
+ import * as path from "path"
4
+
5
+ import loglevel from 'loglevel'
6
+ import { uploadModule } from "./ModuleCommand";
7
+ const logger = loglevel.getLogger('InstallCommand.ts')
8
+ logger.setLevel('debug')
9
+
10
+ export class InstallCommand extends Cmd {
11
+ constructor(name: string) {
12
+ super(name)
13
+ this.description('upload Cyk modules to a Cyk server from a Node package downloaded by "npm install" ')
14
+ .argument('<node_package>', 'Node Package installed as dependency')
15
+ .action(async (node_package: any, options: any) => {
16
+ await this.install(node_package, options)
17
+ })
18
+ }
19
+
20
+ async install(node_package: string, options: any) {
21
+ try {
22
+ await this.prologue(options)
23
+ if (this.dbManager === undefined) throw 'dbManager undefined'
24
+ await this.verifyPackageJson(node_package)
25
+
26
+ const xmlFolder = path.join('node_modules', node_package, 'xml')
27
+ if (!fs.existsSync(xmlFolder) || !fs.statSync(xmlFolder).isDirectory()) {
28
+ throw 'xml folder not found ( ' + xmlFolder + ' )'
29
+ }
30
+
31
+ const files = fs.readdirSync(xmlFolder)
32
+ for (let ind = 0; ind < files.length; ind++) {
33
+ const file = files[ind]
34
+ await uploadModule(path.join(xmlFolder, file), this.dbManager)
35
+ }
36
+ }
37
+ catch (err) {
38
+ logger.error(err)
39
+ }
40
+ }
41
+
42
+ /**
43
+ * method verifyPackageJson
44
+ * @param node_package
45
+ */
46
+ async verifyPackageJson(node_package: string) {
47
+
48
+ let packageJson: any
49
+
50
+ try {
51
+ // Lecture du contenu du fichier package.json en tant que chaîne de caractères
52
+ const packageJsonContent = fs.readFileSync('package.json', 'utf8');
53
+
54
+ // Analyse du contenu en tant qu'objet JSON
55
+ packageJson = JSON.parse(packageJsonContent);
56
+
57
+ } catch (error) {
58
+ console.error('Error loading package.json file :', error);
59
+ throw error
60
+ }
61
+
62
+ if (!packageJson.dependencies || !packageJson.dependencies[node_package]) {
63
+ throw node_package + ' not installed in the current project. Install it first with "npm install"'
64
+ }
65
+
66
+
67
+
68
+ }
69
+
70
+
71
+ }
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ts-node
2
- import { DBModule, parseXML } from "@cyklang/core"
2
+ import { DBManager, DBModule, parseXML } from "@cyklang/core"
3
3
  import * as fs from "fs"
4
4
  import loglevel from 'loglevel'
5
5
  import path from "path"
@@ -115,30 +115,7 @@ class ModuleU extends Cmd {
115
115
  else {
116
116
  for (let ind = 0; ind < files.length; ind++) {
117
117
  const file = files[ind]
118
- const dbname = getModuleDBName(file)
119
- const source = fs.readFileSync(file).toString()
120
- const tag = parseXML(dbname, source)
121
- const dbModuleExist = await this.dbManager.dbModuleExist(dbname)
122
- if (dbModuleExist === undefined) {
123
- // insert
124
- const dbModule = new DBModule()
125
- dbModule.source = source
126
- dbModule.dbname = dbname
127
- dbModule.access = tag.attributes.ACCESS
128
- dbModule.description = tag.attributes.DESCRIPTION
129
- logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description)
130
- const id = await this.dbManager.dbModuleInsert(dbModule)
131
- logger.info('module ' + dbname + ' added with ID ' + id)
132
- }
133
- else {
134
- // update
135
- dbModuleExist.source = source
136
- dbModuleExist.access = tag.attributes.ACCESS
137
- dbModuleExist.description = tag.attributes.DESCRIPTION
138
- logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description)
139
- await this.dbManager.dbModuleUpdate(dbModuleExist)
140
- logger.info('module ' + dbname + ' updated')
141
- }
118
+ await uploadModule(file, this.dbManager)
142
119
  }
143
120
  }
144
121
  }
@@ -148,6 +125,38 @@ class ModuleU extends Cmd {
148
125
  }
149
126
  }
150
127
 
128
+ /**
129
+ *
130
+ * @param file
131
+ * @param dbManager
132
+ */
133
+ export async function uploadModule(file: string, dbManager: DBManager) {
134
+ const dbname = getModuleDBName(file)
135
+ const source = fs.readFileSync(file).toString()
136
+ const tag = parseXML(dbname, source)
137
+ const dbModuleExist = await dbManager.dbModuleExist(dbname)
138
+ if (dbModuleExist === undefined) {
139
+ // insert
140
+ const dbModule = new DBModule()
141
+ dbModule.source = source
142
+ dbModule.dbname = dbname
143
+ dbModule.access = tag.attributes.ACCESS
144
+ dbModule.description = tag.attributes.DESCRIPTION
145
+ // logger.debug('module insert ' + dbname + ' access ' + dbModule.access + ' description ' + dbModule.description)
146
+ const id = await dbManager.dbModuleInsert(dbModule)
147
+ logger.info('module ' + dbname + ' added with ID ' + id)
148
+ }
149
+ else {
150
+ // update
151
+ dbModuleExist.source = source
152
+ dbModuleExist.access = tag.attributes.ACCESS
153
+ dbModuleExist.description = tag.attributes.DESCRIPTION
154
+ // logger.debug('module update ' + dbname + ' access ' + dbModuleExist.access + ' description ' + dbModuleExist.description)
155
+ await dbManager.dbModuleUpdate(dbModuleExist)
156
+ logger.info('module ' + dbname + ' updated')
157
+ }
158
+ }
159
+
151
160
  interface DownloadOptions {
152
161
  id: string | undefined
153
162
  env: string | undefined
@@ -5,8 +5,8 @@ const logger = loglevel.getLogger('OpenCommand.ts')
5
5
  logger.setLevel('debug')
6
6
 
7
7
  export class OpenCommand extends Cmd {
8
- constructor() {
9
- super('open')
8
+ constructor(name: string) {
9
+ super(name)
10
10
  this.description('open browser').version('0.1')
11
11
  .argument('<module>', 'module to execute')
12
12
  .action(async (module: any, options: any) => {
package/src/RunCommand.ts CHANGED
@@ -8,8 +8,8 @@ loglevel.setLevel('debug')
8
8
  const logger = loglevel.getLogger('RunCommand.ts');
9
9
 
10
10
  export class RunCommand extends Cmd {
11
- constructor() {
12
- super('run')
11
+ constructor(name: string) {
12
+ super(name)
13
13
  this.description('run module').version('0.2')
14
14
  .argument('<files...>', 'local module file(s) to run')
15
15
  .action(async (files: any, options: any) => {
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ import { QueryCommand } from './QueryCommand'
7
7
  import { TableCommand } from './TableCommand'
8
8
  import { TestCommand } from './TestCommand'
9
9
  import { RunCommand } from './RunCommand'
10
- import { InitCommand } from './InitCommand'
10
+ import { InstallCommand } from './InstallCommand'
11
11
  import { AssetCommand } from './AssetCommand'
12
12
  import { OpenCommand } from './OpenCommand'
13
13
  const logger = loglevel.getLogger("index.ts")
@@ -17,7 +17,8 @@ const program = new Command()
17
17
  program.name('cyk').description('cyklang CLI')
18
18
  .version('0.2')
19
19
 
20
- program.addCommand(new InitCommand('init'))
20
+ program.addCommand(new InstallCommand('install'))
21
+ program.addCommand(new InstallCommand('i'))
21
22
  program.addCommand(new AssetCommand('asset', 'manage assets'))
22
23
  program.addCommand(new AssetCommand('a', 'manage assets'))
23
24
  program.addCommand(new ModuleCommand('module'))
@@ -29,7 +30,9 @@ program.addCommand(new QueryCommand('q'))
29
30
  program.addCommand(new TableCommand('table'))
30
31
  program.addCommand(new TableCommand('t'))
31
32
  program.addCommand(new TestCommand())
32
- program.addCommand(new RunCommand())
33
- program.addCommand(new OpenCommand())
33
+ program.addCommand(new RunCommand('run'))
34
+ program.addCommand(new RunCommand('r'))
35
+ program.addCommand(new OpenCommand('open'))
36
+ program.addCommand(new OpenCommand('o'))
34
37
 
35
38
  program.parse()