Socket
Socket
Sign inDemoInstall

@netlify/framework-info

Package Overview
Dependencies
7
Maintainers
12
Versions
93
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@netlify/framework-info


Version published
Maintainers
12
Install size
1.22 MB
Created

Package description

What is @netlify/framework-info?

@netlify/framework-info is an npm package designed to provide information about various web frameworks. It helps in detecting the framework used in a project and provides relevant details, which can be useful for deployment and configuration purposes.

What are @netlify/framework-info's main functionalities?

Detect Framework

This feature allows you to detect the framework used in a given project directory. The `getFramework` function returns details about the detected framework, such as its name and version.

const { getFramework } = require('@netlify/framework-info');

async function detectFramework() {
  const framework = await getFramework({
    projectDir: process.cwd(),
  });
  console.log(framework);
}

detectFramework();

List All Frameworks

This feature provides a list of all frameworks that the package can detect. The `listFrameworks` function returns an array of framework objects, each containing details like name, category, and detection criteria.

const { listFrameworks } = require('@netlify/framework-info');

async function listAllFrameworks() {
  const frameworks = await listFrameworks();
  console.log(frameworks);
}

listAllFrameworks();

Other packages similar to @netlify/framework-info

Readme

Source

npm version Coverage Status Build Downloads

Framework detection utility.

Detects which framework a specific website is using. The framework's build/watch commands, directories and server port are also returned.

The following frameworks are detected:

  • Static site generators: Gatsby, Hugo, Jekyll, Next.js, Nuxt, Hexo, Gridsome, Docusaurus, Eleventy, Middleman, Phenomic, React-static, Stencil, Vuepress
  • Front-end frameworks: create-react-app, Vue, Sapper, Angular, Ember, Svelte, Expo, Quasar
  • Build tools: Parcel, Brunch

Additions and updates are welcome!

Example (Node.js)

const { listFrameworks, getFramework } = require('@netlify/framework-info')

console.log(await listFrameworks({ projectDir: './path/to/gatsby/website' }))
// [
//   {
//     name: 'gatsby',
//     category: 'static_site_generator',
//     watch: {
//       commands: ['gatsby develop'],
//       directory: 'public',
//       port: 8000
//     },
//     env: { GATSBY_LOGGER: 'yurnalist' }
//   }
// ]

console.log(await listFrameworks({ projectDir: './path/to/vue/website' }))
// [
//   {
//     name: 'vue',
//     category: 'frontend_framework',
//     watch: {
//       commands: ['npm run serve'],
//       directory: 'dist',
//       port: 8080
//     },
//     env: {}
//   }
// ]

console.log(await getFramework('vue', { projectDir: './path/to/vue/website' }))
// {
//   name: 'vue',
//   category: 'frontend_framework',
//   watch: {
//     commands: ['npm run serve'],
//     directory: 'dist',
//     port: 8080
//   },
//   env: {}
// }

Example (CLI)

$ framework-info ./path/to/gatsby/website
gatsby

$ framework-info --long ./path/to/vue/website
[
  {
    "name": "vue",
    "category": "frontend_framework",
    "watch": {
      "commands": ["npm run serve"],
      "directory": "dist",
      "port": 8080
    },
    "env": {}
  }
]

Installation

npm install @netlify/framework-info

Usage (Node.js)

listFrameworks(options?)

options: object?
Return value: Promise<object[]>

Options

projectDir

Type: string
Default value: process.cwd()

Path to the website's directory.

ignoredWatchCommand

Type: string

When detecting the watch command, ignore package.json scripts whose value includes this string.

Return value

This returns a Promise resolving to an array of objects describing each framework. The array can be empty, contain a single object or several objects.

Each object has the following properties.

name

Type: string

Name such as "gatsby".

category

Type: string

Category among "static_site_generator", "frontend_framework" and "build_tool".

watch

Type: object

Information about the build command, in watch mode.

commands

Type: string[]

Build command, in watch mode. There might be several alternatives.

directory

Type: string

Relative path to the directory where files are built, in watch mode.

port

Type: number

Server port.

env

Type: object

Environment variables that should be set when calling the watch command.

getFramework(frameworkName, options?)

options: object?
Return value: Promise<object>

Same as listFramework() except the framework is passed as argument instead of being detected. A single framework object is returned.

Usage (CLI)

$ framework-info [projectDirectory]

This prints the names of each framework.

If known is found, unknown is printed.

Available flags:

  • --long: Show more information about each framework. The output will be a JSON array.
  • --ignoredWatchCommand string

Add or update a framework

Each framework is a JSON file in the /src/frameworks/ directory. For example:

{
  "name": "gatsby",
  "category": "static_site_generator",
  "detect": {
    "npmDependencies": ["gatsby"],
    "excludedNpmDependencies": [],
    "configFiles": ["gatsby-config.js"]
  },
  "watch": {
    "command": "gatsby develop",
    "directory": "public",
    "port": 8000
  },
  "env": { "GATSBY_LOGGER": "yurnalist" }
}

All properties are required.

name

Type: string

Name of the framework, lowercase.

category

Type: string

One of "static_site_generator", "frontend_framework" or "build_tool".

detect

Type: object

Information used to detect this framework

npmDependencies

Type: string[]

Framework's npm packages. Any project with one of those packages in their package.json (dependencies or devDependencies) will be considered as using the framework.

If empty, this is ignored.

excludedNpmDependencies

Type: string[]

Inverse of npmDependencies. If any project is using one of those packages, it will not be considered as using the framework.

If empty, this is ignored.

configFiles

Type: string[]

Framework's configuration files. Those should be paths relative to the project's directory. Any project with one of configuration files will be considered as using the framework.

If empty, this is ignored.

watch

Type: object

Parameters to detect the watch command.

command

Type: string

Default watch command.

directory

Type: string

Directory where built files are written to, in watch mode.

port

Type: number

Local watch server port.

env

Type: object

Environment variables that should be set when running the watch command.

Keywords

FAQs

Last updated on 07 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc