Skip to content

Commit 0425079

Browse files
committed
Check for updates and deprecation warning
1 parent ad6cd84 commit 0425079

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

commands/utils/constants.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@ constants.stage = {
55
RENDER_API_URL: "https://stage-api.lambdatestinternal.com/storybook/render",
66
BUILD_STATUS_URL: "https://stage-api.lambdatestinternal.com/storybook/status",
77
BASE_URL: "https://stage-api.lambdatestinternal.com",
8-
SB_BUILD_VALIDATE_PATH: "/storybook/validate"
8+
SB_BUILD_VALIDATE_PATH: "/storybook/validate",
9+
CHECK_UPDATE_PATH: "storybook/packageinfo"
910
};
1011
constants.prod = {
1112
AUTH_URL: "https://api.lambdatest.com/storybook/auth",
1213
RENDER_API_URL: "https://api.lambdatest.com/storybook/render",
1314
BUILD_STATUS_URL: "https://api.lambdatest.com/storybook/status",
1415
BASE_URL: "https://api.lambdatest.com",
15-
SB_BUILD_VALIDATE_PATH: "/storybook/validate"
16+
SB_BUILD_VALIDATE_PATH: "/storybook/validate",
17+
CHECK_UPDATE_PATH: "storybook/packageinfo"
1618
};
1719

1820
module.exports = { constants };

commands/utils/package.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const axios = require('axios');
2+
var { constants } = require('./constants');
3+
4+
// Check for package updates
5+
function checkUpdate(version, options) {
6+
return axios.get(new URL(constants[options.env].CHECK_UPDATE_PATH, constants[options.env].BASE_URL).href, {
7+
params: {
8+
packageName: 'smartui-storybook',
9+
packageVersion: version
10+
}})
11+
.then(function (response) {
12+
if (response.data.data.deprecated) {
13+
console.log('v' + version + ' is deprecated. Please update to v' + response.data.data.latestVersion);
14+
} else if (response.data.data.latestVersion != version) {
15+
console.log('A newer version v' + response.data.data.latestVersion + ' is available.');
16+
}
17+
})
18+
.catch(function (error) {
19+
if (error.response) {
20+
console.log('Cannot check for updates. Error: ' + error.response.data.error.message);
21+
} else {
22+
console.log('Cannot check for updates. Error: ' + error.message);
23+
}
24+
});
25+
};
26+
27+
module.exports = { checkUpdate };

index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ const program = new Command();
55
const { storybook } = require('./commands/storybook');
66
const { validateProjectToken, validateLatestBuild } = require('./commands/utils/validate');
77
const { createConfig } = require('./commands/config');
8+
const { version } = require('./package.json');
9+
const { checkUpdate } = require('./commands/utils/package');
810

911
program
1012
.name('smartui')
1113
.description('CLI to help you run your SmartUI tests on LambdaTest platform')
12-
.version('1.1.2')
14+
.version('v' + version)
1315
.addOption(new Option('--env <prod|stage>', 'Runtime environment option').choices(['prod', 'stage']));
1416

1517
const configCommand = program.command('config')
@@ -18,7 +20,12 @@ const configCommand = program.command('config')
1820
configCommand.command('create')
1921
.description('Create LambdaTest SmartUI config file')
2022
.argument('[filepath]', 'Optional config filepath')
21-
.action(function(filepath) {
23+
.action(async function(filepath, options) {
24+
options.env = program.opts().env || 'prod';
25+
console.log('SmartUI Storybook CLI v' + version);
26+
await checkUpdate(version, options);
27+
console.log('\n');
28+
2229
createConfig(filepath);
2330
});
2431

@@ -29,6 +36,10 @@ program.command('storybook')
2936
// .option('--force-rebuild', 'Force a rebuild of an already existing build.', false)
3037
.action(async function(serve, options) {
3138
options.env = program.opts().env || 'prod';
39+
console.log('SmartUI Storybook CLI v' + version);
40+
await checkUpdate(version, options);
41+
console.log('\n');
42+
3243
await validateProjectToken(options);
3344
// if (!options.forceRebuild) await validateLatestBuild(options);
3445
storybook(serve, options);

0 commit comments

Comments
 (0)