Skip to content

Commit

Permalink
Merge pull request #13 from keyuan0701/dev
Browse files Browse the repository at this point in the history
Fix exclude files issue
  • Loading branch information
keyuan0701 authored Sep 22, 2020
2 parents 98d353f + 5069586 commit 34d98f5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
22 changes: 14 additions & 8 deletions lib/packageSigner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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 = '<SignedInfo>\n' +
Expand Down Expand Up @@ -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`);
Expand All @@ -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`);
Expand Down
29 changes: 16 additions & 13 deletions lib/projectHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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!');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down

0 comments on commit 34d98f5

Please sign in to comment.