Skip to content
代码片段 群组 项目
提交 f527ae81 编辑于 作者: Timotej Ecimovic's avatar Timotej Ecimovic
浏览文件

Ensure that the conversion properly reports packages.

上级 e0b11181
No related branches found
No related tags found
无相关合并请求
......@@ -37,6 +37,7 @@
"pretty-quick": "pretty-quick",
"self-check": "node src-electron/main-process/electron-main.js selfCheck -g ./test/gen-template/zigbee/gen-templates.json",
"version-stamp": "node src-script/zap-versionstamp.js",
"refresh-zap": "node src-script/zap-convert.js -z zcl-builtin/silabs/zcl.json test/resource/three-endpoint-device.zap -g test/gen-template/zigbee/gen-templates.json -o test/resource/three-endpoint-device.zap",
"gen": "node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/zigbee/gen-templates.json -i ./test/resource/three-endpoint-device.zap -o ./tmp",
"gen2": "node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ./test/gen-template/zigbee/gen-templates.json -i ./test/resource/generation-test-file-1.zap -o ./tmp",
"gen3": "node src-script/zap-generate.js -z ./zcl-builtin/dotdot/library.xml -g ./test/gen-template/zigbee/gen-templates.json -i ./test/resource/generation-test-file-1.zap -o ./tmp",
......
......@@ -351,12 +351,14 @@ async function loadTemplates(db, genTemplatesJson) {
}
if (genTemplatesJson == null) {
context.error = 'No templates file specified.'
env.logWarning(context.error)
return Promise.resolve(context)
}
let file = path.resolve(genTemplatesJson)
if (!fs.existsSync(file)) {
context.error = `Can't locate templates file: ${file}`
env.logWarning(context.error)
return Promise.resolve(context)
}
......
......@@ -136,38 +136,53 @@ function outputFile(inputFile, outputPattern) {
* @param {*} files
* @param {*} output
*/
function startConvert(files, output, options = { log: true, quit: true }) {
async function startConvert(
files,
output,
options = { log: true, quit: true }
) {
if (options.log) console.log(`🤖 Conversion started`)
if (options.log) console.log(` 👉 input files: ${files}`)
if (options.log) console.log(` 👉 output pattern: ${output}`)
let dbFile = env.sqliteFile('convert')
let db = await dbApi.initDatabaseAndLoadSchema(
dbFile,
env.schemaFile(),
env.zapVersion()
)
if (options.log) console.log(' 👉 database and schema initialized')
await zclLoader.loadZcl(db, args.zclPropertiesFile)
if (options.log)
console.log(` 👉 zcl package loaded: ${args.zclPropertiesFile}`)
if (args.genTemplateJsonFile != null) {
await generatorEngine.loadTemplates(db, args.genTemplateJsonFile)
if (options.log)
console.log(` 👉 templates loaded: ${args.genTemplateJsonFile}`)
}
return dbApi
.initDatabaseAndLoadSchema(dbFile, env.schemaFile(), env.zapVersion())
.then((d) => {
db = d
if (options.log) console.log(' 👉 database and schema initialized')
return zclLoader.loadZcl(db, args.zclPropertiesFile)
})
.then((d) => {
return util.executePromisesSequentially(files, (singlePath) =>
importJs
.importDataFromFile(db, singlePath)
.then((sessionId) => {
if (options.log) console.log(` 👈 read in: ${singlePath}`)
let of = outputFile(singlePath, output)
let parent = path.dirname(of)
if (!fs.existsSync(parent)) {
fs.mkdirSync(parent, { recursive: true })
}
return exportJs.exportDataIntoFile(db, sessionId, of)
})
.then((outputPath) => {
if (options.log) console.log(` 👉 write out: ${outputPath}`)
})
)
})
return util
.executePromisesSequentially(files, (singlePath) =>
importJs
.importDataFromFile(db, singlePath)
.then((sessionId) => {
return util
.initializeSessionPackage(db, sessionId)
.then((pkgs) => sessionId)
})
.then((sessionId) => {
if (options.log) console.log(` 👈 read in: ${singlePath}`)
let of = outputFile(singlePath, output)
let parent = path.dirname(of)
if (!fs.existsSync(parent)) {
fs.mkdirSync(parent, { recursive: true })
}
return exportJs.exportDataIntoFile(db, sessionId, of)
})
.then((outputPath) => {
if (options.log) console.log(` 👉 write out: ${outputPath}`)
})
)
.then(() => {
if (options.log) console.log('😎 Conversion done!')
if (options.quit && app != null) {
......
......@@ -19,12 +19,6 @@ const { dialog } = require('electron')
const importJs = require('../importexport/import.js')
const windowJs = require('./window.js')
const env = require('../util/env.js')
/*
* Created Date: Tuesday, March 10th 2020, 4:22:57 pm
* Author: Timotej Ecimovic
*
* Copyright (c) 2020 Silicon Labs
*/
// You can always use this to show an exception.
function showErrorMessage(title, err) {
......
......@@ -28,13 +28,22 @@ let arg = yargs
type: 'string',
demandOption: true,
})
.option('generationTemplate', {
desc: 'Specifies gen-template.json file to be used.',
alias: 'g',
type: 'string',
demandOption: true,
})
.option('out', {
desc: 'Output filename where the converted file goes.',
alias: 'o',
type: 'string',
demandOption: true,
})
.demandOption(['zcl', 'out'], 'Please provide required options!')
.demandOption(
['zcl', 'out', 'generationTemplate'],
'Please provide required options!'
)
.help()
.wrap(null).argv
......@@ -49,6 +58,8 @@ let cli = [
arg.zcl,
'--out',
arg.out,
'--generationTemplate',
arg.generationTemplate,
]
arg._.forEach((x) => cli.push(x))
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册