Commit 29115188 authored by Philipp Nowinski's avatar Philipp Nowinski
Browse files

[FEATURE] migrate open task to new structure

parent 565f305d
'use strict';
const open = require('opn');
const yargs = require('yargs').argv;
const settings = require('../../gulp/settings');
const chalk = require('chalk');
if (yargs._.length > 1) {
const config = settings.getConfig();
if (config.hasOwnProperty('open')) {
let sites = yargs._[1];
if (config.open.hasOwnProperty(sites)) {
let index = 0;
config.open[sites].forEach(site => {
setTimeout(() => {
open(site);
}, 100 * index++);
});
} else {
console.log(chalk.red(`The desired entry ${sites} could not be found in your .sgc-config.json!`));
}
} else {
console.log(chalk.red('You have currently no sites configured (set the "open" property inside your .sgc-config.json)!'));
}
} else {
console.log(chalk.red('Please specify which site you want to open!'));
}
......@@ -24,6 +24,7 @@ class Settings {
watch: () => {return require('./tasks/watch')},
server: () => {return require('./tasks/server')},
images: () => {return require('./tasks/images')},
open: () => {return require('./tasks/open')},
default: () => {return require('./tasks/default')}
};
}
......
const Task = require('../task');
const open = require('opn');
const yargs = require('yargs').argv;
const chalk = require('chalk');
/**
* Opens a defined URL in the default browser
*/
module.exports = class Open extends Task {
/**
* Runner function
*/
run() {
if (yargs._.length > 1) {
if (this._config.hasOwnProperty('open')) {
let sites = yargs._[1];
if (this._config.open.hasOwnProperty(sites)) {
let index = 0;
this._config.open[sites].forEach(site => {
setTimeout(() => {
open(site);
}, 100 * index++);
});
} else {
this._logger.error(`The desired entry ${chalk.bold(sites)} could not be found in your .sgc-config.json!`);
}
} else {
this._logger.error('You have currently no sites configured (set the "open" property inside your .sgc-config.json)!');
}
} else {
this._logger.error('Please specify which site you want to open!');
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment