Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
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
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const { listFrameworks, hasFramework, getFramework } = require('@netlify/framewo
console.log(await listFrameworks({ projectDir: './path/to/gatsby/website' }))
// [
// {
// name: 'gatsby',
// id: 'gatsby',
// title: 'Gatsby',
// category: 'static_site_generator',
// dev: {
Expand All @@ -44,7 +44,7 @@ console.log(await listFrameworks({ projectDir: './path/to/gatsby/website' }))
console.log(await listFrameworks({ projectDir: './path/to/vue/website' }))
// [
// {
// name: 'vue',
// id: 'vue',
// title: 'Vue.js',
// category: 'frontend_framework',
// dev: {
Expand All @@ -65,7 +65,7 @@ console.log(await hasFramework('vue', { projectDir: './path/to/vue/website' }))

console.log(await getFramework('vue', { projectDir: './path/to/vue/website' }))
// {
// name: 'vue',
// id: 'vue',
// title: 'Vue.js',
// category: 'frontend_framework',
// dev: {
Expand All @@ -90,7 +90,7 @@ gatsby
$ framework-info --long ./path/to/vue/website
[
{
"name": "vue",
"id": "vue",
"title": 'Vue.js',
"category": "frontend_framework",
"dev": {
Expand Down Expand Up @@ -136,11 +136,11 @@ single object or several objects.

Each object has the following properties.

#### name
#### id

_Type_: `string`

Name such as `"gatsby"`.
Id such as `"gatsby"`.

## title

Expand Down Expand Up @@ -202,14 +202,14 @@ _Type_: `string[]`

A list of recommend Netlify build plugins to install for the framework.

## hasFramework(frameworkName, options?)
## hasFramework(frameworkId, options?)

`options`: `object?`\
_Return value_: `Promise<boolean>`

Same as [`listFramework()`](#listframeworksoptions) except only for a specific framework and returns a boolean.

## getFramework(frameworkName, options?)
## getFramework(frameworkId, options?)

`options`: `object?`\
_Return value_: `Promise<object>`
Expand All @@ -223,7 +223,7 @@ detected. A single framework object is returned.
$ framework-info [projectDirectory]
```

This prints the names of each framework.
This prints the ids of each framework.

If known is found, `unknown` is printed.

Expand All @@ -237,7 +237,7 @@ Each framework is a JSON file in the `/src/frameworks/` directory. For example:

```json
{
"name": "gatsby",
"id": "gatsby",
"title": "Gatsby",
"category": "static_site_generator",
"detect": {
Expand All @@ -260,11 +260,11 @@ Each framework is a JSON file in the `/src/frameworks/` directory. For example:

All properties are required.

## name
## id

_Type_: `string`

Name of the framework, lowercase.
Id of the framework.

## title

Expand Down
2 changes: 1 addition & 1 deletion site/react/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ export const App = () => {
}
}, [])

return frameworks.map((framework) => <Framework key={framework.name} {...framework} />)
return frameworks.map((framework) => <Framework key={framework.id} {...framework} />)
}
2 changes: 1 addition & 1 deletion site/vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
const body = document.querySelector('body')
frameworks.forEach((framework) => {
const div = document.createElement('div')
div.setAttribute('id', framework.name)
div.setAttribute('id', framework.id)
// eslint-disable-next-line fp/no-mutation
div.textContent = JSON.stringify(framework)
body.append(div)
Expand Down
6 changes: 1 addition & 5 deletions src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ const serializeFrameworks = function (frameworks, long) {
return NO_FRAMEWORKS
}

return frameworks.map((framework) => getName(framework)).join('\n')
return frameworks.map(({ id }) => id).join('\n')
}

const NO_FRAMEWORKS = 'unknown'

const getName = function ({ name }) {
return name
}

runCli()
30 changes: 15 additions & 15 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const getContext = (context) => {

/**
* @typedef {object} Framework
* @property {string} name - framework name such as `"gatsby"`
* @property {string} id - framework id such as `"gatsby"`
* @property {string} title - framework title as `"Gatsby"`
* @property {string} category - Category among `"static_site_generator"`, `"frontend_framework"` and `"build_tool"`
* @property {Dev} dev - Information about the dev command
Expand Down Expand Up @@ -75,13 +75,13 @@ const listFrameworks = async function (context) {
/**
* Return whether a project uses a specific framework
*
* @param {string} frameworkName - Name such as `"gatsby"`
* @param {string} frameworkId - Id such as `"gatsby"`
* @param {Context} [context] - Context
*
* @returns {boolean} result - Whether the project uses this framework
*/
const hasFramework = async function (frameworkName, context) {
const framework = getFrameworkByName(frameworkName)
const hasFramework = async function (frameworkId, context) {
const framework = getFrameworkById(frameworkId)
const { pathExists, packageJson, packageJsonPath } = getContext(context)
const { npmDependencies } = await getProjectInfo({ pathExists, packageJson, packageJsonPath })
const result = await usesFramework(framework, { pathExists, npmDependencies })
Expand All @@ -91,13 +91,13 @@ const hasFramework = async function (frameworkName, context) {
/**
* Return some information about a framework used by a project.
*
* @param {string} frameworkName - Name such as `"gatsby"`
* @param {string} frameworkId - Id such as `"gatsby"`
* @param {Context} [context] - Context
*
* @returns {Framework} framework - Framework used by a project
*/
const getFramework = async function (frameworkName, context) {
const framework = getFrameworkByName(frameworkName)
const getFramework = async function (frameworkId, context) {
const framework = getFrameworkById(frameworkId)
const { pathExists, packageJson, packageJsonPath, nodeVersion } = getContext(context)
const { scripts, runScriptCommand } = await getProjectInfo({
pathExists,
Expand All @@ -108,17 +108,17 @@ const getFramework = async function (frameworkName, context) {
return frameworkInfo
}

const getFrameworkByName = function (frameworkName) {
const framework = FRAMEWORKS.find(({ name }) => name === frameworkName)
const getFrameworkById = function (frameworkId) {
const framework = FRAMEWORKS.find(({ id }) => id === frameworkId)
if (framework === undefined) {
const frameworkNames = FRAMEWORKS.map((knownFramework) => getFrameworkName(knownFramework)).join(', ')
throw new Error(`Invalid framework "${frameworkName}". It should be one of: ${frameworkNames}`)
const frameworkIds = FRAMEWORKS.map((knownFramework) => getFrameworkId(knownFramework)).join(', ')
throw new Error(`Invalid framework "${frameworkId}". It should be one of: ${frameworkIds}`)
}
return framework
}

const getFrameworkName = function ({ name }) {
return name
const getFrameworkId = function ({ id }) {
return id
}

const getProjectInfo = async function ({ pathExists, packageJson, packageJsonPath }) {
Expand All @@ -131,7 +131,7 @@ const getProjectInfo = async function ({ pathExists, packageJson, packageJsonPat

const getFrameworkInfo = function (
{
name,
id,
title,
category,
dev: { command: frameworkDevCommand, port },
Expand All @@ -144,7 +144,7 @@ const getFrameworkInfo = function (
const devCommands = getDevCommands({ frameworkDevCommand, scripts, runScriptCommand })
const recommendedPlugins = getPlugins(plugins, { nodeVersion })
return {
name,
id,
title,
category,
dev: { commands: devCommands, port },
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/angular.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "angular",
"id": "angular",
"title": "Angular",
"category": "frontend_framework",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/assemble.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "assemble",
"id": "assemble",
"title": "Assemble",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/brunch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "brunch",
"id": "brunch",
"title": "Brunch",
"category": "build_tool",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/create-react-app.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "create-react-app",
"id": "create-react-app",
"title": "Create React App",
"category": "frontend_framework",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/docpad.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "docpad",
"id": "docpad",
"title": "DocPad",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/docusaurus-v2.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "docusaurus-v2",
"id": "docusaurus-v2",
"title": "Docusaurus 2",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/docusaurus.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "docusaurus",
"id": "docusaurus",
"title": "Docusaurus",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/eleventy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "eleventy",
"id": "eleventy",
"title": "Eleventy",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/ember.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ember",
"id": "ember",
"title": "Ember.js",
"category": "frontend_framework",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/expo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "expo",
"id": "expo",
"title": "Expo",
"category": "frontend_framework",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/gatsby.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "gatsby",
"id": "gatsby",
"title": "Gatsby",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/gridsome.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "gridsome",
"id": "gridsome",
"title": "Gridsome",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/grunt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "grunt",
"id": "grunt",
"title": "Grunt",
"category": "build_tool",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/gulp.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "gulp",
"id": "gulp",
"title": "gulp.js",
"category": "build_tool",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/harp.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "harp",
"id": "harp",
"title": "Harp",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/hexo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "hexo",
"id": "hexo",
"title": "Hexo",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/hugo.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "hugo",
"id": "hugo",
"title": "Hugo",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/jekyll.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "jekyll",
"id": "jekyll",
"title": "Jekyll",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/metalsmith.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "metalsmith",
"id": "metalsmith",
"title": "Metalsmith",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/middleman.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "middleman",
"id": "middleman",
"title": "Middleman",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/next.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "next",
"id": "next",
"title": "Next.js",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/nuxt.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "nuxt",
"id": "nuxt",
"title": "Next.js",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/parcel.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "parcel",
"id": "parcel",
"title": "Parcel",
"category": "build_tool",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/phenomic.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "phenomic",
"id": "phenomic",
"title": "Phenomic",
"category": "static_site_generator",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/quasar-v0.17.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "quasar-v0.17",
"id": "quasar-v0.17",
"title": "Quasar",
"category": "frontend_framework",
"detect": {
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks/quasar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "quasar",
"id": "quasar",
"title": "Quasar",
"category": "frontend_framework",
"detect": {
Expand Down
Loading