Skip to content
This repository was archived by the owner on Sep 12, 2019. It is now read-only.

Commit 4024dc5

Browse files
author
sw-yx
committed
mirror naming
1 parent 105b395 commit 4024dc5

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ netlify functions:create
4545
netlify functions:create hello-world
4646
netlify functions:create --name hello-world
4747
netlify functions:create hello-world --dir
48-
netlify functions:create --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware
48+
netlify functions:create hello-world --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware
4949
```
5050

5151
You can just call `netlify functions:create` and the prompts will guide you all the way, however you can also supply a first argument to name the function. By default it creates a single file, however you can also use a `--dir` flag to create a function as a directory.
5252

53-
By passing a folder in a github repo to the `--url` flag, you can clone new templates. Dependencies are installed inside its own folder.
53+
By passing a URL to a folder in a github repo to the `--url` flag, you can clone new templates. Dependencies are installed inside its own folder. Example: `netlify functions:create hello-world --url https://github.com/netlify-labs/all-the-functions/tree/master/functions/9-using-middleware`

src/commands/functions/create.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class FunctionsCreateCommand extends Command {
3232
// // --url flag specified, download from there
3333
const folderContents = await readRepoURL(flags.url)
3434
const functionName = flags.url.split('/').slice(-1)[0]
35-
const fnFolder = path.join(functionsDir, functionName)
35+
const nameToUse = await getNameFromArgs(args, flags, functionName)
36+
const fnFolder = path.join(functionsDir, nameToUse)
3637
if (fs.existsSync(fnFolder + '.js') && fs.lstatSync(fnFolder + '.js').isFile()) {
3738
this.log(`A single file version of the function ${name} already exists at ${fnFolder}.js`)
3839
process.exit(1)
@@ -46,14 +47,16 @@ class FunctionsCreateCommand extends Command {
4647
await Promise.all(
4748
folderContents.map(({ name, download_url }) => {
4849
return fetch(download_url).then(res => {
49-
const dest = fs.createWriteStream(path.join(fnFolder, name))
50+
const finalName = path.basename(name, '.js') === functionName ? nameToUse + '.js' : name
51+
const dest = fs.createWriteStream(path.join(fnFolder, finalName))
5052
res.body.pipe(dest)
5153
})
5254
})
5355
)
5456

55-
cp.exec('npm i', { cwd: path.join(functionsDir, functionName) }, () => {
56-
console.log(`${functionName} dependencies installed`)
57+
console.log(`installing dependencies for ${nameToUse}...`)
58+
cp.exec('npm i', { cwd: path.join(functionsDir, nameToUse) }, () => {
59+
console.log(`installing dependencies for ${nameToUse} complete `)
5760
})
5861
} else {
5962
// // no --url flag specified, pick from a provided template

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy