Skip to content

Commit

Permalink
feat: added support for Slideshow Source (id:slideshow)
Browse files Browse the repository at this point in the history
Now when export or import themes, slideshow files are stored
  • Loading branch information
salsan committed Jun 25, 2021
1 parent 9a1a32b commit 8dcc166
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
29 changes: 26 additions & 3 deletions otu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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));
Expand All @@ -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;
});
}
Expand All @@ -124,24 +135,36 @@ 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))
};

});

zip.addFile("theme.json", Buffer.from(JSON.stringify(theme), "utf8"));
zip.writeZip(fdest + ".otu");
console.log('Completed!!! '+fdest+'.otu');

});

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -20,5 +20,13 @@
"tool"
],
"author": "Salvatore Santagati [email protected]",
"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"
}

0 comments on commit 8dcc166

Please sign in to comment.