-
Notifications
You must be signed in to change notification settings - Fork 431
feat(command-init): recommend build plugins #1836
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a26a7fc
feat(command-init): recommend build plugins
erezrokah 29c1975
feat: update plugins installation messages
erezrokah 687ba29
feat: use framework titles
erezrokah e3338e9
feat: pass nodeVersion to framework info
erezrokah 9c5e66a
feat: use plugins and framework names
erezrokah 381773d
test(command-init): add tests
erezrokah 5e6c013
refactor: add comment explaining chosing first framework
erezrokah d6cd872
fix: don't remove existing plugins
erezrokah c7aa88b
fix: add icons
erezrokah 697cb19
fix: don't add plugins to netlify.toml
erezrokah 23ddd67
fix: set defaut for multiple plugins list
erezrokah 9fa0fd8
chore: sync deps
erezrokah 7232b11
fix: update messages and fix tests
erezrokah d69403b
fix: revert command custom api host workaround
erezrokah 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,24 @@ | ||
| const { listFrameworks } = require('@netlify/framework-info') | ||
|
|
||
| const getFrameworkInfo = async ({ siteRoot, nodeVersion }) => { | ||
| const frameworks = await listFrameworks({ projectDir: siteRoot, nodeVersion }) | ||
| // several frameworks can be detected - first one has highest priority | ||
| if (frameworks.length !== 0) { | ||
| const [ | ||
| { | ||
| name, | ||
| build: { directory, commands }, | ||
| plugins, | ||
| }, | ||
| ] = frameworks | ||
| return { | ||
| frameworkName: name, | ||
| frameworkBuildCommand: commands[0], | ||
| frameworkBuildDir: directory, | ||
| frameworkPlugins: plugins, | ||
| } | ||
| } | ||
| return {} | ||
| } | ||
|
|
||
| module.exports = { getFrameworkInfo } | ||
This file contains hidden or 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,32 @@ | ||
| const { get } = require('dot-prop') | ||
| const locatePath = require('locate-path') | ||
| const nodeVersionAlias = require('node-version-alias') | ||
|
|
||
| const { readFileAsync } = require('../../lib/fs') | ||
|
|
||
| const DEFAULT_NODE_VERSION = '12.18.0' | ||
| const NVM_FLAG_PREFIX = '--' | ||
|
|
||
| // to support NODE_VERSION=--lts, etc. | ||
| const normalizeConfiguredVersion = (version) => | ||
| version.startsWith(NVM_FLAG_PREFIX) ? version.slice(NVM_FLAG_PREFIX.length) : version | ||
|
|
||
| const detectNodeVersion = async ({ siteRoot, env, warn }) => { | ||
| try { | ||
| const nodeVersionFile = await locatePath(['.nvmrc', '.node-version'], { cwd: siteRoot }) | ||
| const configuredVersion = | ||
| nodeVersionFile === undefined ? get(env, 'NODE_VERSION.value') : await readFileAsync(nodeVersionFile, 'utf8') | ||
|
|
||
| const version = | ||
| configuredVersion === undefined | ||
| ? DEFAULT_NODE_VERSION | ||
| : await nodeVersionAlias(normalizeConfiguredVersion(configuredVersion)) | ||
|
|
||
| return version | ||
| } catch (error) { | ||
| warn(`Failed detecting Node.js version: ${error.message}`) | ||
| return DEFAULT_NODE_VERSION | ||
| } | ||
| } | ||
|
|
||
| module.exports = { detectNodeVersion } |
This file contains hidden or 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,36 @@ | ||
| const pluginsList = require('@netlify/plugins-list') | ||
| const fetch = require('node-fetch') | ||
|
|
||
| const PLUGINS_LIST_URL = 'https://netlify-plugins.netlify.app/plugins.json' | ||
| // 1 minute | ||
| const PLUGINS_LIST_TIMEOUT = 6e4 | ||
|
|
||
| const getPluginsList = async () => { | ||
| try { | ||
| const response = await fetch(PLUGINS_LIST_URL, { timeout: PLUGINS_LIST_TIMEOUT }) | ||
| return await response.json() | ||
| } catch { | ||
| return pluginsList | ||
| } | ||
| } | ||
|
|
||
| const getPluginInfo = (list, packageName) => list.find(({ package }) => package === packageName) | ||
|
|
||
| const isPluginInstalled = (configPlugins, plugin) => | ||
| configPlugins.some(({ package: configPlugin }) => configPlugin === plugin) | ||
|
|
||
| const getRecommendPlugins = (frameworkPlugins, config) => | ||
| frameworkPlugins.filter((plugin) => !isPluginInstalled(config.plugins, plugin)) | ||
|
|
||
| const getPluginsToInstall = ({ plugins, installSinglePlugin, recommendedPlugins }) => { | ||
| if (Array.isArray(plugins)) { | ||
| return plugins.map((plugin) => ({ package: plugin })) | ||
| } | ||
|
|
||
| return installSinglePlugin === true ? [{ package: recommendedPlugins[0] }] : [] | ||
| } | ||
|
|
||
| const getUIPlugins = (configPlugins) => | ||
| configPlugins.filter(({ origin }) => origin === 'ui').map(({ package }) => ({ package })) | ||
|
|
||
| module.exports = { getPluginsList, getPluginInfo, getRecommendPlugins, getPluginsToInstall, getUIPlugins } |
This file contains hidden or 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
Oops, something went wrong.
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.
Are we only considering the first element of the array on purpose (i.e. the
framework-infolib is only returning one framework for the time being)?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.
It might detect a few frameworks - the first one has higher priority based on the order in https://github.com/netlify/framework-info/blob/32c58bb8de2f86874a61bdc7abab059c4c638f6c/src/frameworks/main.js#L4.
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.
I wouldn't mind having a comment here just highlighting that (we pick the first as its the highest priority). Not critical though, happy to move forward if you feel like it doesn't make sense @erezrokah 👍
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.
That makes sense. I'll add it
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.
Done in e1a410e