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
8 changes: 6 additions & 2 deletions src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down
12 changes: 12 additions & 0 deletions test/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
66 changes: 62 additions & 4 deletions test/snapshots/bin.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"␊
]␊
}␊
]`
Binary file modified test/snapshots/bin.js.snap
Binary file not shown.