-
-
Notifications
You must be signed in to change notification settings - Fork 375
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
feature: yarn install (through a flag) #225
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c7c8231
feature: yarn install (through a flag)
reznord 38f0b3f
eslint error fix, tests - partial fix [skip ci]
reznord 35fe515
Rename: src/lib/install-dependencies.js -> src/lib/setup.js
reznord d8c5e92
Merge branch 'master' into feature/yarn-support
reznord c361431
Merge branch 'master' into feature/yarn-support
reznord 903356b
Merge branch 'master' into feature/yarn-support
reznord 8676035
Update dependency-install-loader.js
developit a0624ef
Check for yarn.lock while isntalling
reznord File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import spawn from 'cross-spawn-promise'; | ||
import { commandExists } from './shell'; | ||
|
||
const initialize = async (yarn, cwd) => { | ||
let isYarnAvailable = await commandExists('yarn'); | ||
|
||
if (isYarnAvailable && yarn) { | ||
return await spawn('yarn', ['init', '-y'], { cwd, stdio: 'ignore' }); | ||
} | ||
|
||
await spawn('npm', ['init', '-y'], { cwd, stdio: 'ignore' }); | ||
}; | ||
|
||
const install = async (yarn, cwd, packages, env) => { | ||
let isDev = env === 'dev' ? true : false; | ||
let isYarnAvailable = await commandExists('yarn'); | ||
let toInstall = packages.filter(Boolean); | ||
|
||
if (isYarnAvailable && yarn) { | ||
let args = ['add']; | ||
if (isDev) { | ||
args.push('-D'); | ||
} | ||
|
||
return await spawn('yarn', [...args, ...toInstall], { cwd, stdio: 'ignore' }); | ||
} | ||
|
||
await spawn('npm', ['install', isDev ? '--save-dev' : '--save', ...toInstall], { cwd, stdio: 'ignore' }); | ||
}; | ||
|
||
const pkgScripts = async (yarn, pkg) => { | ||
let isYarnAvailable = await commandExists('yarn'); | ||
|
||
if (isYarnAvailable && yarn) { | ||
return { | ||
...(pkg.scripts || {}), | ||
start: 'if-env NODE_ENV=production && yarnpkg -s serve || yarnpkg -s dev', | ||
build: 'preact build', | ||
serve: 'preact build && preact serve', | ||
dev: 'preact watch', | ||
test: 'eslint src && preact test' | ||
}; | ||
} | ||
|
||
return { | ||
...(pkg.scripts || {}), | ||
start: 'if-env NODE_ENV=production && npm run -s serve || npm run -s dev', | ||
build: 'preact build', | ||
serve: 'preact build && preact serve', | ||
dev: 'preact watch', | ||
test: 'eslint src && preact test' | ||
}; | ||
}; | ||
|
||
export { install, initialize, pkgScripts }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import promisify from 'es6-promisify'; | ||
import which from 'which'; | ||
|
||
const commandExists = async cmd => { | ||
try { | ||
await promisify(which)(cmd); | ||
return true; | ||
} catch (e){ | ||
return false; | ||
} | ||
}; | ||
|
||
export { commandExists }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to allow yarn here if it's installed? We could check for a
yarn.lock
as an indication of whether the current repo is set up with yarn.