microbit部署问题及解决

1)pxtapp.ts

pxt serve本机正常,改为具体地址提示为编译错误,测试是由于pxt serve使用了官方的hex文件,放在服务器后,需要调用自己的资源。

改为不从cdn下载为调接口,解决hex文件无法下载的问题,当然也可以增加GET clientconfig使用自己的cdn

 

function getHexAsync(sha) {

var forceLive = pxt.webConfig && pxt.webConfig.isStatic;

return (pxt.Cloud.privateGetAsync("compile/" + sha, forceLive)

.then(function (r) { return r.hex; }));

}

 

function downloadHexInfoCoreAsync(extInfo) {

var hexurl = "";

hexloader.showLoading(pxt.U.lf("Compiling (this may take a minute)..."));

return downloadHexInfoLocalAsync(extInfo)

.then(function (hex) {

if (hex) {

// Found the hex image in the local server cache, use that

return hex;

}

// return getCdnUrlAsync() //从CDN上下载hex文件

// .then(url => {

// hexurl = url + "/compile/" + extInfo.sha

// console.log(hexurl+".hex")

// return U.httpGetTextAsync(hexurl + ".hex")

// })

return getHexAsync(extInfo.sha) //改为直接调用接口

.then(function (hex) {

return hex;

})

 

 

2)server.ts

 

else if( cmd== "GET clientconfig"){

//增加此接口,返回CDN地址

//http://192.168.1.142:3232 https://makecode.trafficmanager.cn

return readFileAsync("targetconfig.json").then((res) => {return {primaryCdnUrl: "http://192.168.1.142:3232"}});

}

else if(cmd=="GET translations"){

//增加翻译文件接口

let jsonFile= opts['filename']

let lang=opts['lang']

console.log('lang:'+lang+ ' jsonFile:'+jsonFile )

return readFileAsync(jsonFile.toString).then(buf => JSON.parse(buf.toString("utf8")));

}

 

3)翻译文件下载,并放在对应的文件夹

pxt-microbit

 

https://makecode.com/api/translations?lang=zh-CN&filename=microbit%2Fcore-jsdoc-strings.json&approved=true

https://makecode.com/api/translations?lang=zh-CN&filename=microbit%2Fcore-strings.json&approved=true

https://makecode.com/api/translations?lang=zh-CN&filename=microbit%2Fradio-jsdoc-strings.json&approved=true

https://makecode.com/api/translations?lang=zh-CN&filename=microbit%2Fradio-strings.json&approved=true

http://10.0.28.99:3232/api/translations?lang=zh-CN&filename=strings.json&approved=true

 

https://makecode.microbit.org/api/translations?lang=zh-CN&filename=microbit%2Fdevices-strings.json&approved=true

 

https://makecode.microbit.org/api/translations?lang=zh-CN&filename=microbit%2Fbluetooth-jsdoc-strings.json&approved=true

 

https://makecode.microbit.org/api/translations?lang=zh-CN&filename=microbit%2Fbluetooth-strings.json&approved=true

 

https://makecode.microbit.org/api/translations?lang=zh-CN&filename=microbit%2Fdevices-jsdoc-strings.json&approved=true

 

你可能感兴趣的:(microbit部署问题及解决)