1、配置编译环境
在scratch-blocks目录下安装scratch-blocks需要的包。
npm install
安装Python2.7。这是scratch-blocks 中 build.py文件中的部分代码,仅支持Python2.x,通常都使用Python2.7。
2、修改build.py
windows环境下 如果直接执行编译命令,可能会报错,需要修改build.py。
修改两处大概331行和557行,添加shell=True,调用cmd.exe去执行。
# 大约331行 在subprocess.Popen参数中添加shell=True
outfile = open("dash_args.txt","w+")
outfile.write("\n".join(args[11:]))
outfile.close()
args = args[:11]
args.extend(['--flagfile','dash_args.txt'])
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell = True)
# 大约577行 在subprocess.Popen参数中添加shell=True
test_proc = subprocess.Popen(test_args, stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=True)
3、编译
编译时需要科学上网,否则Google 远程编译服务不可用。
在scratch-blocks目录下执行。
npm run prepublish //或 python build.py
出现如下输出就开始编译了,等待执行完就可以编译成功了。
如果编译报错,可尝试直接在scratch-blocks下执行如下命令
npm install