diff --git a/otu.js b/otu.js index 8bb4d1e..2ef4527 100644 --- a/otu.js +++ b/otu.js @@ -62,6 +62,7 @@ yargs(hideBin(process.argv)) .alias('version', 'v') .argv; + /** * @description importTheme return compatible scene version from original and extract files * @param {string} fsource - source file @@ -79,6 +80,16 @@ function importTheme(fsource, fdest, options) { theme["sources"].forEach(src => { + if (typeof(src.settings.files) !== 'undefined') { + src.settings.files.forEach((item, index) => { + if (fs.statSync(item.value).isFile()) { + zip.extractEntryTo("files/" + path.win32.basename(item.value), currentDir, true, true); + } else zip.extractEntryTo("files/" + path.win32.basename(item.value) + "/", currentDir, true, true); + + src.settings.files[index].value = path.resolve(currentDir, 'files', path.win32.basename(src.settings.files[index].value)); + }) + } + if (typeof(src.settings.file) !== 'undefined') { src.settings.file = path.resolve(currentDir, 'files', path.win32.basename(src.settings.file)); @@ -102,7 +113,7 @@ function importTheme(fsource, fdest, options) { fs.writeFile(fdest, JSON.stringify(theme), function(err) { if (err) return console.log(err); - console.log('Completed!!!'); + console.log('Completed!!! '+fdest); return; }); } @@ -124,17 +135,28 @@ function exportTheme(fsource, fdest, options) { theme["sources"].forEach(src => { + if (typeof(src.settings.files) !== 'undefined') { + src.settings.files.forEach(item => { + if (fs.existsSync(item.value)) { + if (fs.statSync(item.value).isFile()) { + zip.addLocalFile(item.value, 'files/', path.win32.basename(item.value)); + } else { + zip.addFile('files/' + path.win32.basename(item.value) + '/', Buffer.alloc(0), "", fs.statSync(item.value)); + zip.addLocalFolder(item.value, 'files/' + path.win32.basename(item.value) + '/'); + } + } + }) + }; + if ((typeof(src.settings.file) !== 'undefined') && fs.existsSync(src.settings.file)) { zip.addLocalFile(src.settings.file, 'files/', path.win32.basename(src.settings.file)) }; if ((typeof(src.settings.custom_font) !== 'undefined') && fs.existsSync(src.settings.custom_font)) { - zip.addLocalFile(src.settings.custom_font, 'files/', path.win32.basename(src.settings.custom_font)) }; if ((typeof(src.settings.local_file) !== 'undefined') && fs.existsSync(src.settings.local_file)) { - zip.addLocalFile(src.settings.local_file, 'files/', path.win32.basename(src.settings.local_file)) }; @@ -142,6 +164,7 @@ function exportTheme(fsource, fdest, options) { zip.addFile("theme.json", Buffer.from(JSON.stringify(theme), "utf8")); zip.writeZip(fdest + ".otu"); + console.log('Completed!!! '+fdest+'.otu'); }); diff --git a/package-lock.json b/package-lock.json index aeec2bf..ddd8cca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "otu", + "name": "otu-tool", "version": "0.0.2", "lockfileVersion": 1, "requires": true, diff --git a/package.json b/package.json index 246506a..70405fe 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "adm-zip": "^0.5.5", "yargs": "^17.0.1" }, - "name": "otu", - "version": "0.0.2", + "name": "otu-tool", + "version": "0.0.3", "bin": { "otu": "otu.js" }, @@ -20,5 +20,13 @@ "tool" ], "author": "Salvatore Santagati info@salsan.dev", - "license": "GPL-3.0-or-later" + "license": "GPL-3.0-or-later", + "repository": { + "type": "git", + "url": "git+https://github.com/salsan/otu.git" + }, + "bugs": { + "url": "https://github.com/salsan/otu/issues" + }, + "homepage": "https://github.com/salsan/otu#readme" }