@cyklang/cli 0.15.23 → 0.16.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.
@@ -85,6 +85,7 @@ async function runFile(filename) {
85
85
  const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
86
86
  const dbManager = new core_1.DBManager(structure.scope, dbRemote);
87
87
  await dbManager.initialize();
88
+ structure.scope.addInstructionType(new console_1.WriteFileInstructionType("write_file"));
88
89
  await (0, core_1.loadLanguageModule)(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG]);
89
90
  let script = new core_1.Script(structure.scope, xmlfilename, xml.toString(), dbManager);
90
91
  await script.parseInstructions();
@@ -86,6 +86,7 @@ async function testfile(filename) {
86
86
  const dbManager = new core_1.DBManager(structure.scope, dbRemote);
87
87
  await dbManager.initialize();
88
88
  structure.scope.addInstructionType(new console_1.PrintInstructionType(logfilename));
89
+ structure.scope.addInstructionType(new console_1.WriteFileInstructionType("write_file"));
89
90
  await (0, core_1.loadLanguageModule)(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG]);
90
91
  let script = new core_1.Script(structure.scope, xmlfilename, xml.toString(), dbManager);
91
92
  await script.parseInstructions();
@@ -11,3 +11,10 @@ export declare class PrintInstructionType extends InstructionType {
11
11
  constructor(logfilename: string);
12
12
  parseInstruction(tag: Tag, scope: Scope): Promise<Instruction>;
13
13
  }
14
+ /**
15
+ *
16
+ */
17
+ export declare class WriteFileInstructionType extends InstructionType {
18
+ constructor(name: string);
19
+ parseInstruction(tag: Tag, scope: Scope): Promise<Instruction>;
20
+ }
package/build/console.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.PrintInstructionType = exports.InputInstructionType = exports.errorconsole = void 0;
26
+ exports.WriteFileInstructionType = exports.PrintInstructionType = exports.InputInstructionType = exports.errorconsole = void 0;
27
27
  const core_1 = require("@cyklang/core");
28
28
  const fs = __importStar(require("fs"));
29
29
  const core_2 = require("@cyklang/core");
@@ -112,3 +112,44 @@ class PrintInstruction extends core_2.Instruction {
112
112
  dump() {
113
113
  }
114
114
  }
115
+ /**
116
+ *
117
+ */
118
+ class WriteFileInstructionType extends core_2.InstructionType {
119
+ constructor(name) {
120
+ super(name);
121
+ }
122
+ async parseInstruction(tag, scope) {
123
+ return new WriteFileInstruction(tag);
124
+ }
125
+ }
126
+ exports.WriteFileInstructionType = WriteFileInstructionType;
127
+ /**
128
+ *
129
+ */
130
+ class WriteFileInstruction extends core_2.Instruction {
131
+ constructor(tag) {
132
+ super(tag);
133
+ }
134
+ async execute(scope) {
135
+ try {
136
+ const objectDataType = scope.structure.objectDataType;
137
+ const objParams = await objectDataType.parseData(this.tag, scope);
138
+ const pathname = objParams.variables.getString("pathname");
139
+ if (!pathname)
140
+ throw `pathname parameter is missing`;
141
+ const content = objParams.variables.getData("content");
142
+ if (!content)
143
+ throw `content parameter is missing`;
144
+ if (!content.buffer)
145
+ throw `content is empty`;
146
+ fs.writeFileSync(pathname, content.buffer);
147
+ return;
148
+ }
149
+ catch (err) {
150
+ if (err instanceof core_1.XmlError)
151
+ throw err;
152
+ throw new core_1.XmlError(`${this.tagName}() error : ${err}`, this.tag);
153
+ }
154
+ }
155
+ }
package/build/index.js CHANGED
@@ -182,7 +182,7 @@ class StopCommand extends commander_1.Command {
182
182
  */
183
183
  const program = new commander_1.Command();
184
184
  program.name('cyk').description('cyklang CLI')
185
- .version('0.15.23');
185
+ .version('0.16.1');
186
186
  program.addCommand(new StartCommand('start'));
187
187
  program.addCommand(new StopCommand('stop'));
188
188
  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.15.23",
3
+ "version": "0.16.1",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -19,7 +19,7 @@
19
19
  "author": "",
20
20
  "license": "ISC",
21
21
  "dependencies": {
22
- "@cyklang/core": "^0.34.0",
22
+ "@cyklang/core": "^0.35.1",
23
23
  "commander": "^9.4.0",
24
24
  "dotenv": "^16.0.1",
25
25
  "form-data": "^4.0.0",
package/src/RunCommand.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Structure, Script, XmlError, DBRemote, DBManager, ModuleInstruction, parseXML, MapData, loadLanguageModule } from "@cyklang/core"
2
2
  import * as fs from "fs"
3
- import { errorconsole, PrintInstructionType } from "./console"
3
+ import { errorconsole, PrintInstructionType, WriteFileInstructionType } from "./console"
4
4
  import loglevel from 'loglevel'
5
5
  import { NodeCrypto } from "./NodeCrypto"
6
6
  import { Cmd } from "./Cmd"
@@ -60,6 +60,7 @@ export async function runFile(filename: string): Promise<void> {
60
60
  const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD)
61
61
  const dbManager = new DBManager(structure.scope, dbRemote)
62
62
  await dbManager.initialize()
63
+ structure.scope.addInstructionType(new WriteFileInstructionType("write_file"))
63
64
 
64
65
  await loadLanguageModule(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG])
65
66
 
@@ -1,6 +1,6 @@
1
1
  import { Structure, Script, XmlError, DBRemote, DBManager, MapData, ModuleInstruction, parseXML, loadLanguageModule } from "@cyklang/core"
2
2
  import * as fs from "fs"
3
- import { errorconsole, PrintInstructionType } from "./console"
3
+ import { errorconsole, PrintInstructionType, WriteFileInstructionType } from "./console"
4
4
  import loglevel from 'loglevel'
5
5
  import { NodeCrypto } from "./NodeCrypto"
6
6
  import { Cmd } from "./Cmd"
@@ -64,6 +64,7 @@ async function testfile(filename: string): Promise<boolean> {
64
64
  const dbManager = new DBManager(structure.scope, dbRemote)
65
65
  await dbManager.initialize()
66
66
  structure.scope.addInstructionType(new PrintInstructionType(logfilename))
67
+ structure.scope.addInstructionType(new WriteFileInstructionType("write_file"))
67
68
 
68
69
  await loadLanguageModule(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG])
69
70
 
package/src/console.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { XmlError } from '@cyklang/core'
1
+ import { BufferData, Jump, ObjectData, XmlError } from '@cyklang/core'
2
2
  import * as fs from "fs"
3
3
  import { Instruction, InstructionType, Tag } from '@cyklang/core'
4
4
  import { Data, Scope } from '@cyklang/core'
@@ -96,3 +96,50 @@ class PrintInstruction extends Instruction {
96
96
 
97
97
  }
98
98
  }
99
+
100
+ /**
101
+ *
102
+ */
103
+ export class WriteFileInstructionType extends InstructionType {
104
+
105
+ constructor(name: string) {
106
+ super(name)
107
+ }
108
+
109
+ async parseInstruction(tag: Tag, scope: Scope): Promise<Instruction> {
110
+ return new WriteFileInstruction(tag)
111
+ }
112
+
113
+ }
114
+
115
+ /**
116
+ *
117
+ */
118
+ class WriteFileInstruction extends Instruction {
119
+
120
+ constructor(tag: Tag) {
121
+ super(tag)
122
+ }
123
+
124
+ async execute(scope: Scope): Promise<Jump> {
125
+
126
+ try {
127
+ const objectDataType = scope.structure.objectDataType
128
+ const objParams = await objectDataType.parseData(this.tag, scope) as ObjectData
129
+ const pathname = objParams.variables.getString("pathname")
130
+ if (! pathname) throw `pathname parameter is missing`
131
+ const content = objParams.variables.getData("content") as BufferData
132
+ if (! content) throw `content parameter is missing`
133
+ if (! content.buffer) throw `content is empty`
134
+
135
+ fs.writeFileSync(pathname, content.buffer)
136
+
137
+ return
138
+ }
139
+ catch (err) {
140
+ if (err instanceof XmlError) throw err
141
+ throw new XmlError(`${this.tagName}() error : ${err}`, this.tag)
142
+ }
143
+ }
144
+
145
+ }
package/src/index.ts CHANGED
@@ -176,7 +176,7 @@ class StopCommand extends Command {
176
176
  */
177
177
  const program = new Command()
178
178
  program.name('cyk').description('cyklang CLI')
179
- .version('0.15.23')
179
+ .version('0.16.1')
180
180
  program.addCommand(new StartCommand('start'))
181
181
  program.addCommand(new StopCommand('stop'))
182
182
  program.addCommand(new InstallCommand('install'))
package/t37.xlsx ADDED
Binary file
package/test/t37.xml ADDED
@@ -0,0 +1,19 @@
1
+ <?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" ?>
2
+ <module>
3
+ <object name="list">
4
+ <object>
5
+ <string name="Nom">"CHANE"</string>
6
+ <string name="Prénom">"Phil"</string>
7
+ </object>
8
+ <object>
9
+ <string name="Nom">"LAU"</string>
10
+ <string name="Prénom">"érika"</string>
11
+ </object>
12
+ </object>
13
+
14
+ <write_file>
15
+ <string name="pathname">"t37.xlsx"</string>
16
+ <buffer name="content">xlsx(list)</buffer>
17
+ </write_file>
18
+
19
+ </module>