Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
dhchandw committed Sep 4, 2024
1 parent 23517b8 commit c6e038a
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src-script/unify-regen.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ const scriptUtil = require('./script-util')

const unifySdkPath = process.argv[2]
if (!unifySdkPath) {
console.error('Missing Argument. Usage: unify-regen.js <unify_sdk_path>')
process.exit(1)
throw Error('Missing Argument. Usage: unify-regen.js <unify_sdk_path>')
}

async function generateZapFiles() {
Expand All @@ -33,13 +32,23 @@ async function generateZapFiles() {
const zclFile = `${unifySdkPath}components/uic_dotdot/dotdot-xml/library.xml`
if (!fs.existsSync(zclFile)) {
throw Error(`Invalid Zcl File ${zclFile} does not exist.`)
} else {
console.log(`👍 ZCL metafile: ${zclFile}`)
}

// get all template files in the unify sdk
const templateFiles = await scriptUtil.locateRecursively(
unifySdkPath,
'gen-templates.json'
)
if (templateFiles.length === 0) {
throw Error(`No template files found in ${unifySdkPath}`)
} else {
console.log(`👍 Found ${templateFiles.length} template files.`)
}

// get ZAP main path
const zapCli = scriptUtil.mainPath(false)

for (const templateFile of templateFiles) {
// get the output directory as per unify sdk structure
Expand All @@ -49,8 +58,6 @@ async function generateZapFiles() {
)
fs.rmSync(outputDir, { recursive: true, force: true })

const zapCli = scriptUtil.mainPath(false)

let cmdArgs = [
'node',
scriptUtil.mainPath(false),
Expand All @@ -67,7 +74,7 @@ async function generateZapFiles() {
await scriptUtil.executeCmd(null, 'npx', cmdArgs)
}
} catch (error) {
console.error('An error occurred during the ZAP generation process:', error)
throw Error('An error occurred during the ZAP generation process:', error)
}
}

Expand Down

0 comments on commit c6e038a

Please sign in to comment.