Skip to content

Commit 59fd5f0

Browse files
author
Halmen Istvan
committed
Proxy option fixes
1 parent ec93860 commit 59fd5f0

4 files changed

Lines changed: 48 additions & 36 deletions

File tree

changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Mobiscroll CLI changelog
22

3+
v 1.7.1 - 11 May 2022
4+
5+
* Fixed: We fixed the `--proxy` parameter to pass it down to the `npm` and `yarn` calls, so the config command runs, even if proxy options are not set in the npm/yarn config, or in the system environment variables.
6+
37
v 1.7.0 - 17 Nov 2021
48

59
* New: We added support for yarn 2+. The cli takes the npm auth token from the .npmrc file and creates .yarnrc.yml to make sure the mobiscroll install gets authenticated.

mobiscroll.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,13 @@ var startIoncVesrion = '';
3232

3333
process.env.HOME = process.env.HOME || ''; // fix npm-cli-login plugin on windows
3434

35-
function checkUpdate() {
35+
function checkUpdate(proxy) {
36+
let proxyParam = '';
37+
if (proxy) {
38+
proxyParam = ' --proxy ' + proxy;
39+
}
3640
return new Promise((resolve) => {
37-
run('npm show @mobiscroll/cli version', true, true, true).then((npmCliVersion) => { // get the mobiscroll cli version from npm
41+
run('npm show @mobiscroll/cli version' + proxyParam, true, true, true).then((npmCliVersion) => { // get the mobiscroll cli version from npm
3842

3943
if (npmCliVersion) {
4044
npmCliVersion = npmCliVersion.trim();
@@ -48,7 +52,7 @@ function checkUpdate() {
4852
default: 'y'
4953
}).then(answer => {
5054
if (answer.update.toLowerCase() == 'y') {
51-
run('npm install -g @mobiscroll/cli@latest').then(() => {
55+
run('npm install -g @mobiscroll/cli@latest' + proxyParam).then(() => {
5256
printFeedback(`Updated Mobiscroll CLI to ${npmCliVersion}! \n\nPlease re-run your command!\n`);
5357
process.exit();
5458
});
@@ -253,7 +257,7 @@ function askStyleSheetType(version, useScss, config, callback) {
253257
}
254258

255259
// only ask the scss install if the version is larger then 4.7.0
256-
if (semver.gte(version, '4.7.0') && useScss === undefined && !skipQuestion) {
260+
if (semver.gte(version, '4.7.0') && useScss === undefined && !skipQuestion) {
257261
let choices = ['CSS', 'SCSS'];
258262
console.log('\n');
259263
inquirer.prompt({
@@ -339,11 +343,11 @@ function createProject(type, name) {
339343
utils.testInstalledCLI('create-react-app --version', 'npm install -g create-react-app', 'npm start', name, type);
340344
});
341345
break;
342-
// case 'vue':
343-
// startProject('', type, name, () => {
344-
// utils.testInstalledCLI('vue -V', 'npm install -g @vue/cli', 'npm run serve', name, type);
345-
// });
346-
// break;
346+
// case 'vue':
347+
// startProject('', type, name, () => {
348+
// utils.testInstalledCLI('vue -V', 'npm install -g @vue/cli', 'npm run serve', name, type);
349+
// });
350+
// break;
347351
default:
348352
printWarning('No valid project type was specified. Currently the following project types are supported: [ angular, ionic, ionic-angular, ionic-react, react ]');
349353
break;
@@ -373,10 +377,10 @@ function handleConfig(projectType) {
373377
return;
374378
}
375379

376-
checkUpdate().then(() => {
380+
checkUpdate(proxyUrl).then(() => {
377381
var framework = projectType,
378-
jsFileName = `@mobiscroll/angular${ isLite ? '-lite' : '' }`,
379-
cssFileName = `../node_modules/@mobiscroll/angular${ isLite ? '-lite' : '' }/dist/css/mobiscroll.min.css`,
382+
jsFileName = `@mobiscroll/angular${isLite ? '-lite' : ''}`,
383+
cssFileName = `../node_modules/@mobiscroll/angular${isLite ? '-lite' : ''}/dist/css/mobiscroll.min.css`,
380384
currDir = process.cwd(), // get the directory where the mobiscroll command was executed
381385
packageJsonLocation = path.resolve(currDir, 'package.json'),
382386
packageJson = '';
@@ -478,7 +482,7 @@ function handleConfig(projectType) {
478482
}
479483

480484
if (!localJsFileName.length || !localCssFileName.length) {
481-
printWarning(`No mobiscroll js/css files were found in your project's src/lib/mobiscroll folder. \n\nPlease make sure to extract the downloaded Mobiscroll package, then grab the ${ framework == 'angular' ? 'lib folder and copy it into src folder of your app!' : 'js and css folders and copy it into src/lib/mobiscroll folder of your app. If there is no such folder available, you can create it.' }`);
485+
printWarning(`No mobiscroll js/css files were found in your project's src/lib/mobiscroll folder. \n\nPlease make sure to extract the downloaded Mobiscroll package, then grab the ${framework == 'angular' ? 'lib folder and copy it into src folder of your app!' : 'js and css folders and copy it into src/lib/mobiscroll folder of your app. If there is no such folder available, you can create it.'}`);
482486
return;
483487
}
484488

@@ -593,7 +597,7 @@ function handleConfig(projectType) {
593597
}
594598

595599
utils.writeToFile(packageJsonLocation, JSON.stringify(packageJson, null, 4), () => {
596-
console.log(`${chalk.green('>') + chalk.grey(' package.json')} modified to load mobiscroll from the generated package file. \n`);
600+
console.log(`${chalk.green('>') + chalk.grey(' package.json')} modified to load mobiscroll from the generated package file. \n`);
597601

598602
// run npm install
599603
utils.run((useYarn ? 'yarn add file:./src/lib/mobiscroll-package/' + packageName : 'npm install'), true).then(() => {
@@ -687,4 +691,4 @@ if (!program.args.length) {
687691
if (program.rawArgs.indexOf('-v') == -1) {
688692
program.help();
689693
}
690-
}
694+
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@mobiscroll/cli",
3-
"version": "1.7.0",
3+
"version": "1.7.1",
44
"description": "Mobiscroll command line configuration tool",
55
"homepage": "https://mobiscroll.com/",
66
"license": "Apache-2.0",
@@ -39,4 +39,4 @@
3939
"devDependencies": {
4040
"crlf": "^1.1.1"
4141
}
42-
}
42+
}

src/utils.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function processProxyUrl(url) {
3737
proxyObj.port = proxyHost[1];
3838
}
3939

40-
if(proxyAuth.length >= 3) {
40+
if (proxyAuth.length >= 3) {
4141
proxyObj.auth = {
4242
username: proxyAuth[1],
4343
password: proxyAuth[2]
@@ -71,7 +71,7 @@ function testYarn(currDir) {
7171
printLog('Testing yarn')
7272
const hasLockFile = fs.existsSync(path.resolve(currDir, 'yarn.lock'));
7373
const yarnVersion = runCommandSync('yarn -v', true);
74-
if (yarnVersion && hasLockFile ) {
74+
if (yarnVersion && hasLockFile) {
7575
printLog(`Yarn version: ${yarnVersion}`)
7676
return yarnVersion;
7777
}
@@ -260,11 +260,11 @@ function login(useGlobalNpmrc, proxy) {
260260
return new Promise((resolve, reject) => {
261261
inquirer.prompt(questions).then((answers) => {
262262
// Email address is not used by the Mobiscroll NPM registry
263-
npmLogin(answers.username, answers.password, 'any@any.com', mbscNpmUrl, '@mobiscroll', null, (useGlobalNpmrc ? undefined : path.resolve(process.cwd(), '.npmrc'))).then(() => {
263+
npmLogin(answers.username, answers.password, 'any@any.com', mbscNpmUrl, '@mobiscroll', null, (useGlobalNpmrc ? undefined : path.resolve(process.cwd(), '.npmrc')), proxy).then(() => {
264264
console.log(` Logged in as ${answers.username}`);
265265
printFeedback('Successful login!\n');
266266
resolve(answers.username);
267-
}, proxy).catch(err => {
267+
}).catch(err => {
268268
err = err.toString();
269269
if (err.indexOf("Could not find user with the specified username or password") !== -1 || err.indexOf("Incorrect username or password") !== -1) {
270270
printWarning(`We couldn’t log you in. This might be either because your account does not exist or you mistyped your login information. You can update your credentials ` + terminalLink('from your account', 'https://mobiscroll.com/account') + '.');
@@ -325,7 +325,7 @@ module.exports = {
325325
},
326326
installMobiscrollLite: function (framework, version, callback) {
327327
framework = (framework.indexOf('ionic') > -1 ? 'angular' : framework);
328-
runCommand(`npm install @mobiscroll/${framework}-lite@${ version || 'latest' } --save`, true).then(() => {
328+
runCommand(`npm install @mobiscroll/${framework}-lite@${version || 'latest'} --save`, true).then(() => {
329329
printFeedback(`The lite version of Mobiscroll for ${framework} installed.`);
330330
callback();
331331
});
@@ -372,7 +372,7 @@ module.exports = {
372372
checkMbscNpmLogin: (isTrial, useGlobalNpmrc, proxy, framework, installVersion, callback) => {
373373
printFeedback('Checking logged in status...');
374374
// check if the user is already logged in
375-
runCommand('npm whoami --registry=' + mbscNpmUrl, false, true).then((userName) => {
375+
runCommand('npm whoami --registry=' + mbscNpmUrl + (proxy ? ' --proxy ' + proxy : ''), false, true).then((userName) => {
376376
if (userName) {
377377
userName = userName.trim();
378378
console.log(` Logged in as ${userName}`);
@@ -453,13 +453,13 @@ module.exports = {
453453
if (mainVersion) {
454454
installVersion = version;
455455
}
456-
456+
457457
if (isYarn2) {
458458
// in case of yarn2 we need to copy the auth token form the .npmrc file to the .yarnrc.yml
459459
let data;
460460
const npmrcPath = path.resolve(currDir, '.npmrc');
461461
const ymlPath = path.resolve(currDir, '.yarnrc.yml');
462-
462+
463463

464464
try {
465465
if (fs.existsSync(ymlPath)) {
@@ -474,7 +474,7 @@ module.exports = {
474474
let AUTH_TOKEN = '';
475475
data = {};
476476
if (fs.existsSync(npmrcPath)) {
477-
const npmrcData = fs.readFileSync(npmrcPath, 'utf8').toString();
477+
const npmrcData = fs.readFileSync(npmrcPath, 'utf8').toString();
478478
const tokenRow = npmrcData.match(/\/\/npm.mobiscroll.com\/:_authToken=(.*)=$/mi);
479479

480480
if (tokenRow.length > 1) {
@@ -507,7 +507,11 @@ module.exports = {
507507
command = `${installCmd} ${mbscNpmUrl}/@mobiscroll/${pkgName}/-/${pkgName}-${installVersion || version}.tgz --save --registry=${mbscNpmUrl}`;
508508
}
509509
} else {
510-
command = `${installCmd} @mobiscroll/${pkgName}@${ installVersion || version } ${isYarn2 ? '' : ' --save'}`;
510+
command = `${installCmd} @mobiscroll/${pkgName}@${installVersion || version} ${isYarn2 ? '' : ' --save'}`;
511+
}
512+
513+
if (proxy) {
514+
command += ' --proxy ' + proxy;
511515
}
512516

513517
// Skip node warnings
@@ -525,7 +529,7 @@ module.exports = {
525529
process.chdir(packLocation); // change directory to node modules folder
526530
console.log(`${chalk.green('>')} changed current directory to ${packLocation}. \n`);
527531

528-
runCommand(`${ useYarn ? 'yarn pack' : 'npm pack'}`, true).then(() => { // run npm pack which will generate the mobiscroll package
532+
runCommand(`${useYarn ? 'yarn pack' : 'npm pack'}`, true).then(() => { // run npm pack which will generate the mobiscroll package
529533
fs.readdir(packLocation, function (err, files) {
530534
if (err) {
531535
printError('Could not access to the directory files.\n\n' + err);
@@ -558,14 +562,14 @@ module.exports = {
558562

559563
// Remove previous module load
560564
// if (checkForRoute) {
561-
const importRegex = /import \{ MbscModule(?:, mobiscroll)? \} from '[^']*';\s*/;
562-
if (importRegex.test(data)) {
563-
data = data.replace(importRegex, '');
564-
data = data.replace(/[ \t]*MbscModule,[ \t\r]*\s?/, '');
565-
}
565+
const importRegex = /import \{ MbscModule(?:, mobiscroll)? \} from '[^']*';\s*/;
566+
if (importRegex.test(data)) {
567+
data = data.replace(importRegex, '');
568+
data = data.replace(/[ \t]*MbscModule,[ \t\r]*\s?/, '');
569+
}
566570

567-
// Add angular module imports which are needed for mobiscroll
568-
data = importModule('MbscModule', mbscFileName, data);
571+
// Add angular module imports which are needed for mobiscroll
572+
data = importModule('MbscModule', mbscFileName, data);
569573
// }
570574
data = importModule('FormsModule', '@angular/forms', data);
571575

@@ -606,4 +610,4 @@ module.exports = {
606610
login,
607611
testYarn,
608612
appendContentToFile
609-
};
613+
};

0 commit comments

Comments
 (0)