Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added the option to choose between npm/yarn on the templates that install dependencies #133

Merged
merged 1 commit into from
Oct 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,31 @@ module.exports = class extends Generator {
}).then(idAnswer => {
generator.extensionConfig.languageId = idAnswer.languageId;
});
}
},

askForPackageManager: () => {
if (['ext-command-ts', 'ext-command-js', 'ext-localization'].indexOf(generator.extensionConfig.type) === -1) {
return Promise.resolve();
}
generator.extensionConfig.pkgManager = 'npm';
return generator.prompt({
type: 'list',
name: 'pkgManager',
message: 'Which package manager to use?',
choices: [
{
name: 'npm',
value: 'npm'
},
{
name: 'yarn',
value: 'yarn'
}
]
}).then(pckgManagerAnswer => {
generator.extensionConfig.pkgManager = pckgManagerAnswer.pkgManager;
});
},
};

// run all prompts in sequence. Results can be ignored.
Expand Down Expand Up @@ -717,7 +741,8 @@ module.exports = class extends Generator {

if (this.extensionConfig.installDependencies) {
this.installDependencies({
npm: true,
yarn: this.extensionConfig.pkgManager === 'yarn',
npm: this.extensionConfig.pkgManager === 'npm',
bower: false
});
}
Expand Down
4 changes: 2 additions & 2 deletions generators/app/templates/ext-command-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
}]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"vscode:prepublish": "<%= pkgManager %> run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
"test": "<%= pkgManager %> run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"typescript": "^2.6.1",
Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/ext-localization/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
}]
},
"scripts": {
"update": "cd ../vscode && npm run update-localization-extension <%- lpLanguageId %>"
"update": "cd ../vscode && <%= pkgManager %> run update-localization-extension <%- lpLanguageId %>"
}
}
72 changes: 63 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,8 @@ describe('test code generator', function () {
publisher: 'Microsoft',
strictTypeScript: false,
tslint: false,
gitInit: true
gitInit: true,
pkgManager: 'npm'
}) // Mock the prompt answers
.toPromise().then(function () {
var expected = {
Expand Down Expand Up @@ -687,7 +688,7 @@ describe('test code generator', function () {
});
});

it('command-ts with tslint', function (done) {
it('command-ts with tslint and yarn', function (done) {
this.timeout(10000);

helpers.run(path.join(__dirname, '../generators/app'))
Expand All @@ -699,7 +700,8 @@ describe('test code generator', function () {
publisher: 'Microsoft',
strictTypeScript: false,
tslint: true,
gitInit: false
gitInit: false,
pkgManager: 'yarn'
}) // Mock the prompt answers
.toPromise().then(function () {
var expected = {
Expand All @@ -723,11 +725,11 @@ describe('test code generator', function () {
},
"main": "./out/extension",
"scripts": {
"vscode:prepublish": "npm run compile",
"vscode:prepublish": "yarn run compile",
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "npm run compile && node ./node_modules/vscode/bin/test"
"test": "yarn run compile && node ./node_modules/vscode/bin/test"
},
"categories": [
"Other"
Expand Down Expand Up @@ -767,7 +769,8 @@ describe('test code generator', function () {
publisher: 'Microsoft',
strictTypeScript: true,
tslint: false,
gitInit: false
gitInit: false,
pkgManager: 'npm'
}) // Mock the prompt answers
.toPromise().then(function () {
var expected = {
Expand Down Expand Up @@ -812,7 +815,8 @@ describe('test code generator', function () {
description: 'My TestCom',
publisher: 'Microsoft',
checkJavaScript: false,
gitInit: false
gitInit: false,
pkgManager: 'npm'
}) // Mock the prompt answers
.toPromise().then(function () {
var expected = {
Expand Down Expand Up @@ -877,7 +881,8 @@ describe('test code generator', function () {
description: 'My TestCom',
publisher: 'Microsoft',
checkJavaScript: true,
gitInit: false
gitInit: false,
pkgManager: 'yarn'
}) // Mock the prompt answers
.toPromise().then(function () {
var expected = {
Expand Down Expand Up @@ -956,7 +961,8 @@ describe('test code generator', function () {
lpLanguageId: 'ru',
lpLanguageName: 'Russian',
lpLocalizedLanguageName: 'русский',
publisher: 'Microsoft'
publisher: 'Microsoft',
pkgManager: 'npm'
}).toPromise().then(function () {
var expected = {
"name": "vscode-language-pack-ru",
Expand Down Expand Up @@ -995,4 +1001,52 @@ describe('test code generator', function () {
}
}, done);
});

it('language pack with yarn', function (done) {
helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({
type: 'ext-localization',
lpLanguageId: 'ru',
lpLanguageName: 'Russian',
lpLocalizedLanguageName: 'русский',
publisher: 'Microsoft',
pkgManager: 'yarn'
}).toPromise().then(function () {
var expected = {
"name": "vscode-language-pack-ru",
"displayName": "Russian Language Pack",
"description": "Language pack extension for Russian",
"version": "0.0.1",
"publisher": 'Microsoft',
"engines": {
"vscode": engineVersion
},
"categories": [
"Language Packs"
],
"contributes": {
"localizations": [{
"languageId": "ru",
"languageName": "Russian",
"localizedLanguageName": "русский"
}]
},
"scripts": {
"update": "cd ../vscode && yarn run update-localization-extension ru"
}
};
try {
assert.file(['package.json', 'README.md', 'CHANGELOG.md', 'vsc-extension-quickstart.md', '.gitignore', '.gitattributes', '.vscodeignore']);

var body = fs.readFileSync('package.json', 'utf8');

var actual = JSON.parse(body);
assert.deepEqual(expected, actual);

done();
} catch (e) {
done(e);
}
}, done);
});
});