Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
- Fixed because there was a problem with asynchronous processing
- Stop using the fs-extra module due to a problem that the fs-extra module could not be read in the second execution
  • Loading branch information
fuji44 committed Dec 7, 2019
1 parent ee5d472 commit 3d98862
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 42 deletions.
30 changes: 6 additions & 24 deletions package-lock.json

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

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tyranoscript-packager",
"version": "0.1.6-beta.2",
"version": "0.1.6-beta.3",
"description": "This is a CLI tool for packaging Typescript apps.",
"bin": {
"tyrano": "src/main/index.js"
Expand All @@ -26,7 +26,8 @@
"dependencies": {
"archiver": "^3.1.1",
"commander": "^4.0.1",
"fs-extra": "^8.1.0",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"tar": "^5.0.5"
},
"devDependencies": {
Expand Down
27 changes: 16 additions & 11 deletions src/main/TyranoscriptPackagerForWindows.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const tar = require('tar');
const archiver = require('archiver');
Expand Down Expand Up @@ -111,9 +111,9 @@ class TyranoscriptPackagerForWindows {
logger.log('Tyrano app root dir:', tyranoAppRootDir);
logger.log('NW.js Manifest:', nwjsManifestJson);
logger.log('Export dir:', destDir);
await fs.ensureDir(destDir);
await fsUtil.ensureDir(destDir);
await this.exportGameExe(tyranoAppRootDir, nwjsManifestJson, destDir);
await this.copyTyranoBinFiles(destDir)
await this.copyTyranoBinFiles(destDir);
}


Expand All @@ -126,7 +126,7 @@ class TyranoscriptPackagerForWindows {
}

copyTyranoBinFiles(destDir) {
return fs.copy(this.binWinDir, destDir, {filter: (src, dest) => {
return fsUtil.copy(this.binWinDir, destDir, {filter: (src, dest) => {
if (path.basename(src) === 'nw.exe') return false;
if (path.basename(src) === '.gitignore') return false;
if (path.basename(src) === '.npmignore') return false;
Expand All @@ -141,7 +141,10 @@ class TyranoscriptPackagerForWindows {
*/
appendNwjsManifest(nwjsManifestJson, archive) {
return new Promise(resolve => {
archive.append(nwjsManifestJson, {name: 'package.json'})
archive.append(nwjsManifestJson, {name: 'package.json'});
archive.addListener('end', () => {
logger.log('Success write Tyrano manifest to archive');
});
resolve();
})
}
Expand All @@ -157,6 +160,9 @@ class TyranoscriptPackagerForWindows {
archive.directory(path.join(tyranoAppRootDir, 'data'), 'data');
archive.directory(path.join(tyranoAppRootDir, 'tyrano'), 'tyrano');
archive.file(path.join(tyranoAppRootDir, 'index.html'), {name: 'index.html'});
archive.addListener('end', () => {
logger.log('Success write Tyrano app contents to archive');
});
resolve();
})
}
Expand Down Expand Up @@ -199,12 +205,11 @@ class TyranoscriptPackagerForWindows {
*/
writeBinary(ws, binaryPath) {
return new Promise(resolve => {
try {
ws.write(new Uint8Array(Buffer.from(fs.readFileSync(binaryPath))));
} catch (err) {
throw err;
}
resolve();
ws.write(new Uint8Array(Buffer.from(fs.readFileSync(binaryPath))), (err) => {
if (err) throw err;
logger.log('Success write binary', binaryPath);
resolve();
});
});
}
}
Expand Down
21 changes: 20 additions & 1 deletion src/main/fsUtil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const fs = require('fs-extra');
const fs = require('fs');
const ncp = require('ncp');
const mkdirp = require('mkdirp');

module.exports.isNotExist = (filePath) => {
try {
Expand All @@ -19,3 +21,20 @@ module.exports.canNotRead = (filePath) => {
}
};

module.exports.ensureDir = (dir) => {
return new Promise(resolve => {
mkdirp(dir, (err) => {
if (err) throw err;
resolve();
});
});
}

module.exports.copy = (src, dest, options) => {
return new Promise(resolve => {
ncp(src, dest, options, (err) => {
if (err) throw err;
resolve();
});
});
}
10 changes: 6 additions & 4 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

const program = require('commander');
const fs = require('fs-extra');
const fs = require('fs');
const path = require('path');
const logger = require('./logger');

Expand All @@ -13,7 +13,7 @@ const TyPackagerForWindows = require('./TyranoscriptPackagerForWindows')
//---------- initialize commander ----------//

program
.version(fs.readJsonSync(path.join(__dirname, '../../package.json')).version)
.version(JSON.parse(fs.readFileSync(path.join(__dirname, '../../package.json'))).version)
.option('-a, --app-dir <string>', 'Specify the directory of Typescript application', './')
.option('-d, --dest-dir <string>', 'Specify the dest directory', './dest')
.option('-n, --name <string>', 'Specify the name of the game. If omitted, the app-dir name is used')
Expand Down Expand Up @@ -50,8 +50,10 @@ program.platforms.forEach((value, index, array) => {
program.width, program.height, program.maxWidth, program.maxHeight, program.minWidth, program.minHeight
);
const destWinDir = path.join(path.resolve(program.destDir), 'win');
tyTackager.package(appRootDir, manifest, destWinDir);
logger.log('Successful packaging for Windows :', destWinDir);
const promise = tyTackager.package(appRootDir, manifest, destWinDir);
promise.then(() => {
logger.log('Successful packaging for Windows :', destWinDir);
});
break;
// case 'mac':
//TODO Implement mac packaging
Expand Down

0 comments on commit 3d98862

Please sign in to comment.