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 751a6e86..69660a0c 100644 Binary files a/test/snapshots/bin.js.snap and b/test/snapshots/bin.js.snap differ