From 1bc3826e9ca330810b5295f14611e746b0b5e33d Mon Sep 17 00:00:00 2001 From: erezrokah Date: Thu, 4 Feb 2021 18:02:28 +0100 Subject: [PATCH] feat: add nodeVersion option --- src/bin.js | 8 +++-- src/context.js | 4 +-- src/main.js | 1 + test/bin.js | 12 +++++++ test/snapshots/bin.js.md | 66 ++++++++++++++++++++++++++++++++++--- test/snapshots/bin.js.snap | Bin 512 -> 709 bytes 6 files changed, 83 insertions(+), 8 deletions(-) diff --git a/src/bin.js b/src/bin.js index 3aec4a7e..90019919 100755 --- a/src/bin.js +++ b/src/bin.js @@ -7,10 +7,10 @@ const { listFrameworks } = require('./main.js') // CLI entry point const runCli = async function () { - const { projectDir, long } = parseArgs() + const { projectDir, long, nodeVersion } = parseArgs() try { - const frameworks = await listFrameworks({ projectDir }) + const frameworks = await listFrameworks({ projectDir, nodeVersion }) const frameworksStr = serializeFrameworks(frameworks, long) console.log(frameworksStr) } catch (error) { @@ -30,6 +30,10 @@ const OPTIONS = { describe: `Show more information about each framework. The output will be a JSON array.`, }, + 'node-version': { + string: true, + describe: 'Node.js version of the runtime environment. Used to recommend Netlify build plugins', + }, } const USAGE = `$0 [OPTIONS...] [PROJECT_DIRECTORY] diff --git a/src/context.js b/src/context.js index a4dfc587..e1991209 100644 --- a/src/context.js +++ b/src/context.js @@ -23,13 +23,13 @@ const getPackageJson = async (projectDir) => { } } -const getContext = async ({ projectDir = cwd() } = {}) => { +const getContext = async ({ projectDir = cwd(), nodeVersion = version } = {}) => { const { packageJson, packageJsonPath = projectDir } = await getPackageJson(projectDir) return { pathExists: async (path) => (await locatePath([path], { type: 'file', cwd: projectDir })) !== undefined, packageJson, packageJsonPath, - nodeVersion: version, + nodeVersion, } } diff --git a/src/main.js b/src/main.js index f6cee7d3..42b1340a 100644 --- a/src/main.js +++ b/src/main.js @@ -4,6 +4,7 @@ const { listFrameworks: list, hasFramework: has, getFramework: get } = require(' /** * @typedef {object} Options * @property {string} [projectDir=process.cwd()] - Project's directory + * @property {string} [nodeVersion=process.version] - Node.js version of the runtime environment. Used to recommend Netlify build plugins */ /** diff --git a/test/bin.js b/test/bin.js index c92e0531..4a117679 100644 --- a/test/bin.js +++ b/test/bin.js @@ -29,3 +29,15 @@ test('CLI --long flag', async (t) => { const { stdout } = await execa(binPath, ['--long', `${FIXTURES_DIR}/multiple`]) t.snapshot(stdout) }) + +test('CLI should not recommend Next.js plugin when --node-version flag is less than v10.13.0', async (t) => { + const binPath = await BINARY_PATH + const { stdout } = await execa(binPath, ['--long', '--node-version', 'v8.0.0', `${FIXTURES_DIR}/next-plugin`]) + t.snapshot(stdout) +}) + +test('CLI should recommend Next.js plugin when --node-version flag is v10.13.0', async (t) => { + const binPath = await BINARY_PATH + const { stdout } = await execa(binPath, ['--long', '--node-version', 'v10.13.0', `${FIXTURES_DIR}/next-plugin`]) + t.snapshot(stdout) +}) diff --git a/test/snapshots/bin.js.md b/test/snapshots/bin.js.md index 31b3e66e..5dbeaf63 100644 --- a/test/snapshots/bin.js.md +++ b/test/snapshots/bin.js.md @@ -11,10 +11,12 @@ Generated by [AVA](https://ava.li). `bin.js [projectDir]␊ ␊ Options:␊ - --help Show help [boolean]␊ - --version Show version number [boolean]␊ - --long Show more information about each framework.␊ - The output will be a JSON array. [boolean] [default: false]` + --help Show help [boolean]␊ + --version Show version number [boolean]␊ + --long Show more information about each framework.␊ + The output will be a JSON array. [boolean] [default: false]␊ + --node-version Node.js version of the runtime environment. Used to recommend␊ + Netlify build plugins [string]` ## CLI --long flag @@ -65,3 +67,59 @@ Generated by [AVA](https://ava.li). `vuepress␊ vue` + +## CLI should not recommend Next.js plugin when --node-version flag is less than v10.13.0 + +> Snapshot 1 + + `[␊ + {␊ + "name": "next",␊ + "category": "static_site_generator",␊ + "dev": {␊ + "commands": [␊ + "npm run dev",␊ + "npm run start",␊ + "npm run build"␊ + ],␊ + "port": 3000␊ + },␊ + "build": {␊ + "commands": [␊ + "next build"␊ + ],␊ + "directory": "out"␊ + },␊ + "env": {},␊ + "plugins": []␊ + }␊ + ]` + +## CLI should recommend Next.js plugin when --node-version flag is v10.13.0 + +> Snapshot 1 + + `[␊ + {␊ + "name": "next",␊ + "category": "static_site_generator",␊ + "dev": {␊ + "commands": [␊ + "npm run dev",␊ + "npm run start",␊ + "npm run build"␊ + ],␊ + "port": 3000␊ + },␊ + "build": {␊ + "commands": [␊ + "next build"␊ + ],␊ + "directory": "out"␊ + },␊ + "env": {},␊ + "plugins": [␊ + "@netlify/plugin-nextjs"␊ + ]␊ + }␊ + ]` diff --git a/test/snapshots/bin.js.snap b/test/snapshots/bin.js.snap index 751a6e86440956537347ee361c1eb020d3c8d5d3..69660a0cd2ff0af0ce6d50b67b0183e4d23445cf 100644 GIT binary patch literal 709 zcmV;$0y_OcRzVMxoL(F38`}T+@cS#@KMz_ldZV9^ zJ)}RjY4wpoYoHZkAWL$5Wyojj{78b=sm6woOVOUvRI~b= zVjAZf$Wc-)WJYwbWjKjibWZp_<&H8~CB-9v zbD~gaq8GrgG1C+a&<<@sDm5WIq`Vpnwoob~zf~}Uc<9$q_A2NJ-uUf?zK{rvyF&Uj z@&#y3gc^|6oA9d$igu^+Y!ksS14CY5o(DAq3g>60r+`XHmx^uHq2i!RLr<5%rJlm% zI$Suo>Ex7IMG?*b;es|cWXLu15lp_AsZJlcF2Y5H4rl=;!=^+`!FIXe6l#yTOG$Y^ zn&0gMrnF?d(VqQlR+oo|lCuGM;jg2?ziHe-2ry literal 512 zcmV+b0{{I%RzVAgQN%tb{5gX6uH8%EXVBb+q;RgGs~OVJHz20u+^WC zRtZU?g+D+nYz46w!Ah)kcCvfPaTcE7gJt%8`_1>w`(_88=dF1+?!JBcaj(B~@AC^2 z{M_91y}BOT!_3iEE2iV~#+G8sF; z36i$*jbPi!sz{LjNl+*`x;$Z_2!YF7QNijlfF-IjfGizDPOQMGq9?szL2ocdu%y!R zrd$X}5Ewi>*nb3!h#mKqjUmb~XO%F0$eGX>U(MCum{eF2Y8}{@g~UZCveq+aA4+?g zun%F&4!17wlo=c;I~Gb~(rejwGOkUy;D^$U(zd0jMqE0x z`jQ>IoZ6oP%SlOtG8@h>d)2hMso-6WG~p>iz2g6fZNcSl(px#RApQ;EpJSOp1ONaJ CIR4cD