diff --git a/lib/packageSigner.js b/lib/packageSigner.js index cdce228..3473bad 100644 --- a/lib/packageSigner.js +++ b/lib/packageSigner.js @@ -51,13 +51,19 @@ class Signature { this.objectInfo = ``; } - _listFiles() { + _listFiles(userExcludeFiles) { let dirList = []; let excludeFile = this.id == 'AuthorSignature' ? ['author-signature.xml', 'signature1.xml', 'signature2.xml'] : ['signature1.xml', 'signature2.xml']; + if (undefined == userExcludeFiles || null == userExcludeFiles || '' == userExcludeFiles) { + userExcludeFiles = ['']; + } else { + userExcludeFiles = userExcludeFiles.split(','); + } + function _listDirs(curDir) { let dir = fs.readdirSync(curDir, {withFileTypes: true}); dir.forEach(item => { - if (!item.name.startsWith('.') && !excludeFile.includes(item.name)) { + if (!item.name.startsWith('.') && !excludeFile.includes(item.name) && !userExcludeFiles.includes(path.resolve(curDir, item.name))) { if (item.isDirectory()) { _listDirs(path.resolve(curDir, item.name)) } @@ -90,8 +96,8 @@ class Signature { return references; } - sign(key) { - let fileList = this._listFiles(); + sign(key, userExcludeFiles) { + let fileList = this._listFiles(userExcludeFiles); let references = this._addReferences(fileList); this.signedInfo = '\n' + @@ -169,16 +175,16 @@ module.exports = class PackageSigner { return true; } - signPackage(projectRoot) { + signPackage(projectRoot, userExcludeFiles) { let authorSig = new Signature('AuthorSignature', projectRoot); - authorSig.sign(this.profileInfo.author.privateKey); + authorSig.sign(this.profileInfo.author.privateKey, userExcludeFiles); authorSig.addKeyInfo(this.profileInfo.author.certChain); let authorSignatureXml = authorSig.generateSignatureXml(); let authorSigFile = path.resolve(projectRoot, `author-signature.xml`); fs.writeFileSync(authorSigFile, authorSignatureXml, {encoding: 'utf-8'}); let distributorSig1 = new Signature('DistributorSignature', projectRoot); - distributorSig1.sign(this.profileInfo.distributor1.privateKey); + distributorSig1.sign(this.profileInfo.distributor1.privateKey, userExcludeFiles); distributorSig1.addKeyInfo(this.profileInfo.distributor1.certChain); let distributorSignatureXml1 = distributorSig1.generateSignatureXml(); let distributorSigFile1 = path.resolve(projectRoot, `signature1.xml`); @@ -187,7 +193,7 @@ module.exports = class PackageSigner { let distributorSignatureXml2 = ''; if (this.profileInfo.distributor2) { let distributorSig2 = new Signature('DistributorSignature', projectRoot); - distributorSig2.sign(this.profileInfo.distributor2.privateKey); + distributorSig2.sign(this.profileInfo.distributor2.privateKey, userExcludeFiles); distributorSig2.addKeyInfo(this.profileInfo.distributor2.certChain); distributorSignatureXml2 = distributorSig2.generateSignatureXml(); let distributorSigFile2 = path.resolve(projectRoot, `signature2.xml`); diff --git a/lib/projectHelper.js b/lib/projectHelper.js index 8016f6d..403ec1b 100644 --- a/lib/projectHelper.js +++ b/lib/projectHelper.js @@ -114,7 +114,7 @@ module.exports = class TVWebApp { let pkgSigner = new PackageSigner(); await pkgSigner.setProfile(profilePath, activeProfile); - pkgSigner.signPackage(this.location); + pkgSigner.signPackage(this.location, excludeFiles); let widget = fs.createWriteStream(path.resolve(this.location, `${this.name}.wgt`)); let archive = archiver('zip'); @@ -128,21 +128,24 @@ module.exports = class TVWebApp { excludeFiles = excludeFiles.split(','); } - let dirent = fs.readdirSync(this.location, {withFileTypes: true}); - dirent.forEach(item => { - if (!item.name.startsWith('.')) { - let itemPath = path.resolve(this.location, item.name); - if (item.isDirectory()) { - if (!excludeFiles.includes(itemPath)) { - archive.directory(itemPath, item.name); + let rootDirLen = this.location.length; + function _listDirs(curDir) { + let dir = fs.readdirSync(curDir, {withFileTypes: true}); + dir.forEach(item => { + let itemPath = path.resolve(curDir, item.name); + if (!item.name.startsWith('.') && !excludeFiles.includes(itemPath)) { + if (item.isDirectory()) { + _listDirs(itemPath); } - } else { - if (!excludeFiles.includes(itemPath)) { - archive.append(fs.createReadStream(itemPath), {name: item.name}); + else { + let archivePath = itemPath.substring(rootDirLen); + archive.append(fs.createReadStream(itemPath), {name: archivePath}); } } - } - }); + }) + } + + _listDirs(this.location); widget.on('close', async () => { console.log('After build package, signature tempory files were removed'); console.log('[webide-common-tizentv]projectHelper.widget.on(): Build Package completed!'); diff --git a/package.json b/package.json index 09098aa..ec93562 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tizentv/webide-common-tizentv", - "version": "1.0.9", + "version": "1.0.10", "description": "Common APIs for web IDEs extension development to support Tizen SDK features.", "main": "index.js", "author": "Samsung Electronics Co., Ltd.",