antlink 0.0.5 → 0.0.6

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/README.md CHANGED
@@ -17,17 +17,17 @@ $ npm install antlink -g # 全局安装
17
17
 
18
18
 
19
19
  ```shell
20
- cd E:\antwork # 蚁巢位置路径
21
- ant init # 建巢(获得安全码)
22
- ant reset [code] # 重置蚁巢(需安全码)
20
+ $ cd E:\antwork # 蚁巢位置路径
21
+ $ ant nest # 建巢(获得安全码)
22
+ $ ant reset [scode] # 重置蚁巢(需安全码)
23
23
  ```
24
24
 
25
25
 
26
26
  ```shell
27
- ant nest start # 启动蚁巢
28
- ant nest stop # 停止蚁巢
29
- ant nest restart # 重启蚁巢
30
- ant nest status # 运行状态
27
+ $ ant link # 启动蚂蚁AI
28
+ $ ant unlink # 停止蚂蚁AI
29
+ $ ant relink # 重启蚂蚁AI
30
+ $ ant info # AI运行状态
31
31
  ```
32
32
 
33
33
 
package/bin/ant CHANGED
@@ -1,2 +1,14 @@
1
- #!/usr/bin/env node
2
- require('../lib/comm');
1
+ #!/usr/bin/env node
2
+ const arg = process.argv;
3
+ const {version} = require('../package.json');
4
+ const versionFunt = ()=>{console.log('v'+version);}
5
+ if (arg.length < 3) versionFunt();
6
+ if (arg.length > 2) {
7
+ const arr = require('../lib/json/cmds.json');
8
+ const name = arg[2].toLowerCase(); // 字母转小写
9
+ if(arr.includes(name)){
10
+ require('../lib/order/'+name)(arg.slice(3));
11
+ }else {
12
+ console.log(`Command '${name}' doesn't exist!`);
13
+ }
14
+ }
@@ -1 +1 @@
1
- ["init","nest","reset","info"]
1
+ ["nest","clear","link","unlink","relink","info","backup","use"]
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+ module.exports = {
3
+
4
+ }
@@ -0,0 +1,73 @@
1
+ 'use strict';
2
+ const oss = require('oss-sdk');
3
+ const log = require('../utils/logs');
4
+ module.exports = async(arg)=>{
5
+ // 判断蚁巢是否初始化
6
+ const name = 'nest.ant';
7
+ const urls = process.cwd();
8
+ const dir = oss.dir(urls);
9
+ const resDir = await dir.list();
10
+ if(arg[0]){
11
+ // 蚁巢命名空间名称
12
+ if(resDir){
13
+ if(resDir.length>0){
14
+ // 当前文件夹存在文件,需要清空
15
+ log.r('The current folder is not empty')
16
+ log.r('This folder must be cleared!')
17
+ }else{
18
+ // 开始初始化
19
+ const dirAdd = await dir.add('data','evolve','cache','logs');
20
+ if(dirAdd){
21
+ // 新建配置文件
22
+ let obj = {name:arg[0]};
23
+ const {version} = require('../../package.json');
24
+ obj.version = version;
25
+ obj.addTime = new Date().getTime();
26
+ const rrid = require('rrid');
27
+ obj.appId = rrid.key(32);
28
+ const scode = rrid.key(16);
29
+ obj.appKey = rrid.ekey(obj.appId+obj.addTime+scode,obj.appId+obj.addTime+scode);
30
+ const file = oss.file(process.cwd());
31
+ const fileAdd = await file.add(name,JSON.stringify(obj));
32
+ if(fileAdd){
33
+ // 初始化成功
34
+ log.g('Initialization successful!');
35
+ log.y('Security Code:'+scode);
36
+ log.y('Keep the security code safe')
37
+ }else{
38
+ log.r('Initialization failed!');
39
+ await dir.clear();
40
+ }
41
+ }else{
42
+ //初始化失败:无法创建目录
43
+ log.r('Initialization failed: unable to create directory')
44
+ }
45
+ }
46
+ }else{
47
+ log.r('Unknown error!');
48
+ }
49
+ }else{
50
+ if(resDir.length>0){
51
+ // 当前文件夹存在文件,判断是不是蚁巢
52
+ const file = oss.file(urls);
53
+ if(await file.ok(name)){
54
+ try{
55
+ let fileRes = await file.get(name);
56
+ fileRes = JSON.parse(fileRes);
57
+ log.y('Ant Nest Name: '+fileRes.name);
58
+ const format = require('../utils/format');
59
+ log.y('Creation Time: '+format(fileRes.addTime,'YYYY-MM-DD HH:mm'));
60
+ }catch(err){
61
+ log.r(err)
62
+ }
63
+ }else{
64
+ // 当前文件夹存在文件,需要清空
65
+ log.r('The current folder is not empty')
66
+ log.r('Cannot be used to raise ants!')
67
+ }
68
+ }else{
69
+ log.y('Ant nests need to be named!');
70
+ log.y('Command: $ ant nest [name]');
71
+ }
72
+ }
73
+ }
@@ -0,0 +1,4 @@
1
+ 'use strict';
2
+ module.exports = async(arg)=>{
3
+ console.log(arg);
4
+ }
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+ module.exports = (timestamp,formatStr = 'YYYY-MM-DD HH:mm:ss') => {
3
+ const date = new Date(timestamp);
4
+ const padZero = (num)=> {
5
+ return num.toString().padStart(2, '0');
6
+ }
7
+ const map = {
8
+ YYYY: date.getFullYear(),
9
+ MM: padZero(date.getMonth() + 1),
10
+ DD: padZero(date.getDate()),
11
+ HH: padZero(date.getHours()),
12
+ mm: padZero(date.getMinutes()),
13
+ ss: padZero(date.getSeconds())
14
+ };
15
+ return formatStr.replace(/YYYY|MM|DD|HH|mm|ss/g, matched => map[matched]);
16
+ }
@@ -11,12 +11,12 @@ module.exports = async(scode)=>{
11
11
  if(scode) {
12
12
  // 验证安全码
13
13
  const file = oss.file(process.cwd());
14
- let conf = await file.get('config.ant');
14
+ let conf = await file.get('nest.ant');
15
15
  if(conf){
16
16
  try {
17
17
  conf = JSON.parse(conf);
18
18
  const rrid = require('rrid');
19
- const key = rrid.ekey(conf.appId+conf.initTime+scode,conf.appId+conf.initTime+scode);
19
+ const key = rrid.ekey(conf.appId+conf.addTime+scode,conf.appId+conf.addTime+scode);
20
20
  if(key===conf.appKey){
21
21
  // 验证码通过
22
22
  ok = conf;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antlink",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "Ant Nest AI Framework.",
5
5
  "main": "index.js",
6
6
  "author": "weduu",
@@ -21,7 +21,7 @@
21
21
  "README.md"
22
22
  ],
23
23
  "dependencies": {
24
- "oss-sdk": "^1.0.5",
24
+ "oss-sdk": "^1.0.6",
25
25
  "rrid": "^1.0.7"
26
26
  }
27
27
  }
package/bin/plain.md DELETED
@@ -1,29 +0,0 @@
1
- AntLink
2
- ├── bin
3
- │ └── ant
4
- ├── lib
5
- │ ├── ants
6
- │ │ ├── models
7
- │ │ ├── plugins
8
- │ │ ├── skills
9
- │ │ └── tools
10
- │ ├── json
11
- │ │ └── cmds.json
12
- │ ├── order
13
- │ │ ├── nest
14
- │ │ │ └── index.js
15
- │ │ ├── init.js
16
- │ │ └── reset.js
17
- │ ├── utils
18
- │ │ ├── input.js
19
- │ │ ├── logs.js
20
- │ │ ├── plain.js
21
- │ │ └── scode.js
22
- │ ├── web
23
- │ │ ├── api
24
- │ │ └── h5
25
- │ └── comm.js
26
- ├── index.js
27
- ├── package.json
28
- ├── plain.md
29
- └── README.md
package/lib/comm.js DELETED
@@ -1,19 +0,0 @@
1
- 'use strict';
2
- fkgConmm();
3
- async function fkgConmm() {
4
- const arg = process.argv;
5
- const {version} = require('../package.json');
6
- const versionFunt = ()=>{console.log('v'+version);}
7
- if (arg.length < 3) versionFunt();
8
- if (arg.length > 2) {
9
- const arr = require('./json/cmds.json');
10
- const name = arg[2].toLowerCase(); // 字母转小写
11
- if (name=='-v') {
12
- versionFunt();
13
- } else if(arr.includes(name)){
14
- await require('./order/'+name)(arg.slice(3));
15
- }else {
16
- console.log(`Command '${name}' doesn't exist!`);
17
- }
18
- }
19
- }
package/lib/order/init.js DELETED
@@ -1,45 +0,0 @@
1
- 'use strict';
2
- const oss = require('oss-sdk');
3
- const log = require('../utils/logs');
4
- module.exports = async()=>{
5
- // 判断是否初始化
6
- const dir = oss.dir(process.cwd());
7
- const res = await dir.list();
8
- if(res){
9
- if(res.length>0){
10
- // 当前文件夹存在文件,需要清空
11
- log.r('The current folder is not empty')
12
- log.r('This folder must be cleared!')
13
- }else{
14
- // 开始初始化
15
- const dirAdd = await dir.add('nest','data','skills','scripts');
16
- if(dirAdd){
17
- // 新建配置文件
18
- let obj = {};
19
- const {version} = require('../../package.json');
20
- obj.version = version;
21
- obj.initTime = new Date().getTime();
22
- const rrid = require('rrid');
23
- obj.appId = rrid.key(32);
24
- const scode = rrid.key(16);
25
- obj.appKey = rrid.ekey(obj.appId+obj.initTime+scode,obj.appId+obj.initTime+scode);
26
- const file = oss.file(process.cwd());
27
- const fileAdd = await file.add('config.ant',JSON.stringify(obj));
28
- if(fileAdd){
29
- // 初始化成功
30
- log.g('Initialization successful!');
31
- log.y('Security Code:'+scode);
32
- log.y('Keep the security code safe')
33
- }else{
34
- log.r('Initialization failed!');
35
- await dir.clear();
36
- }
37
- }else{
38
- //初始化失败:无法创建目录
39
- log.r('Initialization failed: unable to create directory')
40
- }
41
- }
42
- }else{
43
- log.r('Unknown error!')
44
- }
45
- }
@@ -1,15 +0,0 @@
1
- 'use strict';
2
- const log = require('../../utils/logs');
3
- module.exports = async(arg)=>{
4
- if(arg.length===0){
5
- log.r('Missing parameter')
6
- }else{
7
- const cmd = arg[0];
8
- const arr = ['start','stop','restart','status'];
9
- if(arr.includes(cmd)) {
10
- await require('./'+cmd)(arg.slice(1));
11
- }else{
12
- log.y('Command not found:ant nest '+cmd)
13
- }
14
- }
15
- }
@@ -1,4 +0,0 @@
1
- 'use strict';
2
- module.exports = async()=>{
3
- console.log(arg);
4
- }
File without changes
File without changes
File without changes
File without changes