Behavior3Editor批量导出改造

项目里面需要将行为树project批量的导出子树。

开始部署环境

安装环境

将node.js 设置成 10.x win32版本,再去匹配 gulp 的版本。

通过命令行安装gulp工具。

npm install gulp-cli -g
npm install gulp -D
npx -p touch nodetouch gulpfile.js
gulp --help

设置梯子

npm config set registry http://registry.npm.taobao.org

其实就是 .npmrc

registry=http://registry.npm.taobao.org

@REM 将npm的缓存都删除掉
npm cache clear --force

// 配置梯子,否则就会无法安装;
Add the below entry to your .bowerrc:
{
  "proxy":"http://<user>:<password>@<host>:<port>",
  "https-proxy":"http://<user>:<password>@<host>:<port>"
}

遇到的问题

bower sweetalert#~1.0.0-beta              cached https://github.com/t4t5/sweetalert.git#1.0.1
bower sweetalert#~1.0.0-beta            validate 1.0.1 against https://github.com/t4t5/sweetalert.git#~1.0.0-beta
bower fontawesome#~4.3.0                 ECMDERR Failed to execute "git ls-remote --tags --heads https://github.com/FortAwesome/Font-Awesome.git", exit code of #128 fatal: unable 
to access 'https://github.com/FortAwesome/Font-Awesome.git/': Failed to connect to github.com port 443: Timed out

Additional error details:
fatal: unable to access 'https://github.com/FortAwesome/Font-Awesome.git/': Failed to connect to github.com port 443: Timed out

// 配置梯子,否则就会无法安装;
Add the below entry to your .bowerrc:

{
  "proxy":"http://<user>:<password>@<host>:<port>",
  "https-proxy":"http://<user>:<password>@<host>:<port>"
}

node,gulp版本不合

PS D:\work\trunk\behavior3editor_bf> gulp serve
ReferenceError: primordials is not defined
    at fs.js:45:5
    at req_ (D:\work\trunk\behavior3editor_bf\node_modules\natives\index.js:143:24)
    at Object.req [as require] (D:\work\trunk\behavior3editor_bf\node_modules\natives\index.js:55:10)
    at Object.<anonymous> (D:\work\trunk\behavior3editor_bf\node_modules\graceful-fs\fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)

> node --version
v14.16.0
> gulp -v
CLI version: 2.3.0
Local version: 3.9.1

解决方案:

##安装npm版本控制器
npm install -g n

##切换npm版本到 V10 (v10 版本的npm会安装 node 10)
sudo n v10.19.0

##安装node
npm i -g node

##查看node版本
node --version

##现在node版本切换到了v10了,可以重新安装依赖的
    #重新安装gulp(版本很重要,应该是代码发布时的版本,而不是本地的版本)
    npm i -g gulp@3.9.1 --force
    #重新安装依赖
    npm install

npm install -g nvm

##运行
gulp watch
————————————————
版权声明:本文为优快云博主「内心毫无波动甚至还想笑」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.youkuaiyun.com/yym836659673/article/details/104847572/

将node.js降低到 10.x版本,再去匹配 gulp 的版本。

node.js_10.x版本下载

在做dist的时候,还是会下载electronc

Downloading electron-v0.34.2-linux-ia32.zip
[>                                            ] 0.0% (0 B/s)

还需要安装:

electron_v0.30.4下载地址

国内下载地址:

国内源

文件占用

打开资源管理器。

resmon.exe

其实就是vscode的powershell占用了文件。重启一次vscode就好了。

修改gulpfile.js

在这个文件里面,定义输出的版本是 windows arch类型: i32 就好了。

gulp.task('_electron', ['build'], function(cb) {
  packager({
    dir       : 'build',
    out       : '.temp-dist',
    name      : project.name,
    platform  : 'win32',
    arch      : 'ia32',
    version   : '0.34.2',
    overwrite : true,
    asar      : true
  }

由于网络情况,如果想把全部平台的库都下载全了,也是比较困难的。

批量导出子树源码

改造的位置:

export.controller.js: 75 lines

function save()
      }else if (vm.type === 'trees') {
        dialogService
          .openDirectory()
          .then(function(path){
            tree = project.trees.each(function(tree) {
              var root = tree.blocks.getRoot();
              defaultName = root.title;
              var fs = require('fs');
              var e = $window.editor.export;
              _createJson(e.treeToData(tree))
              console.log(vm.pretty)
              fs.writeFileSync(path +'/'+defaultName +'.json', vm.pretty)
              notificationService.success(
                'File path',
                defaultName +'.json'
              );
            });
            
          });
        
      }

其实就是将project.trees遍历;

将tree内容萃取出json;

直接使用fs模块,同步写入文件;

dialogService.openDirectory()能让用户自己指定输出目录;

notificationService.success()将日志输出到屏幕上;

我现在还不会如何调试,阅读了一点eletronc的文档,东西不少,今后有时间再来学习。

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值