New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

space-cli

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

space-cli - npm Package Compare versions

Comparing version 0.9.0 to 1.0.0

2

package.json
{
"name": "space-cli",
"version": "0.9.0",
"version": "1.0.0",
"description": "CLI for space information",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -15,8 +15,10 @@ const moment = require('moment-timezone');

exports.isValidTimezone = function (timezone) {
return moment.tz.zone(timezone);
// Empty time zone option is a true flag, type condition checks if a value has been submitted
const isPossibleTimezone = typeof timezone === 'string';
return isPossibleTimezone && moment.tz.zone(timezone);
};
exports.convertTimezone = function (time, timezone) {
const newTime = moment.tz(new Date(time), timezone).format('MMMM D, YYYY HH:mm:ss z');
return newTime;
return moment.tz(new Date(time), timezone).format('MMMM D, YYYY HH:mm:ss z');
};

@@ -5,3 +5,6 @@ const chalk = require('chalk');

exports.about = function () {
helpers.printMessage(chalk.green('Welcome to Space CLI') + ' ' + '- a CLI for space information' + '\n\n' + 'Credits:' + '\n' + 'https://launchlibrary.net/ - API documentation for upcoming launches');
const welcome = chalk`{green Welcome to Space CLI} - a CLI for space information`;
const credits = `Credits:\nhttps://launchlibrary.net/ - API documentation for upcoming launches`;
helpers.printMessage(`${welcome}\n\n${credits}`);
};

@@ -10,8 +10,7 @@ const axios = require('axios');

// Empty time zone option is a true flag, type condition checks if a value has been submitted
const argvTimezoneHasValue = argv.timezone && typeof argv.timezone === 'string';
const argvHasValidTimezone = argvTimezoneHasValue && helpers.isValidTimezone(argv.timezone);
const timezone = (argvHasValidTimezone && argv.timezone) || settings.timezone;
const timezone = argv.timezone || settings.timezone;
if (argvTimezoneHasValue && !argvHasValidTimezone) {
// Central validation with error outside time conversion method prevents error from being shown with every conversion e.g. when requesting info about n launches
const isValidTimezone = helpers.isValidTimezone(timezone);
if (!!timezone && !isValidTimezone) {
helpers.printError('Unrecognized timezone. Time will be shown in UTC');

@@ -30,44 +29,30 @@ }

const title = chalk`{yellow Next launch} ${next.id} ${next.name}`;
let schedule = chalk`{cyan Scheduled launch attempt:} ${next.net}`;
if (timezone) {
const convertedTime = helpers.convertTimezone(next.net, timezone);
schedule = chalk`{cyan Scheduled launch attempt:} ${convertedTime}`;
}
const time = isValidTimezone ? helpers.convertTimezone(next.net, timezone) : next.net;
const scheduleFlag = next.tbddate === 1 || next.tbdtime === 1 ? chalk` {bgYellow.black TBD}` : '';
const schedule = chalk`{cyan Scheduled launch attempt:} ${time}${scheduleFlag}`;
if (next.tbddate === 1 || next.tbdtime === 1) {
schedule += chalk` {bgYellow.black TBD}`;
}
const hasVideoUrls = !!next.vidURLs && next.vidURLs.length > 0;
const broadcasts = hasVideoUrls ? chalk`{cyan Broadcasts:} ${next.vidURLs.join(' ')}` : chalk`{cyan Broadcasts:} TBD / Unavailable`;
const vidCount = next.vidURLs.length;
let broadcasts = vidCount < 1 ? chalk`{cyan Broadcasts:} TBD / Unavailable` : chalk`{cyan Broadcasts:}`;
const launchCore = `${title}\n${schedule}\n${broadcasts}`;
let launchDetails = '';
if (vidCount >= 1) {
for (let i = 0; i < vidCount; i++) {
broadcasts += ` ${next.vidURLs[i]}`;
}
}
const dataBreak = nextCount > 1 ? '\n' : '';
if (argv.details) {
const rocket = chalk`{cyan Rocket:} ${next.rocket.name}`;
const missionCount = next.missions.length;
let missions = missionCount < 1 ? chalk`{cyan Missions:} TBD / Unknown` : chalk`{cyan Missions:}`;
const missionsList = !!next.missions && next.missions.length > 0 && next.missions.map((mission, index) => {
const missionNo = `${++index})`;
const missionType = `[${mission.typeName}]`;
const missionDescription = mission.description;
if (missionCount >= 1) {
for (let i = 0; i < missionCount; i++) {
const missionNo = `${i + +1})`;
const missionType = `[${next.missions[i].typeName}]`;
const missionDescription = next.missions[i].description;
return chalk`{yellow ${missionNo} ${missionType}} ${missionDescription}`;
});
const missions = missionsList ? chalk`{cyan Missions:}\n${missionsList.join('\n')}` : chalk`{cyan Missions:} TBD / Unknown`;
missions += '\n' + chalk.yellow(missionNo + ' ' + missionType) + ' ' + missionDescription;
}
}
launchDetails = `\n${rocket}\n${missions}`;
}
helpers.printMessage(`${title}\n${schedule}\n${broadcasts}\n${rocket}\n${missions}${dataBreak}`);
} else {
helpers.printMessage(`${title}\n${schedule}\n${broadcasts}${dataBreak}`);
}
const dataBreak = nextCount > 1 ? '\n' : '';
helpers.printMessage(`${launchCore}${launchDetails}${dataBreak}`);
}

@@ -74,0 +59,0 @@ }).catch(function (error) {

@@ -6,2 +6,4 @@ const fs = require('fs');

const helpers = require('../helpers');
const homeDir = os.homedir();

@@ -12,44 +14,40 @@ const configSubdir = os.platform() === 'win32' ? path.join('AppData', 'Local') : '.config';

const helpers = require('../helpers');
const settingsFilePath = path.join(spacecliDir, 'settingsData.json');
const settingsFilePath = path.join(spacecliDir, 'settings.json');
function getSettings () {
if (fs.existsSync(settingsFilePath)) {
const data = fs.readFileSync(settingsFilePath, 'utf8');
return JSON.parse(data);
}
if (!fs.existsSync(spacecliDir)) {
fs.mkdirSync(spacecliDir);
}
return {};
const settingsFileExists = fs.existsSync(settingsFilePath);
const settingsDataRaw = settingsFileExists && fs.readFileSync(settingsFilePath, 'utf8');
const settings = settingsDataRaw && JSON.parse(settingsDataRaw);
return settings || {};
}
function update (argv) {
const settingsData = getSettings();
const settingsDataUpdate = Object.create(settingsData);
const configDirExists = fs.existsSync(spacecliDir);
if (argv.timezone && argv.timezone.length > 0) {
const timezone = argv.timezone;
const currentSettings = getSettings();
const settings = Object.create(currentSettings);
if (!helpers.isValidTimezone(timezone)) {
const errorMessage = 'Unrecognised time zone.';
return helpers.printError(errorMessage);
}
settingsDataUpdate.timezone = timezone;
const hasValidTimezone = argv.timezone && helpers.isValidTimezone(argv.timezone);
if (!hasValidTimezone) {
const errorMessage = 'Unrecognised time zone.';
return helpers.printError(errorMessage);
}
settings.timezone = argv.timezone;
const settingsJSON = JSON.stringify(settingsDataUpdate);
const settingsJSON = JSON.stringify(settings);
if (settingsData.timezone !== settingsDataUpdate.timezone) {
return fs.writeFile(settingsFilePath, settingsJSON, 'utf8', (error) => {
if (error) {
return helpers.printError(error.message);
}
const message = chalk.bgGreen('Success!') + ' ' + 'The file has been saved!';
helpers.printMessage(message);
});
if (!configDirExists) {
fs.mkdirSync(spacecliDir);
}
const message = chalk.bgGreen('OK') + ' ' + 'Settings are correct, no changes required.';
return helpers.printMessage(message);
return fs.writeFile(settingsFilePath, settingsJSON, 'utf8', (error) => {
if (error) {
return helpers.printError(error.message);
}
const message = chalk`{bgGreen Success!} The file has been saved!`;
helpers.printMessage(message);
});
};

@@ -56,0 +54,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc