@fastly/create-compute
Advanced tools
Comparing version 0.1.0-beta.4 to 0.1.0
@@ -5,4 +5,4 @@ /* | ||
*/ | ||
import path from 'node:path'; | ||
import { isCancel, text, spinner, select, note } from '@clack/prompts'; | ||
import { getDirectoryStatus } from './directory.js'; | ||
import { findReposStartWith, repoNameToPath } from './github.js'; | ||
@@ -46,30 +46,5 @@ import { KNOWN_STARTER_KITS, defaultStarterKitForLanguage, starterKitFullNameToShortName, starterKitShortNameToFullName, } from './fastlyStarterKits.js'; | ||
else { | ||
const promptValue = await text({ | ||
message: 'Where do you wish to create your application?', | ||
placeholder: 'Path to application directory', | ||
initialValue: './', | ||
validate(directory) { | ||
if (directory === '') { | ||
return `Cannot be empty!`; | ||
} | ||
switch (getDirectoryStatus(directory)) { | ||
case 'not-directory': | ||
return `A file at '${directory}' already exists!`; | ||
case 'not-empty': | ||
return `Directory '${directory}' is not empty!`; | ||
case 'other-error': | ||
return `'${directory}' cannot be used!`; | ||
case 'available': | ||
case 'empty': | ||
// available | ||
break; | ||
} | ||
}, | ||
}); | ||
if (isCancel(promptValue)) { | ||
throw new BuildExecParamsCancelledError(); | ||
} | ||
directory = promptValue; | ||
directory = './'; | ||
} | ||
note(`Using directory: ${directory}`); | ||
note(`Using directory: ${path.resolve(directory)}`); | ||
// Whatever the value is, we will try to fs.mkdir() after confirmation to make sure | ||
@@ -76,0 +51,0 @@ // we can create the directory. |
@@ -12,20 +12,21 @@ #!/usr/bin/env node | ||
import { execFastlyCli, getFastlyCliVersion } from './fastlyCommand.js'; | ||
import { getDirectoryStatus } from "./directory.js"; | ||
import { getDirectoryStatus } from './directory.js'; | ||
import { starterKitFullNameToShortName } from './fastlyStarterKits.js'; | ||
import { findReposStartWith } from './github.js'; | ||
const OPTION_DEFINITIONS = [ | ||
{ name: 'help', type: Boolean, }, // Display help | ||
{ name: 'directory', type: String, }, // A directory that should not exist. If not provided, then will be prompted. | ||
{ name: 'author', type: String, multiple: true, }, // Author email. If not provided, then will be left empty in fastly.toml. | ||
{ name: 'language', type: String, }, // Language. Can be javascript or typescript. If not provided, then will be prompted. | ||
{ name: 'starter-kit', type: String, }, // Starter kit. If not provided, then will be prompted. Requires --language. | ||
{ name: 'default-starter-kit', type: Boolean, }, // Default starter kit. Requires --language. | ||
{ name: 'list-starter-kits', type: Boolean, }, // List starter kits. | ||
{ name: 'from', type: String, }, // Path to a directory with a fastly.toml, a URL to a GitHub repo path with a fastly.toml, or a fiddle. | ||
{ name: 'fastly-cli-path', type: String, }, // Path to the fastly CLI command. If not provided, then defaults to $(which fastly) (where in Windows) | ||
{ name: 'no-confirm', type: Boolean, }, // If set, then perform the operation with a confirmation prompt. | ||
{ name: 'help', type: Boolean, }, | ||
{ name: 'directory', type: String, }, | ||
{ name: 'author', type: String, multiple: true, }, | ||
{ name: 'language', type: String, }, | ||
{ name: 'starter-kit', type: String, }, | ||
{ name: 'default-starter-kit', type: Boolean, }, | ||
{ name: 'list-starter-kits', type: Boolean, }, | ||
{ name: 'from', type: String, }, | ||
{ name: 'fastly-cli-path', type: String, }, | ||
{ name: 'no-confirm', type: Boolean, }, | ||
]; | ||
function displayHelp() { | ||
log.info(`\ | ||
@fastly/create-compute: A CLI for creating new JavaScript (TypeScript) applications on Fastly Compute. | ||
@fastly/create-compute: A CLI for creating new JavaScript (TypeScript) | ||
applications on Fastly Compute. | ||
@@ -40,4 +41,5 @@ Initializes a Fastly Compute JavaScript (TypeScript) application. | ||
--directory=<pathspec> - Specifies the directory to create the new | ||
application. If the directory exists, it must | ||
be empty. Defaults to the current directory. | ||
application. If the directory exists, it | ||
must be empty. Defaults to the current | ||
directory. | ||
--author=<author-name>, ... - Sets the author(s) in fastly.toml. | ||
@@ -47,15 +49,25 @@ --language=<lang> - Used to select a category of starter kit. | ||
Cannot be used with --from. | ||
--starter-kit=<id> - Used to specify a starter kit. Must be used | ||
with --language, and cannot be used with | ||
--default-starter-kit or --from. | ||
--starter-kit=<id> - Used to specify a starter kit. Must be | ||
used with --language. | ||
Cannot be used with --default-starter-kit, | ||
--list-starter-kits, or --from. | ||
--default-starter-kit - Uses 'default' as the starter kit. | ||
Equivalent to --starter-kit=default. | ||
Cannot be used with --starter-kit or --from. | ||
--from=<pathspec-or-url> - Specifies a directory with a fastly.toml, a | ||
URL to a GitHub repo path with a fastly.toml, | ||
or a URL to a Fiddle, and will be used as the | ||
starting point of the new application. Cannot | ||
be used with --language or --starter-kit. | ||
--fastly-cli-path=<pathspec> - Path to the fastly CLI command. If not | ||
specified, then @fastly/cli will be used. | ||
Cannot be used with --starter-kit, | ||
--list-starter-kits, or --from. | ||
--list-starter-kits - Fetches a list of available starter kits | ||
and outputs it. | ||
Cannot be used with --starter-kit, | ||
--default-starter-kit, or --from. | ||
--from=<pathspec-or-url> - Specifies a directory with a fastly.toml, | ||
a URL to a GitHub repo path with a | ||
fastly.toml, or a URL to a Fiddle, and | ||
will be used as the starting point of the | ||
new application. | ||
Cannot be used with --language, | ||
--list-starter-kits, or --starter-kit. | ||
--fastly-cli-path=<pathspec> - By default, this initializer uses a | ||
built-in copy of the Fastly CLI. Use this | ||
option to specify the path of an | ||
alternative Fastly CLI to use. | ||
--no-confirm - Do not show confirmation prompt before | ||
@@ -66,8 +78,7 @@ creating the application. | ||
* If --directory is not provided, then the current directory will be used. | ||
* If --author is not provided, then fastly.toml will be initialized with an | ||
empty value. | ||
* If --fastly-cli-path is not provided, then the '@fastly/cli' package will | ||
be used. | ||
* If --directory, --language, or --starter-kit are not provided, then you will | ||
be prompted for them. | ||
* If --language, or --starter-kit are not provided, then you will be | ||
prompted for them. | ||
`); | ||
@@ -74,0 +85,0 @@ } |
{ | ||
"name": "@fastly/create-compute", | ||
"version": "0.1.0-beta.4", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"description": "A CLI for creating new JavaScript (TypeScript) applications on Fastly Compute", | ||
"type": "module", | ||
"bin": "./dist/cli/index.js", | ||
"bin": "dist/cli/index.js", | ||
"engines": { | ||
@@ -23,3 +23,3 @@ "node": ">=18" | ||
"@clack/prompts": "^0.7.0", | ||
"@fastly/cli": "^10.13.3", | ||
"@fastly/cli": "^10.14.0", | ||
"command-line-args": "^6.0.0" | ||
@@ -26,0 +26,0 @@ }, |
# @fastly/create-compute | ||
An `npm create` script for interactively creating new JavaScript (TypeScript) applications for Fastly Compute. | ||
An initializer for `npm create` to interactively create new JavaScript (TypeScript) applications for Fastly Compute. | ||
@@ -9,5 +9,5 @@ ```shell | ||
Follow the interactive prompts to select a directory, language, and starter kit, to create your Fastly Compute application in JavaScript or TypeScript. | ||
Follow the interactive prompts to select between JavaScript and Typescript and a starter kit, to initialize your Fastly Compute application. | ||
![example](./demo.gif) | ||
![example](demo.gif) | ||
@@ -24,10 +24,11 @@ > NOTE: `@fastly/create-compute` is provided as a Fastly Labs product. Visit the [Fastly Labs](https://www.fastlylabs.com/) site for terms of use. | ||
You may also pass a number of command line options, in the form of `npm create @fastly/compute -- [<options>]`: | ||
You may also pass a number of optional command line options, in the form of `npm create @fastly/compute -- [<options>]`: | ||
``` | ||
Options: | ||
--help - Displays a help screen. | ||
--help - Displays this help screen. | ||
--directory=<pathspec> - Specifies the directory to create the new | ||
application. If the directory exists, it must | ||
be empty. Defaults to the current directory. | ||
application. If the directory exists, it | ||
must be empty. Defaults to the current | ||
directory. | ||
--author=<author-name>, ... - Sets the author(s) in fastly.toml. | ||
@@ -37,17 +38,25 @@ --language=<lang> - Used to select a category of starter kit. | ||
Cannot be used with --from. | ||
--starter-kit=<id> - Used to specify a starter kit. Must be used | ||
with --language, and cannot be used with | ||
--default-starter-kit or --from. | ||
--starter-kit=<id> - Used to specify a starter kit. Must be | ||
used with --language. | ||
Cannot be used with --default-starter-kit, | ||
--list-starter-kits, or --from. | ||
--default-starter-kit - Uses 'default' as the starter kit. | ||
Equivalent to --starter-kit=default. | ||
Cannot be used with --starter-kit or --from. | ||
--list-starter-kits - Query GitHub to list the starter kits | ||
available. May be used with --language. | ||
--from=<pathspec-or-url> - Specifies a directory with a fastly.toml, a | ||
URL to a GitHub repo path with a fastly.toml, | ||
or a URL to a Fiddle, and will be used as the | ||
starting point of the new application. Cannot | ||
be used with --language or --starter-kit. | ||
--fastly-cli-path=<pathspec> - Path to the fastly CLI command. If not | ||
specified, then @fastly/cli will be used. | ||
Cannot be used with --starter-kit, | ||
--list-starter-kits, or --from. | ||
--list-starter-kits - Fetches a list of available starter kits | ||
and outputs it. | ||
Cannot be used with --starter-kit, | ||
--default-starter-kit, or --from. | ||
--from=<pathspec-or-url> - Specifies a directory with a fastly.toml, | ||
a URL to a GitHub repo path with a | ||
fastly.toml, or a URL to a Fiddle, and | ||
will be used as the starting point of the | ||
new application. | ||
Cannot be used with --language, | ||
--list-starter-kits, or --starter-kit. | ||
--fastly-cli-path=<pathspec> - By default, this initializer uses a | ||
built-in copy of the Fastly CLI. Use this | ||
option to specify the path of an | ||
alternative Fastly CLI to use. | ||
--no-confirm - Do not show confirmation prompt before | ||
@@ -63,3 +72,3 @@ creating the application. | ||
By using the `--from` argument, or by selecting `Specify starter kit or directory` from the interactive prompts, you may specify an existing Compute JavaScript application to base your new application from. You may provide one of the following: | ||
By using the `--from` option, or by selecting `Specify starter kit or directory` from the interactive prompts, you may specify an existing Compute JavaScript application to base your new application from. You may provide one of the following: | ||
@@ -70,5 +79,34 @@ * A path to a local directory that contains a Compute program, e.g., `/path/to/existing/app`. | ||
## Listing available Starter Kits and selecting from them | ||
To obtain a complete list of available starter kits, use the `--list-starter-kits` option: | ||
```shell | ||
npm create @fastly/compute -- --list-starter-kits | ||
``` | ||
Sample output: | ||
``` | ||
Available starter kits: | ||
Language: javascript | ||
[default] - Default package template for JavaScript based Fastly Compute projects | ||
[empty] - Empty package template for JavaScript based Fastly Compute projects | ||
``` | ||
To initialize a project with a Starter Kit, specify it using the identifier within the brackets (such as `default` and `empty`) for the `--starter-kit=<id>` value. | ||
## Fastly CLI | ||
By default, this initializer uses a copy of the Fastly CLI builtin to it. | ||
Alternatively, to use a copy of the Fastly CLI (version >= 10.0.0) available on your system, specify it using the `--fastly-cli-path` option: | ||
``` | ||
npm create @fastly/compute -- --fastly-cli-path=/path/to/fastly | ||
``` | ||
## Prerequisites: | ||
* [Fastly CLI](https://developer.fastly.com/learning/tools/cli/), version >= 10.0.0 | ||
* [Node.js](https://nodejs.org/) >= 18 | ||
@@ -75,0 +113,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123
54228
687
Updated@fastly/cli@^10.14.0