Skip to content
This repository was archived by the owner on Oct 20, 2023. It is now read-only.

Commit 1fe4844

Browse files
committed
fix: automatically install with npm if Yarn isn’t available
Closes #5
1 parent 9e382eb commit 1fe4844

File tree

4 files changed

+75
-19
lines changed

4 files changed

+75
-19
lines changed

generators/app/index.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const Generator = require('yeoman-generator');
33
const chalk = require('chalk');
44
const yosay = require('yosay');
55
const superb = require('superb');
6+
const commandExists = require('command-exists').sync;
67
const helper = require('./promptingHelpers');
78

89
module.exports = class extends Generator {
@@ -127,22 +128,18 @@ module.exports = class extends Generator {
127128
}
128129

129130
install() {
131+
const hasYarn = commandExists('yarn');
130132
this.installDependencies({
131-
npm: false,
133+
npm: !hasYarn,
132134
bower: false,
133-
yarn: true,
134-
callback: error => {
135-
if (error) {
136-
this.log('… or alternatively run ' +
137-
chalk.yellow('npm install') +
138-
' instead.');
139-
} else {
140-
this.log(yosay(`
141-
That’s it. Feel free to fire up the server with ${chalk.green('npm run start:dev')}
142-
or use our subgenerator to create endpoints.
143-
`));
144-
}
145-
}
135+
yarn: hasYarn
146136
});
147137
}
138+
139+
end() {
140+
this.log(yosay(`
141+
That’s it. Feel free to fire up the server with ${chalk.green('npm run start:dev')}
142+
or use our subgenerator to create endpoints: ${chalk.yellow('yo http-fake-backend:endpoint')}
143+
`, {maxLength: 40}));
144+
}
148145
};

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
],
3333
"dependencies": {
3434
"chalk": "2.0.1",
35+
"command-exists": "^1.2.2",
3536
"superb": "1.3.0",
3637
"title-case": "^2.1.1",
3738
"yeoman-generator": "^1.1.1",

yarn.lock

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ combined-stream@^1.0.5, combined-stream@~1.0.5:
411411
dependencies:
412412
delayed-stream "~1.0.0"
413413

414+
command-exists@^1.2.2:
415+
version "1.2.2"
416+
resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.2.tgz#12819c64faf95446ec0ae07fe6cafb6eb3708b22"
417+
414418
commander@2.9.0:
415419
version "2.9.0"
416420
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4"
@@ -457,7 +461,7 @@ create-error-class@^3.0.0:
457461
dependencies:
458462
capture-stack-trace "^1.0.0"
459463

460-
cross-spawn@^5.0.1:
464+
cross-spawn@^5.0.1, cross-spawn@^5.1.0:
461465
version "5.1.0"
462466
resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449"
463467
dependencies:
@@ -649,7 +653,7 @@ eslint-scope@^3.7.1:
649653
esrecurse "^4.1.0"
650654
estraverse "^4.1.1"
651655

652-
eslint@^4.0.0, eslint@^4.2.0:
656+
eslint@^4.0.0:
653657
version "4.2.0"
654658
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.2.0.tgz#a2b3184111b198e02e9c7f3cca625a5e01c56b3d"
655659
dependencies:
@@ -687,6 +691,47 @@ eslint@^4.0.0, eslint@^4.2.0:
687691
table "^4.0.1"
688692
text-table "~0.2.0"
689693

694+
eslint@^4.3.0:
695+
version "4.3.0"
696+
resolved "https://registry.yarnpkg.com/eslint/-/eslint-4.3.0.tgz#fcd7c96376bbf34c85ee67ed0012a299642b108f"
697+
dependencies:
698+
ajv "^5.2.0"
699+
babel-code-frame "^6.22.0"
700+
chalk "^1.1.3"
701+
concat-stream "^1.6.0"
702+
cross-spawn "^5.1.0"
703+
debug "^2.6.8"
704+
doctrine "^2.0.0"
705+
eslint-scope "^3.7.1"
706+
espree "^3.4.3"
707+
esquery "^1.0.0"
708+
estraverse "^4.2.0"
709+
esutils "^2.0.2"
710+
file-entry-cache "^2.0.0"
711+
functional-red-black-tree "^1.0.1"
712+
glob "^7.1.2"
713+
globals "^9.17.0"
714+
ignore "^3.3.3"
715+
imurmurhash "^0.1.4"
716+
inquirer "^3.0.6"
717+
is-resolvable "^1.0.0"
718+
js-yaml "^3.8.4"
719+
json-stable-stringify "^1.0.1"
720+
levn "^0.3.0"
721+
lodash "^4.17.4"
722+
minimatch "^3.0.2"
723+
mkdirp "^0.5.1"
724+
natural-compare "^1.4.0"
725+
optionator "^0.8.2"
726+
path-is-inside "^1.0.2"
727+
pluralize "^4.0.0"
728+
progress "^2.0.0"
729+
require-uncached "^1.0.3"
730+
semver "^5.3.0"
731+
strip-json-comments "~2.0.1"
732+
table "^4.0.1"
733+
text-table "~0.2.0"
734+
690735
espree@^3.4.3:
691736
version "3.4.3"
692737
resolved "https://registry.yarnpkg.com/espree/-/espree-3.4.3.tgz#2910b5ccd49ce893c2ffffaab4fd8b3a31b82374"
@@ -935,6 +980,10 @@ fs.realpath@^1.0.0:
935980
version "1.0.0"
936981
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
937982

983+
functional-red-black-tree@^1.0.1:
984+
version "1.0.1"
985+
resolved "https://registry.yarnpkg.com/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz#1b0ab3bd553b2a0d6399d29c0e3ea0b252078327"
986+
938987
gaze@^0.5.1:
939988
version "0.5.2"
940989
resolved "https://registry.yarnpkg.com/gaze/-/gaze-0.5.2.tgz#40b709537d24d1d45767db5a908689dfe69ac44f"
@@ -2774,6 +2823,10 @@ semver@^4.1.0:
27742823
version "4.3.6"
27752824
resolved "https://registry.yarnpkg.com/semver/-/semver-4.3.6.tgz#300bc6e0e86374f7ba61068b5b1ecd57fc6532da"
27762825

2826+
semver@^5.3.0:
2827+
version "5.4.1"
2828+
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"
2829+
27772830
semver@~5.0.1:
27782831
version "5.0.3"
27792832
resolved "https://registry.yarnpkg.com/semver/-/semver-5.0.3.tgz#77466de589cd5d3c95f138aa78bc569a3cb5d27a"
@@ -3454,9 +3507,9 @@ yeoman-test@1.7.0:
34543507
yeoman-environment "^2.0.0"
34553508
yeoman-generator "^1.1.0"
34563509

3457-
yosay@^2.0.0:
3458-
version "2.0.0"
3459-
resolved "https://registry.yarnpkg.com/yosay/-/yosay-2.0.0.tgz#0f3d2bb01f7f25362c127212f53c1572906333fe"
3510+
yosay@^2.0.1:
3511+
version "2.0.1"
3512+
resolved "https://registry.yarnpkg.com/yosay/-/yosay-2.0.1.tgz#078167f0365732e5c82d3f64633f9cd3a0526d2f"
34603513
dependencies:
34613514
ansi-regex "^2.0.0"
34623515
ansi-styles "^3.0.0"

0 commit comments

Comments
 (0)