Skip to content
This repository has been archived by the owner on Jul 16, 2022. It is now read-only.

Commit

Permalink
Merge feat/vue_cli_support
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain Lenzotti committed Aug 27, 2018
2 parents 923c3a2 + 0d38fc7 commit 6058061
Show file tree
Hide file tree
Showing 44 changed files with 4,928 additions and 1,923 deletions.
3 changes: 2 additions & 1 deletion .nycrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
],
"exclude": [
"**/index.js",
"packages/config/src/utils/format-path.js",
"packages/**/*.spec.js",
"packages/**/bin",
"packages/**/src/commands",
Expand All @@ -21,7 +22,7 @@
],
"check-coverage": true,
"lines": 99.3,
"functions": 96.4,
"functions": 94.87,
"branches": 84.48,
"statements": 98.03,
"all": true
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
},
"homepage": "https://github.com/NodeSitecore/sitecore-cli",
"devDependencies": {
"@vue/cli-service": "^3.0.1",
"@vue/cli-shared-utils": "^3.0.1",
"browser-sync": "^2.24.6",
"chai": "^4.1.2",
"chai-as-promised": "^7.1.1",
Expand Down
26 changes: 16 additions & 10 deletions packages/cli-plugin-browsersync/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,28 @@
* @param {Config} config
*/
module.exports = config => {
config.defineGetter('browserSync', () =>
config.resolve({
https: true,
port: 8001,
logLevel: 'debug',
urls: [],
...(config.get('browserSync') || {})
})
);

/**
*
* @param url
*/
config.defineMethod('pushProxyUrl', url => {
const { proxyUrls } = this;
config.defineMethod('setBSUrls', url => {
const { urls } = config.browserSync;

if (proxyUrls.indexOf(url) === -1) {
proxyUrls.push(url);
if (urls.indexOf(url) === -1) {
urls.push(url);
}

this.set('proxyUrls', proxyUrls);
this.save();
config.set('browserSync', { ...config.browserSync, urls });
config.save();
});
/**
*
*/
config.defineGetter('proxyUrls', () => config.get('proxyUrls') || []);
};
93 changes: 39 additions & 54 deletions packages/cli-plugin-browsersync/index.js
Original file line number Diff line number Diff line change
@@ -1,73 +1,58 @@
const inquirer = require('inquirer');
const log = require('fancy-log');
const proxyServer = require('./src/browser-sync');
const execa = require('execa');
const browserSync = require('./src/browser-sync');

module.exports = (api, config) => {
api.registerCommand(
'browsersync',
{
description: '',
usage: '[Feature|Foundation|Project|solution] [options]',
description: 'Run browsersync server and proxy a given server',
usage: '[options]',
options: {
'-p, --package <package>': {
description: 'Load a snippet for a given localization',
type: String
},
// '-p, --package <package>': {
// type: String,
// description: 'Load a snippet for a given localization',
// },

'-c, --concurrently <npm task>': {
description: 'Load a snippet for a given localization'
'-e, --execute <cmd>': {
description: 'Run command concurrently'
}
}
},
commander => {
runInteractive(commander);
const { urls } = config.browserSync;

function runInteractive(options) {
let questions;
return inquirer
.prompt([
{
type: 'list',
name: 'url',
message: 'Which url do you want to proxify ? ',
choices: urls.concat([new inquirer.Separator(), 'Enter new url']),
required: true
},
{
type: 'input',
name: 'url',
when: answers => answers.url === 'Enter new url',
message: 'Which url do you want to proxify ? ',
default: config.siteUrl,
required: true
}
])
.then(answers => {
config.setBSUrls(answers.url);

if (config.proxyUrls.length) {
questions = [
{
type: 'list',
name: 'proxyUrl',
message: 'Which url do you want to proxify ? ',
choices: config.proxyUrls.concat([new inquirer.Separator(), 'Enter new url']),
required: true
},
{
type: 'input',
name: 'proxyUrl',
when: answers => answers.proxyUrl === 'Enter new url',
message: 'Which url do you want to proxify ? ',
default: config.siteUrl,
required: true
}
];
} else {
questions = [
{
type: 'input',
name: 'proxyUrl',
message: 'Which url do you want to proxify ? ',
default: config.siteUrl,
required: true
}
];
}

return inquirer
.prompt(questions)
.then(answers => {
config.pushProxyUrl(answers.proxyUrl);

proxyServer({
url: answers.proxyUrl,
package: options.package,
concurrently: options.concurrently
if (commander.execute) {
execa.shell(commander.execute, {
stdio: 'inherit'
});
})
.catch(er => log.error(er));
}
}

browserSync(answers.url, config, {});
})
.catch(er => log.error(er));
}
);
};
41 changes: 11 additions & 30 deletions packages/cli-plugin-browsersync/package-lock.json

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

Loading

0 comments on commit 6058061

Please sign in to comment.