Skip to content

Commit

Permalink
added: A utitility function to show warning when the current version …
Browse files Browse the repository at this point in the history
…is not the latest version
  • Loading branch information
Sadaf-A committed Apr 18, 2024
1 parent 26b3746 commit 45b3a07
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 0 deletions.
130 changes: 130 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"dependencies": {
"@electron/asar": "^3.0.3",
"archiver": "^4.0.2",
"axios": "^1.6.8",
"chalk": "^4.1.0",
"chokidar": "^3.5.1",
"commander": "^7.2.0",
Expand Down
1 change: 1 addition & 0 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports.register = (program) => {
utils.showArt();
utils.log(`Application package was generated at the ${buildDir} directory!`);
utils.log('Distribution guide: https://neutralino.js.org/docs/distribution/overview');
utils.checkLatestVersion();
});
}

1 change: 1 addition & 0 deletions src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports.register = (program) => {
.action(async (binaryName, command) => {
await creator.createApp(binaryName, command.template);
utils.showArt();
utils.checkLatestVersion();
});
}

1 change: 1 addition & 0 deletions src/commands/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports.register = (program) => {
}
else
pluginloader.list(plugin);
utils.checkLatestVersion();
});
}

1 change: 1 addition & 0 deletions src/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ module.exports.register = (program) => {

filewatcher.stop();
websocket.stop();
utils.checkLatestVersion();
});
}
1 change: 1 addition & 0 deletions src/commands/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports.register = (program) => {

utils.showArt();
utils.log('Run "neu version" to see installed version details.');
utils.checkLatestVersion();
});
}

1 change: 1 addition & 0 deletions src/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module.exports.register = (program) => {
utils.log(`Run this command inside your project directory` +
` to get project specific Neutralinojs version.`);
}
utils.checkLatestVersion();
});
}

15 changes: 15 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const chalk = require('chalk');
const constants = require('./constants');
const CONFIG_FILE = constants.files.configFile;
const config = require('./modules/config')
const axios = require('axios');
const package = require('../package.json')

let error = (message) => {
console.error(`neu: ${chalk.bgRed.black('ERRR')} ${message}`);
Expand Down Expand Up @@ -36,6 +38,18 @@ let checkCurrentProject = () => {
}
}

let checkLatestVersion = async () => {
const response = await axios.get(`https://registry.npmjs.org/${package.name}`);
const data = response.data;
const versionsArray = Object.keys(data.time);
const latestVersion = versionsArray[versionsArray.length - 1];
if (package.version !== latestVersion) {
warn(`Please update to the latest version: ${latestVersion}`);
} else {
return;
}
}

let log = (message) => {
console.log(`neu: ${chalk.bgGreen.black('INFO')} ${message}`);
}
Expand All @@ -62,6 +76,7 @@ module.exports = {
getFiglet,
showArt,
checkCurrentProject,
checkLatestVersion,
log,
warn,
trimPath,
Expand Down

0 comments on commit 45b3a07

Please sign in to comment.