@cyklang/cli 0.16.0 → 0.17.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/build/RunCommand.js +2 -0
- package/build/TestCommand.js +2 -0
- package/build/console.d.ts +16 -2
- package/build/console.js +70 -1
- package/build/index.js +1 -1
- package/package.json +2 -2
- package/src/RunCommand.ts +2 -1
- package/src/TestCommand.ts +3 -1
- package/src/console.ts +27 -1
- package/src/index.ts +1 -1
- package/t37.xlsx +0 -0
- package/test/t37.xml +16 -2
package/build/RunCommand.js
CHANGED
|
@@ -85,6 +85,8 @@ 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"));
|
|
89
|
+
structure.scope.addFunction('read_file', console_1.read_file);
|
|
88
90
|
await (0, core_1.loadLanguageModule)(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG]);
|
|
89
91
|
let script = new core_1.Script(structure.scope, xmlfilename, xml.toString(), dbManager);
|
|
90
92
|
await script.parseInstructions();
|
package/build/TestCommand.js
CHANGED
|
@@ -86,6 +86,8 @@ 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"));
|
|
90
|
+
structure.scope.addFunction('read_file', console_1.read_file);
|
|
89
91
|
await (0, core_1.loadLanguageModule)(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG]);
|
|
90
92
|
let script = new core_1.Script(structure.scope, xmlfilename, xml.toString(), dbManager);
|
|
91
93
|
await script.parseInstructions();
|
package/build/console.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { XmlError } from '@cyklang/core';
|
|
1
|
+
import { Variables, XmlError } from '@cyklang/core';
|
|
2
2
|
import { Instruction, InstructionType, Tag } from '@cyklang/core';
|
|
3
|
-
import { Scope } from '@cyklang/core';
|
|
3
|
+
import { Data, Scope } from '@cyklang/core';
|
|
4
4
|
export declare function errorconsole(xmlError: XmlError): void;
|
|
5
5
|
export declare class InputInstructionType extends InstructionType {
|
|
6
6
|
constructor();
|
|
@@ -11,3 +11,17 @@ 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
|
+
* @param params
|
|
17
|
+
* @param callerScope
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function read_file(params: Variables, callerScope: Scope): Promise<Data | undefined>;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
*/
|
|
24
|
+
export declare class WriteFileInstructionType extends InstructionType {
|
|
25
|
+
constructor(name: string);
|
|
26
|
+
parseInstruction(tag: Tag, scope: Scope): Promise<Instruction>;
|
|
27
|
+
}
|
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.read_file = 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,72 @@ class PrintInstruction extends core_2.Instruction {
|
|
|
112
112
|
dump() {
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
*
|
|
117
|
+
* @param params
|
|
118
|
+
* @param callerScope
|
|
119
|
+
* @returns
|
|
120
|
+
*/
|
|
121
|
+
async function read_file(params, callerScope) {
|
|
122
|
+
try {
|
|
123
|
+
let result = callerScope.structure.undefinedData;
|
|
124
|
+
if (params.length() === 0)
|
|
125
|
+
throw 'needs filename to read';
|
|
126
|
+
const param1 = params.at(0);
|
|
127
|
+
if (param1 === undefined)
|
|
128
|
+
throw 'filename is undefined';
|
|
129
|
+
const pathname = param1.variable.getString();
|
|
130
|
+
if (pathname === undefined)
|
|
131
|
+
throw 'pathname is undefined';
|
|
132
|
+
const buffer = fs.readFileSync(pathname);
|
|
133
|
+
const bufferData = new core_1.BufferData(callerScope.structure.bufferDataType);
|
|
134
|
+
bufferData.buffer = buffer;
|
|
135
|
+
result = bufferData;
|
|
136
|
+
return result;
|
|
137
|
+
}
|
|
138
|
+
catch (err) {
|
|
139
|
+
throw `read_file() error : ${err}`;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
exports.read_file = read_file;
|
|
143
|
+
/**
|
|
144
|
+
*
|
|
145
|
+
*/
|
|
146
|
+
class WriteFileInstructionType extends core_2.InstructionType {
|
|
147
|
+
constructor(name) {
|
|
148
|
+
super(name);
|
|
149
|
+
}
|
|
150
|
+
async parseInstruction(tag, scope) {
|
|
151
|
+
return new WriteFileInstruction(tag);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.WriteFileInstructionType = WriteFileInstructionType;
|
|
155
|
+
/**
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
class WriteFileInstruction extends core_2.Instruction {
|
|
159
|
+
constructor(tag) {
|
|
160
|
+
super(tag);
|
|
161
|
+
}
|
|
162
|
+
async execute(scope) {
|
|
163
|
+
try {
|
|
164
|
+
const objectDataType = scope.structure.objectDataType;
|
|
165
|
+
const objParams = await objectDataType.parseData(this.tag, scope);
|
|
166
|
+
const pathname = objParams.variables.getString("pathname");
|
|
167
|
+
if (!pathname)
|
|
168
|
+
throw `pathname parameter is missing`;
|
|
169
|
+
const content = objParams.variables.getData("content");
|
|
170
|
+
if (!content)
|
|
171
|
+
throw `content parameter is missing`;
|
|
172
|
+
if (!content.buffer)
|
|
173
|
+
throw `content is empty`;
|
|
174
|
+
fs.writeFileSync(pathname, content.buffer);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
catch (err) {
|
|
178
|
+
if (err instanceof core_1.XmlError)
|
|
179
|
+
throw err;
|
|
180
|
+
throw new core_1.XmlError(`${this.tagName}() error : ${err}`, this.tag);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
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.
|
|
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.
|
|
3
|
+
"version": "0.17.0",
|
|
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.
|
|
22
|
+
"@cyklang/core": "^0.36.0",
|
|
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, WriteFileInstructionType } from "./console"
|
|
3
|
+
import { errorconsole, PrintInstructionType, read_file, WriteFileInstructionType } from "./console"
|
|
4
4
|
import loglevel from 'loglevel'
|
|
5
5
|
import { NodeCrypto } from "./NodeCrypto"
|
|
6
6
|
import { Cmd } from "./Cmd"
|
|
@@ -61,6 +61,7 @@ export async function runFile(filename: string): Promise<void> {
|
|
|
61
61
|
const dbManager = new DBManager(structure.scope, dbRemote)
|
|
62
62
|
await dbManager.initialize()
|
|
63
63
|
structure.scope.addInstructionType(new WriteFileInstructionType("write_file"))
|
|
64
|
+
structure.scope.addFunction('read_file', read_file)
|
|
64
65
|
|
|
65
66
|
await loadLanguageModule(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG])
|
|
66
67
|
|
package/src/TestCommand.ts
CHANGED
|
@@ -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, WriteFileInstructionType } from "./console"
|
|
3
|
+
import { errorconsole, PrintInstructionType, read_file, WriteFileInstructionType } from "./console"
|
|
4
4
|
import loglevel from 'loglevel'
|
|
5
5
|
import { NodeCrypto } from "./NodeCrypto"
|
|
6
6
|
import { Cmd } from "./Cmd"
|
|
@@ -65,6 +65,8 @@ async function testfile(filename: string): Promise<boolean> {
|
|
|
65
65
|
await dbManager.initialize()
|
|
66
66
|
structure.scope.addInstructionType(new PrintInstructionType(logfilename))
|
|
67
67
|
structure.scope.addInstructionType(new WriteFileInstructionType("write_file"))
|
|
68
|
+
structure.scope.addFunction('read_file', read_file)
|
|
69
|
+
|
|
68
70
|
|
|
69
71
|
await loadLanguageModule(structure.scope, dbManager, '', [login.content.user_lang, process.env.LANG])
|
|
70
72
|
|
package/src/console.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BufferData, Jump, ObjectData, XmlError } from '@cyklang/core'
|
|
1
|
+
import { BufferData, Jump, ObjectData, Variables, 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'
|
|
@@ -97,6 +97,32 @@ class PrintInstruction extends Instruction {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/**
|
|
101
|
+
*
|
|
102
|
+
* @param params
|
|
103
|
+
* @param callerScope
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
export async function read_file(params: Variables, callerScope: Scope): Promise<Data | undefined> {
|
|
107
|
+
try {
|
|
108
|
+
let result = callerScope.structure.undefinedData
|
|
109
|
+
if (params.length() === 0) throw 'needs filename to read'
|
|
110
|
+
const param1 = params.at(0)
|
|
111
|
+
if (param1 === undefined) throw 'filename is undefined'
|
|
112
|
+
const pathname = param1.variable.getString()
|
|
113
|
+
if (pathname === undefined) throw 'pathname is undefined'
|
|
114
|
+
const buffer = fs.readFileSync(pathname)
|
|
115
|
+
const bufferData = new BufferData(callerScope.structure.bufferDataType)
|
|
116
|
+
bufferData.buffer = buffer
|
|
117
|
+
result = bufferData
|
|
118
|
+
|
|
119
|
+
return result
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
throw `read_file() error : ${err}`
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
100
126
|
/**
|
|
101
127
|
*
|
|
102
128
|
*/
|
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.
|
|
179
|
+
.version('0.17.0')
|
|
180
180
|
program.addCommand(new StartCommand('start'))
|
|
181
181
|
program.addCommand(new StopCommand('stop'))
|
|
182
182
|
program.addCommand(new InstallCommand('install'))
|
package/t37.xlsx
CHANGED
|
Binary file
|
package/test/t37.xml
CHANGED
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
<object name="list">
|
|
4
4
|
<object>
|
|
5
5
|
<string name="Nom">"CHANE"</string>
|
|
6
|
-
<string name="
|
|
6
|
+
<string name="Prenom">"Phil"</string>
|
|
7
|
+
<number name="Salaire">15250.34</number>
|
|
7
8
|
</object>
|
|
8
9
|
<object>
|
|
9
10
|
<string name="Nom">"LAU"</string>
|
|
10
|
-
<string name="
|
|
11
|
+
<string name="Prenom">"érika"</string>
|
|
12
|
+
<number name="Salaire">0</number>
|
|
11
13
|
</object>
|
|
12
14
|
</object>
|
|
13
15
|
|
|
@@ -16,4 +18,16 @@
|
|
|
16
18
|
<buffer name="content">xlsx(list)</buffer>
|
|
17
19
|
</write_file>
|
|
18
20
|
|
|
21
|
+
|
|
22
|
+
<buffer name="bExcel">read_file("t37.xlsx")</buffer>
|
|
23
|
+
<type name="columns">
|
|
24
|
+
<string name="Nom"/>
|
|
25
|
+
<string name="Prenom"/>
|
|
26
|
+
<number name="Salaire"/>
|
|
27
|
+
</type>
|
|
28
|
+
|
|
29
|
+
<object name="result">parsexlsx(bExcel, columns)</object>
|
|
30
|
+
|
|
31
|
+
<print>format("result = {0}", result)</print>
|
|
32
|
+
|
|
19
33
|
</module>
|