|
1 | | -Framework detection utility. |
2 | | - |
3 | | -Detects which framework a specific website is using. The framework's build/dev commands, directories and server port are |
4 | | -also returned. |
5 | | - |
6 | | -The following frameworks are detected: |
7 | | - |
8 | | -- Static site generators: Gatsby, Hugo, Jekyll, Next.js, Nuxt, Hexo, Gridsome, Docusaurus, Eleventy, Middleman, |
9 | | - Phenomic, React-static, Stencil, Vuepress, Assemble, DocPad, Harp, Metalsmith, Roots, Wintersmith |
10 | | -- Front-end frameworks: create-react-app, Vue, Sapper, Angular, Ember, Svelte, Expo, Quasar |
11 | | -- Build tools: Parcel, Brunch, Grunt, Gulp |
12 | | - |
13 | | -If you're looking for a way to run `framework-info` via CLI check the |
14 | | -[`build-info`](https://github.com/netlify/build/tree/main/packages/build-info) project. |
15 | | - |
16 | | -[Additions and updates are welcome!](#add-or-update-a-framework) |
17 | | - |
18 | | -# Example (Node.js) |
19 | | - |
20 | | -```js |
21 | | -import { listFrameworks, hasFramework, getFramework, getFrameworkById } from '@netlify/framework-info' |
22 | | - |
23 | | -console.log(await listFrameworks({ projectDir: './path/to/gatsby/website' })) |
24 | | -// [ |
25 | | -// { |
26 | | -// id: 'gatsby', |
27 | | -// name: 'Gatsby', |
28 | | -// category: 'static_site_generator', |
29 | | -// dev: { |
30 | | -// commands: ['gatsby develop'], |
31 | | -// port: 8000, |
32 | | -// pollingStrategies: [{ name: 'TCP' }] |
33 | | -// }, |
34 | | -// build: { |
35 | | -// commands: ['gatsby build'], |
36 | | -// directory: 'public' |
37 | | -// }, |
38 | | -// staticAssetsDirectory: "static", |
39 | | -// env: { GATSBY_LOGGER: 'yurnalist' }, |
40 | | -// plugins: [] |
41 | | -// } |
42 | | -// ] |
43 | | - |
44 | | -console.log(await listFrameworks({ projectDir: './path/to/vue/website' })) |
45 | | -// [ |
46 | | -// { |
47 | | -// id: 'vue', |
48 | | -// name: 'Vue.js', |
49 | | -// category: 'frontend_framework', |
50 | | -// dev: { |
51 | | -// commands: ['npm run serve'], |
52 | | -// port: 8080, |
53 | | -// pollingStrategies: [{ name: 'TCP' }] |
54 | | -// }, |
55 | | -// build: { |
56 | | -// commands: ['vue-cli-service build'], |
57 | | -// directory: 'dist' |
58 | | -// }, |
59 | | -// env: {}, |
60 | | -// plugins: [] |
61 | | -// } |
62 | | -// ] |
63 | | - |
64 | | -console.log(await hasFramework('vue', { projectDir: './path/to/vue/website' })) |
65 | | -// true |
66 | | - |
67 | | -console.log(await getFramework('vue', { projectDir: './path/to/vue/website' })) |
68 | | -// { |
69 | | -// id: 'vue', |
70 | | -// name: 'Vue.js', |
71 | | -// category: 'frontend_framework', |
72 | | -// dev: { |
73 | | -// commands: ['npm run serve'], |
74 | | -// port: 8080, |
75 | | -// pollingStrategies: [{ name: 'TCP' }] |
76 | | -// }, |
77 | | -// build: { |
78 | | -// commands: ['vue-cli-service build'], |
79 | | -// directory: 'dist' |
80 | | -// }, |
81 | | -// env: {}, |
82 | | -// plugins: [] |
83 | | -// } |
84 | | - |
85 | | -console.log(getFrameworkById('vue')) |
86 | | -// { |
87 | | -// id: 'vue', |
88 | | -// name: 'Vue.js', |
89 | | -// category: 'frontend_framework', |
90 | | -// dev: { |
91 | | -// commands: ['npm run serve'], |
92 | | -// port: 8080, |
93 | | -// pollingStrategies: [{ name: 'TCP' }] |
94 | | -// }, |
95 | | -// build: { |
96 | | -// commands: ['vue-cli-service build'], |
97 | | -// directory: 'dist' |
98 | | -// }, |
99 | | -// env: {}, |
100 | | -// plugins: [] |
101 | | -// } |
102 | | -``` |
103 | | - |
104 | | -# Installation |
105 | | - |
106 | | -```bash |
107 | | -npm install @netlify/framework-info |
108 | | -``` |
109 | | - |
110 | | -# Usage (Node.js) |
111 | | - |
112 | | -## listFrameworks(options?) |
113 | | - |
114 | | -`options`: `object?`\ |
115 | | -_Return value_: `Promise<object[]>` |
116 | | - |
117 | | -### Options |
118 | | - |
119 | | -#### projectDir |
120 | | - |
121 | | -_Type_: `string`\ |
122 | | -_Default value_: `process.cwd()` |
123 | | - |
124 | | -Path to the website's directory. |
125 | | - |
126 | | -### Return value |
127 | | - |
128 | | -This returns a `Promise` resolving to an array of objects describing each framework. The array can be empty, contain a |
129 | | -single object or several objects. |
130 | | - |
131 | | -Each object has the following properties. |
132 | | - |
133 | | -#### id |
134 | | - |
135 | | -_Type_: `string` |
136 | | - |
137 | | -Id such as `"gatsby"`. |
138 | | - |
139 | | -## name |
140 | | - |
141 | | -_Type_: `string` |
142 | | - |
143 | | -Framework name such as `"Gatsby"`. |
144 | | - |
145 | | -#### category |
146 | | - |
147 | | -_Type_: `string` |
148 | | - |
149 | | -Category among `"static_site_generator"`, `"frontend_framework"` and `"build_tool"`. |
150 | | - |
151 | | -#### dev |
152 | | - |
153 | | -_Type_: `object` |
154 | | - |
155 | | -Information about the dev command. |
156 | | - |
157 | | -##### commands |
158 | | - |
159 | | -_Type_: `string[]` |
160 | | - |
161 | | -Dev command. There might be several alternatives. |
162 | | - |
163 | | -##### port |
164 | | - |
165 | | -_Type_: `number` |
166 | | - |
167 | | -Server port. |
168 | | - |
169 | | -##### pollingStrategies |
170 | | - |
171 | | -_Type_: `object[]` |
172 | | - |
173 | | -Polling strategies to use when checking if the dev server is ready. |
174 | | - |
175 | | -#### build |
176 | | - |
177 | | -_Type_: `object` |
178 | | - |
179 | | -Information about the build command. |
180 | | - |
181 | | -##### commands |
182 | | - |
183 | | -_Type_: `string[]` |
184 | | - |
185 | | -Build command. There might be several alternatives. |
186 | | - |
187 | | -##### directory |
188 | | - |
189 | | -_Type_: `string` |
190 | | - |
191 | | -Relative path to the directory where files are built. |
192 | | - |
193 | | -#### staticAssetsDirectory |
194 | | - |
195 | | -_Type_: `string` |
196 | | - |
197 | | -Directory where the framework stores static assets. Can be `undefined`. |
198 | | - |
199 | | -#### env |
200 | | - |
201 | | -_Type_: `object` |
202 | | - |
203 | | -Environment variables that should be set when calling the dev command. |
204 | | - |
205 | | -#### plugins |
206 | | - |
207 | | -_Type_: `string[]` |
208 | | - |
209 | | -A list of recommend Netlify build plugins to install for the framework. |
210 | | - |
211 | | -## hasFramework(frameworkId, options?) |
212 | | - |
213 | | -`options`: `object?`\ |
214 | | -_Return value_: `Promise<boolean>` |
215 | | - |
216 | | -Same as [`listFramework()`](#listframeworksoptions) except only for a specific framework and returns a boolean. |
217 | | - |
218 | | -## getFramework(frameworkId, options?) |
219 | | - |
220 | | -`options`: `object?`\ |
221 | | -_Return value_: `Promise<object>` |
222 | | - |
223 | | -Same as [`listFramework()`](#listframeworksoptions) except the framework is passed as argument instead of being |
224 | | -detected. A single framework object is returned. |
225 | | - |
226 | | -# Usage (CLI) |
227 | | - |
228 | | -```bash |
229 | | -$ framework-info [projectDirectory] |
230 | | -``` |
231 | | - |
232 | | -This prints the ids of each framework. |
233 | | - |
234 | | -If known is found, `unknown` is printed. |
235 | | - |
236 | | -Available flags: |
237 | | - |
238 | | -- `--long`: Show more information about each framework. The output will be a JSON array. |
239 | | - |
240 | | -# Add or update a framework |
241 | | - |
242 | | -Each framework is a JSON file in the `/src/frameworks/` directory. For example: |
243 | | - |
244 | | -```json |
245 | | -{ |
246 | | - "id": "gatsby", |
247 | | - "name": "Gatsby", |
248 | | - "category": "static_site_generator", |
249 | | - "detect": { |
250 | | - "npmDependencies": ["gatsby"], |
251 | | - "excludedNpmDependencies": [], |
252 | | - "configFiles": ["gatsby-config.js"] |
253 | | - }, |
254 | | - "dev": { |
255 | | - "command": "gatsby develop", |
256 | | - "port": 8000, |
257 | | - "pollingStrategies": [{ "name": "TCP" }, { "name": "HTTP" }] |
258 | | - }, |
259 | | - "build": { |
260 | | - "command": "gatsby build", |
261 | | - "directory": "public" |
262 | | - }, |
263 | | - "staticAssetsDirectory": "static", |
264 | | - "env": { "GATSBY_LOGGER": "yurnalist" }, |
265 | | - "plugins": [] |
266 | | -} |
267 | | -``` |
268 | | - |
269 | | -All properties are required. |
270 | | - |
271 | | -## id |
272 | | - |
273 | | -_Type_: `string` |
274 | | - |
275 | | -Id of the framework. |
276 | | - |
277 | | -## name |
278 | | - |
279 | | -_Type_: `string` |
280 | | - |
281 | | -Name of the framework. |
282 | | - |
283 | | -## category |
284 | | - |
285 | | -_Type_: `string` |
286 | | - |
287 | | -One of `"static_site_generator"`, `"frontend_framework"` or `"build_tool"`. |
288 | | - |
289 | | -## detect |
290 | | - |
291 | | -_Type_: `object` |
292 | | - |
293 | | -Information used to detect this framework |
294 | | - |
295 | | -### npmDependencies |
296 | | - |
297 | | -_Type_: `string[]` |
298 | | - |
299 | | -Framework's npm packages. Any project with one of those packages in their `package.json` (`dependencies` or |
300 | | -`devDependencies`) will be considered as using the framework. |
301 | | - |
302 | | -If empty, this is ignored. |
303 | | - |
304 | | -### excludedNpmDependencies |
305 | | - |
306 | | -_Type_: `string[]` |
307 | | - |
308 | | -Inverse of `npmDependencies`. If any project is using one of those packages, it will not be considered as using the |
309 | | -framework. |
310 | | - |
311 | | -If empty, this is ignored. |
312 | | - |
313 | | -### configFiles |
314 | | - |
315 | | -_Type_: `string[]` |
316 | | - |
317 | | -Framework's configuration files. Those should be paths relative to the [project's directory](#projectdir). Any project |
318 | | -with one of configuration files will be considered as using the framework. |
319 | | - |
320 | | -If empty, this is ignored. |
321 | | - |
322 | | -## dev |
323 | | - |
324 | | -_Type_: `object` |
325 | | - |
326 | | -Parameters to detect the dev command. |
327 | | - |
328 | | -### command |
329 | | - |
330 | | -_Type_: `string` |
331 | | - |
332 | | -Default dev command. |
333 | | - |
334 | | -### port |
335 | | - |
336 | | -_Type_: `number` |
337 | | - |
338 | | -Local dev server port. |
339 | | - |
340 | | -### pollingStrategies |
341 | | - |
342 | | -_Type_: `object[]` |
343 | | - |
344 | | -Polling strategies to use when checking if the dev server is ready. |
345 | | - |
346 | | -## build |
347 | | - |
348 | | -_Type_: `object` |
349 | | - |
350 | | -Parameters to detect the build command. |
351 | | - |
352 | | -### command |
353 | | - |
354 | | -_Type_: `string` |
355 | | - |
356 | | -Default build command. |
357 | | - |
358 | | -### directory |
359 | | - |
360 | | -_Type_: `string` |
361 | | - |
362 | | -Directory where built files are written to. |
363 | | - |
364 | | -## staticAssetsDirectory |
365 | | - |
366 | | -_Type_: `string` |
367 | | - |
368 | | -Directory where the framework stores static assets where relevant for the framework. |
369 | | - |
370 | | -## env |
371 | | - |
372 | | -_Type_: `object` |
373 | | - |
374 | | -Environment variables that should be set when running the dev command. |
375 | | - |
376 | | -## plugins |
377 | | - |
378 | | -_Type_: `object[]` |
379 | | - |
380 | | -A list of Netlify build plugins package names and conditions. If a condition is met for a plugin it will be returned in |
381 | | -the framework's plugin's list. |
382 | | - |
383 | | -For example |
384 | | - |
385 | | -```json |
386 | | -{ |
387 | | - "plugins": [ |
388 | | - { |
389 | | - "packageName": "@netlify/plugin-nextjs", |
390 | | - "condition": { "minNodeVersion": "10.13.0" } |
391 | | - } |
392 | | - ] |
393 | | -} |
394 | | -``` |
| 1 | +> [!IMPORTANT] |
| 2 | +> This package is deprecated and will no longer receive updates. |
| 3 | +> |
| 4 | +> Please refer to the [`@netlify/build-info`](https://www.npmjs.com/package/@netlify/build-info) package instead. |
0 commit comments