From 0190d94407f8487db3a5156fb85c36a76b34d819 Mon Sep 17 00:00:00 2001 From: Pirquessa Date: Sat, 8 Feb 2020 12:57:39 +0100 Subject: [PATCH] Try to run npm install only if needed ! --- .vscode/launch.json | 17 +++++++++++++++++ utils/update.js | 23 ++++++++++++++++------- vigiupdate.js | 2 +- 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..02db254 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,17 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Vigiupdate", + "skipFiles": [ + "/**" + ], + "program": "${workspaceFolder}\\vigiupdate.js" + } + ] +} \ No newline at end of file diff --git a/utils/update.js b/utils/update.js index 384979f..018abca 100644 --- a/utils/update.js +++ b/utils/update.js @@ -108,14 +108,25 @@ module.exports = { downloadAndUnzipTag: function(archiveUri, tmpFolder) { console.log('Download @ ' + archiveUri); - return new Promise(function (resolve, reject) { + return new Promise((resolve, reject) => { // downloadAndFollowRedirect last archive - this.downloadAndFollowRedirect(archiveUri).then(function (response) { + this.downloadAndFollowRedirect(archiveUri).then((response) => { response .pipe(unzipper.Extract({ path: tmpFolder })) // Will create tmpFolder if needed - .on('close', resolve); + .on('close', () => { + try { + fs.readdirSync(tmpFolder).forEach((tmpSubFolder) => { // Zip contain a sub-folder... + this.copyFolder(tmpFolder + path.sep + tmpSubFolder, tmpFolder, []); + this.deleteFileOrFolder(tmpFolder + path.sep + tmpSubFolder); + resolve(); + }); + } + catch (e) { + reject(e); + } + }); }, reject); - }.bind(this)); + }); }, replaceCurrentProject: function(originPath, currentProjetPath) { @@ -125,9 +136,7 @@ module.exports = { } try { - fs.readdirSync(originPath).forEach(function (projectFolder) { // Zip contain a sub-folder... - this.copyFolder(originPath + path.sep + projectFolder, currentProjetPath, []); - }.bind(this)); + this.copyFolder(originPath, currentProjetPath, []); } catch (e) { reject(e); diff --git a/vigiupdate.js b/vigiupdate.js index 0b13e0b..b692ee8 100644 --- a/vigiupdate.js +++ b/vigiupdate.js @@ -28,7 +28,7 @@ updateUtils.getLatestTagInfos(repoOwner, repoId).then(function (latestTag) { } console.log('Backup current project'); - updateUtils.copyFolder(projectFolderPath, backupFolderPath, [path.resolve('update.backup2'), path.resolve('.git'), path.resolve('node_modules'), tempFolderPath, backupFolderPath]); + updateUtils.copyFolder(projectFolderPath, backupFolderPath, [path.resolve('.git'), path.resolve('.vscode'), path.resolve('node_modules'), tempFolderPath, backupFolderPath]); } catch(e) { console.error('Fail to backup current project: ' + e);