From a72a607399d8e60b76a2319e475b029713685cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poullain?= Date: Sat, 27 Jul 2024 17:39:39 +0200 Subject: [PATCH 1/4] Prefer using @foal/cli locally than globally --- .github/CONTRIBUTING.MD | 2 +- README.md | 7 ++- docs/docs/README.md | 7 ++- docs/docs/architecture/configuration.md | 2 +- docs/docs/architecture/controllers.md | 2 +- docs/docs/architecture/hooks.md | 2 +- .../services-and-dependency-injection.md | 2 +- docs/docs/authentication/jwt.md | 4 +- docs/docs/authentication/quick-start.md | 4 +- docs/docs/authentication/session-tokens.md | 8 ++-- docs/docs/authentication/user-class.md | 4 +- .../authorization/groups-and-permissions.md | 12 ++--- docs/docs/cli/code-generation.md | 44 +++++++++---------- docs/docs/cli/commands.md | 2 +- docs/docs/cli/shell-scripts.md | 6 +-- docs/docs/common/gRPC.md | 6 +-- docs/docs/common/graphql.md | 6 +-- docs/docs/common/openapi-and-swagger-ui.md | 8 ++-- docs/docs/common/rest-blueprints.md | 6 +-- docs/docs/common/task-scheduling.md | 2 +- docs/docs/common/utilities.md | 2 +- docs/docs/databases/other-orm/introduction.md | 2 +- .../typeorm/create-models-and-queries.md | 2 +- docs/docs/databases/typeorm/mongodb.md | 4 +- .../deployment-and-environments/checklist.md | 2 +- docs/docs/frontend/angular-react-vue.md | 18 ++++---- docs/docs/frontend/nuxt.js.md | 2 +- .../1-introduction.md | 2 +- .../12-file-upload.md | 2 +- .../14-production-build.md | 2 +- .../15-social-auth.md | 2 +- .../3-the-models.md | 2 +- .../4-the-shell-scripts.md | 12 ++--- .../5-our-first-route.md | 2 +- .../6-swagger-interface.md | 2 +- .../7-add-frontend.md | 2 +- .../8-authentication.md | 2 +- .../simple-todo-list/1-installation.md | 2 +- .../simple-todo-list/3-the-todo-model.md | 2 +- .../4-the-shell-script-create-todo.md | 8 ++-- e2e_test.sh | 43 +++++++++--------- .../shell-scripts/create-group.spec.ts | 2 +- .../shell-scripts/create-perm.spec.ts | 2 +- .../rest-api/create-rest-api.spec.ts | 2 +- .../generators/rest-api/create-rest-api.ts | 2 +- .../cli/src/generate/specs/app/package.json | 8 ++-- .../generate/specs/app/package.mongodb.json | 6 +-- .../specs/app/package.mongodb.yaml.json | 6 +-- .../src/generate/specs/app/package.yaml.json | 8 ++-- .../src/generate/templates/app/package.json | 8 ++-- .../templates/app/package.mongodb.json | 6 +-- .../get-command-line-arguments.util.spec.ts | 2 +- .../cli/src/run-script/run-script.spec.ts | 2 +- packages/cli/src/run-script/run-script.ts | 2 +- packages/examples/package.json | 2 +- 55 files changed, 154 insertions(+), 157 deletions(-) diff --git a/.github/CONTRIBUTING.MD b/.github/CONTRIBUTING.MD index 5540a80e8c..edfdd4c740 100644 --- a/.github/CONTRIBUTING.MD +++ b/.github/CONTRIBUTING.MD @@ -146,7 +146,7 @@ All of major releases are supported for at least 18 months. ### `@foal/cli` Package Structure -The directory `src/generate/` contains the source code of the commands `foal createapp` and `foal generate`. +The directory `src/generate/` contains the source code of the commands `npx @foal/cli createapp` and `npx foal generate`. Here is the list of its sub-directories: diff --git a/README.md b/README.md index d6592b164c..f772b807ec 100644 --- a/README.md +++ b/README.md @@ -55,10 +55,9 @@ First install [Node.Js and npm](https://nodejs.org/en/download/). ### Create a new app ``` -$ npm install -g @foal/cli -$ foal createapp my-app -$ cd my-app -$ npm run dev +npx @foal/cli createapp my-app +cd my-app +npm run dev ``` The development server is started! Go to `http://localhost:3001` and find our welcoming page! diff --git a/docs/docs/README.md b/docs/docs/README.md index ddcbb7029c..f40c2238aa 100644 --- a/docs/docs/README.md +++ b/docs/docs/README.md @@ -35,10 +35,9 @@ Great attention is paid to the stability of the product. You can find out more b ## Get Started ``` -> npm install -g @foal/cli -> foal createapp my-app -> cd my-app -> npm run dev +npx @foal/cli createapp my-app +cd my-app +npm run dev ``` The development server is started! Go to `http://localhost:3001` and find our welcoming page! diff --git a/docs/docs/architecture/configuration.md b/docs/docs/architecture/configuration.md index e2e6ce7565..862b14ea25 100644 --- a/docs/docs/architecture/configuration.md +++ b/docs/docs/architecture/configuration.md @@ -63,7 +63,7 @@ module.exports = { > When creating a new project, you can also add the flag `--yaml` to have all the configuration directly generated in YAML. > > ``` -> foal createapp my-app --yaml +> npx @foal/cli createapp my-app --yaml > ``` > > The extension of the YAML files must be `.yml`. diff --git a/docs/docs/architecture/controllers.md b/docs/docs/architecture/controllers.md index 59c7d696d9..2607e8f8e4 100644 --- a/docs/docs/architecture/controllers.md +++ b/docs/docs/architecture/controllers.md @@ -4,7 +4,7 @@ title: Controllers ```sh -foal generate controller my-controller +npx foal generate controller my-controller ``` ```typescript diff --git a/docs/docs/architecture/hooks.md b/docs/docs/architecture/hooks.md index 5e6633665c..ee868b7d9a 100644 --- a/docs/docs/architecture/hooks.md +++ b/docs/docs/architecture/hooks.md @@ -4,7 +4,7 @@ title: Hooks ```sh -foal generate hook my-hook +npx foal generate hook my-hook ``` ## Description diff --git a/docs/docs/architecture/services-and-dependency-injection.md b/docs/docs/architecture/services-and-dependency-injection.md index 6ab3c14192..2cbdea80c7 100644 --- a/docs/docs/architecture/services-and-dependency-injection.md +++ b/docs/docs/architecture/services-and-dependency-injection.md @@ -7,7 +7,7 @@ import TabItem from '@theme/TabItem'; ```sh -foal generate service my-service +npx foal generate service my-service ``` ```typescript diff --git a/docs/docs/authentication/jwt.md b/docs/docs/authentication/jwt.md index 5c82fe5160..f45a733af8 100644 --- a/docs/docs/authentication/jwt.md +++ b/docs/docs/authentication/jwt.md @@ -20,10 +20,10 @@ Foal offers a package, named `@foal/jwt`, to manage authentication / authorizati ## Generate & Provide a Secret -In order to use JWTs, you must provide a secret to *sign* your tokens. If you do not already have your own, you can generate one with the `foal createsecret` command. +In order to use JWTs, you must provide a secret to *sign* your tokens. If you do not already have your own, you can generate one with the `npx foal createsecret` command. ```sh -$ foal createsecret +npx foal createsecret Ak0WcVcGuOoFuZ4oqF1tgqbW6dIAeSacIN6h7qEyJM8= ``` diff --git a/docs/docs/authentication/quick-start.md b/docs/docs/authentication/quick-start.md index b9e145fbe8..ce4faf8006 100644 --- a/docs/docs/authentication/quick-start.md +++ b/docs/docs/authentication/quick-start.md @@ -212,7 +212,7 @@ export class ApiController { First, generate a base64-encoded secret. ```bash -foal createsecret +npx foal createsecret ``` Save this secret in a `.env` file. @@ -516,7 +516,7 @@ export class ApiController { First, generate a base64-encoded secret. ```bash -foal createsecret +npx foal createsecret ``` Save this secret in a `.env` file. diff --git a/docs/docs/authentication/session-tokens.md b/docs/docs/authentication/session-tokens.md index e55fc6a0c1..5d4a588e1a 100644 --- a/docs/docs/authentication/session-tokens.md +++ b/docs/docs/authentication/session-tokens.md @@ -635,7 +635,7 @@ module.exports = { #### Revoking One Session ``` -foal g script revoke-session +npx foal g script revoke-session ``` Open `scripts/revoke-session.ts` and update its content. @@ -675,13 +675,13 @@ npm run build Run the script. ``` -foal run revoke-session token="lfdkszjanjiznr" +npx foal run revoke-session token="lfdkszjanjiznr" ``` #### Revoking All Sessions ``` -foal g script revoke-all-sessions +npx foal g script revoke-all-sessions ``` Open `scripts/revoke-all-sessions.ts` and update its content. @@ -709,7 +709,7 @@ npm run build Run the script. ``` -foal run revoke-all-sessions +npx foal run revoke-all-sessions ``` ### Query All Sessions of a User diff --git a/docs/docs/authentication/user-class.md b/docs/docs/authentication/user-class.md index 8449d45c18..dbd26ba681 100644 --- a/docs/docs/authentication/user-class.md +++ b/docs/docs/authentication/user-class.md @@ -48,7 +48,7 @@ You can use the `create-user` shell script (located in `src/scripts`) to create ```sh npm run build -foal run create-user +npx foal run create-user ``` ## Example (email and password) @@ -134,7 +134,7 @@ You can now create a new user with these commands: ```sh npm run build -foal run create-user email=mary@foalts.org password=mary_password +npx foal run create-user email=mary@foalts.org password=mary_password ``` ## Using another ORM/ODM diff --git a/docs/docs/authorization/groups-and-permissions.md b/docs/docs/authorization/groups-and-permissions.md index 55e06973e8..ef03d546f5 100644 --- a/docs/docs/authorization/groups-and-permissions.md +++ b/docs/docs/authorization/groups-and-permissions.md @@ -41,7 +41,7 @@ async function main() { Create a new script with this command: ``` -foal generate script create-perm +npx foal generate script create-perm ``` Replace the content of the new created file `src/scripts/create-perm.ts` with the following: @@ -84,7 +84,7 @@ export async function main(args: { codeName: string, name: string }) { Then you can create a permission through the command line. ```sh npm run build -foal run create-perm name="Permission to access the secret" codeName="access-secret" +npx foal run create-perm name="Permission to access the secret" codeName="access-secret" ``` ## Groups @@ -125,7 +125,7 @@ async function main() { Create a new script with this command: ``` -foal generate script create-group +npx foal generate script create-group ``` Replace the content of the new created file `src/scripts/create-group.ts` with the following: @@ -180,8 +180,8 @@ export async function main(args: { codeName: string, name: string, permissions: Then you can create a group through the command line. ```sh npm run build -foal run create-perm name="Permission to delete users" codeName="delete-users" -foal run create-group name="Administrators" codeName="admin" permissions="[ \"delete-users\" ]" +npx foal run create-perm name="Permission to delete users" codeName="delete-users" +npx foal run create-group name="Administrators" codeName="admin" permissions="[ \"delete-users\" ]" ``` ## Users @@ -289,7 +289,7 @@ Then you can create a user with their permissions and groups through the command ```sh npm run build -foal run create-user userPermissions="[ \"my-first-perm\" ]" groups="[ \"my-group\" ]" +npx foal run create-user userPermissions="[ \"my-first-perm\" ]" groups="[ \"my-group\" ]" ``` ## Fetching a User with their Permissions diff --git a/docs/docs/cli/code-generation.md b/docs/docs/cli/code-generation.md index 97cee3d1ef..a624ad7365 100644 --- a/docs/docs/cli/code-generation.md +++ b/docs/docs/cli/code-generation.md @@ -6,7 +6,7 @@ title: Code Generation ## Create a project ```shell -foal createapp my-app +npx @foal/cli createapp my-app ``` Create a new directory with all the required files to get started. @@ -18,15 +18,15 @@ If you specify the flag `--yaml`, the new project will use YAML format for its c ## Create a controller ```shell -foal g controller +npx foal g controller ``` Create a new controller in `./src/app/controllers`, in `./controllers` or in the current directory depending on which folders are found. *Example* ```shell -foal g controller auth -foal g controller api/product +npx foal g controller auth +npx foal g controller api/product ``` *Output* @@ -44,15 +44,15 @@ src/ ### The `--register` flag ```shell -foal g controller --register +npx foal g controller --register ``` If you wish to automatically create a new route attached to this controller, you can use the `--register` flag to do so. *Example* ```shell -foal g controller api --register -foal g controller api/product --register +npx foal g controller api --register +npx foal g controller api/product --register ``` *Output* @@ -89,15 +89,15 @@ export class ApiController { ## Create an entity ```shell -foal g entity +npx foal g entity ``` Create a new entity in `./src/app/entities`, in `./entities` or in the current directory depending on which folders are found. *Example* ```shell -foal g entity user -foal g entity business/product +npx foal g entity user +npx foal g entity business/product ``` *Output* @@ -115,15 +115,15 @@ src/ ## Create REST API ```shell -foal g rest-api +npx foal g rest-api ``` Create a new controller and a new entity to build a basic REST API. Depending on which directories are found, they will be generated in `src/app/{entities}|{controllers}/` or in `{entities}|{controllers}/`. *Example* ```shell -foal g rest-api order -foal g rest-api api/product +npx foal g rest-api order +npx foal g rest-api api/product ``` *Output* @@ -148,8 +148,8 @@ If you wish to automatically create a new route attached to this controller, you *Example* ```shell -foal g controller api --register -foal g controller api/product --register +npx foal g controller api --register +npx foal g controller api/product --register ``` See the page [REST Blueprints](../common/rest-blueprints.md) for more details. @@ -157,15 +157,15 @@ See the page [REST Blueprints](../common/rest-blueprints.md) for more details. ## Create a hook ```shell -foal g hook +npx foal g hook ``` Create a new hook in `./src/app/hooks`, in `./hooks` or in the current directory depending on which folders are found. *Example* ```shell -foal g hook log -foal g hook auth/admin-required +npx foal g hook log +npx foal g hook auth/admin-required ``` *Output* @@ -184,7 +184,7 @@ src/ ## Create a script ```shell -foal g script +npx foal g script ``` Create a new shell script in `src/scripts` regardless of where you run the command. @@ -192,15 +192,15 @@ Create a new shell script in `src/scripts` regardless of where you run the comma ## Create a service ```shell -foal g service +npx foal g service ``` Create a new service in `./src/app/services`, in `./services` or in the current directory depending on which folders are found. *Example* ```shell -foal g service auth -foal g service apis/github +npx foal g service auth +npx foal g service apis/github ``` *Output* diff --git a/docs/docs/cli/commands.md b/docs/docs/cli/commands.md index 19d96bcf04..cdb680091e 100644 --- a/docs/docs/cli/commands.md +++ b/docs/docs/cli/commands.md @@ -10,4 +10,4 @@ FoalTS provides several commands to help you build and develop your app. | `npm run dev` | Build the source code and start the server. If a file changes then the code is rebuilt and the server reloads. This is usually **the only command that you need during development** | | `npm run build` | Build the app code located in the `src/` directory (test files are ignored). | | `npm run start` | Start the server from the built files. | -| `foal upgrade [version]` | Upgrade all local `@foal/*` dependencies and dev dependencies to the given version. If no version is provided, then the command upgrades to the latest version of Foal. An additional flag `--no-install` can be provided to not trigger the npm or yarn installation. | +| `npx foal upgrade [version]` | Upgrade all local `@foal/*` dependencies and dev dependencies to the given version. If no version is provided, then the command upgrades to the latest version of Foal. An additional flag `--no-install` can be provided to not trigger the npm or yarn installation. | diff --git a/docs/docs/cli/shell-scripts.md b/docs/docs/cli/shell-scripts.md index d3890d9b81..28f99c7a2d 100644 --- a/docs/docs/cli/shell-scripts.md +++ b/docs/docs/cli/shell-scripts.md @@ -9,7 +9,7 @@ Sometimes we have to execute some tasks from the command line. These tasks can s A shell script is just a TypeScript file located in the `src/scripts`. It must export a `main` function that is then called when running the script. -Let's create a new one with the command line: `foal g script display-users`. A new file with a default template should appear in you `src/scripts` directory. +Let's create a new one with the command line: `npx foal g script display-users`. A new file with a default template should appear in you `src/scripts` directory. ## Write Scripts @@ -55,9 +55,9 @@ npm run build Then you can execute it with this command: ```shell -foal run my-script # or foal run-script my-script +npx foal run my-script # or npx foal run-script my-script ``` -> You can also provide additionnal arguments to your script (for example: `foal run my-script foo=1 bar='[ 3, 4 ]'`). The default template in the generated scripts shows you how to handle such behavior. +> You can also provide additionnal arguments to your script (for example: `npx foal run my-script foo=1 bar='[ 3, 4 ]'`). The default template in the generated scripts shows you how to handle such behavior. > If you want your script to recompile each time you save the file, you can run `npm run dev` in a separate terminal. diff --git a/docs/docs/common/gRPC.md b/docs/docs/common/gRPC.md index ee461e3113..845290803d 100644 --- a/docs/docs/common/gRPC.md +++ b/docs/docs/common/gRPC.md @@ -19,11 +19,11 @@ Then update your `package.json` so that your build scripts will correctly copy y ```json { - "build": "foal rmdir build && cpx \"src/**/*.proto\" build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && cpx \"src/**/*.proto\" build && tsc -p tsconfig.app.json", "dev": "npm run build && concurrently \"cpx \\\"src/**/*.proto\\\" build -w\" \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml,proto --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && cpx \"src/**/*.proto\" build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && cpx \"src/**/*.proto\" build && tsc -p tsconfig.test.json", "test": "npm run build:test && concurrently \"cpx \\\"src/**/*.proto\\\" build -w\" \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w --watch-files build \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && cpx \"src/**/*.proto\" build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && cpx \"src/**/*.proto\" build && tsc -p tsconfig.e2e.json", "e2e": "npm run build:e2e && concurrently \"cpx \\\"src/**/*.proto\\\" build -w\" \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w --watch-files build \\\"./build/e2e/**/*.js\\\"\"", ... } diff --git a/docs/docs/common/graphql.md b/docs/docs/common/graphql.md index 8357980877..b6de5a7128 100644 --- a/docs/docs/common/graphql.md +++ b/docs/docs/common/graphql.md @@ -153,11 +153,11 @@ npm install cpx2 --save-dev ```json { "scripts": { - "build": "foal rmdir build && cpx \"src/**/*.graphql\" build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && cpx \"src/**/*.graphql\" build && tsc -p tsconfig.app.json", "dev": "npm run build && concurrently \"cpx \\\"src/**/*.graphql\\\" build -w\" \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml,graphql --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && cpx \"src/**/*.graphql\" build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && cpx \"src/**/*.graphql\" build && tsc -p tsconfig.test.json", "test": "npm run build:test && concurrently \"cpx \\\"src/**/*.graphql\\\" build -w\" \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w --watch-files build \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && cpx \"src/**/*.graphql\" build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && cpx \"src/**/*.graphql\" build && tsc -p tsconfig.e2e.json", "e2e": "npm run build:e2e && concurrently \"cpx \\\"src/**/*.graphql\\\" build -w\" \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w --watch-files build \\\"./build/e2e/**/*.js\\\"\"", ... } diff --git a/docs/docs/common/openapi-and-swagger-ui.md b/docs/docs/common/openapi-and-swagger-ui.md index 0362e6de72..1f8fdcce1a 100644 --- a/docs/docs/common/openapi-and-swagger-ui.md +++ b/docs/docs/common/openapi-and-swagger-ui.md @@ -384,7 +384,7 @@ class Service { #### from a shell script ``` -foal generate script generate-openapi-doc +npx foal generate script generate-openapi-doc ``` The `createOpenApiDocument` function can also be used in a shell script to generate the document. You can provide it with an optional serviceManager if needed. @@ -414,7 +414,7 @@ export async function main() { ```bash npm run build -foal run generate-openapi-doc +npx foal run generate-openapi-doc ``` @@ -746,7 +746,7 @@ export class ApiController { ### Generate and Save a Specification File with a Shell Script ``` -foal generate script generate-openapi-doc +npx foal generate script generate-openapi-doc ``` *src/scripts/generate-openapi-doc.ts* @@ -772,7 +772,7 @@ export async function main() { ``` npm run build -foal run generate-openapi-doc +npx foal run generate-openapi-doc ``` ### Common Errors diff --git a/docs/docs/common/rest-blueprints.md b/docs/docs/common/rest-blueprints.md index 8e38417410..669e3857f2 100644 --- a/docs/docs/common/rest-blueprints.md +++ b/docs/docs/common/rest-blueprints.md @@ -5,13 +5,13 @@ title: REST API *Example:* ``` -foal generate rest-api product --register +npx foal generate rest-api product --register ``` Building a REST API is often a common task when creating an application. To avoid reinventing the wheel, FoalTS provides a CLI command to achieve this. ``` -foal generate rest-api [--register] [--auth] +npx foal generate rest-api [--register] [--auth] ``` This command generates three files: an entity, a controller and the controller's test. Depending on your directory structure, they may be generated in different locations: @@ -125,7 +125,7 @@ If you wish to attach a user to the resource, you can use the `--auth` flag to d *Example:* ``` -foal generate rest-api product --auth +npx foal generate rest-api product --auth ``` This flags adds an `owner: User` column to your entity and uses it in the API. diff --git a/docs/docs/common/task-scheduling.md b/docs/docs/common/task-scheduling.md index fa4ee58ed4..e4e699bb39 100644 --- a/docs/docs/common/task-scheduling.md +++ b/docs/docs/common/task-scheduling.md @@ -38,7 +38,7 @@ export async function main(args: any) { Schedule the job(s): ```sh npm run build -foal run schedule-jobs arg1=value1 +npx foal run schedule-jobs arg1=value1 ``` ## Background Jobs with pm2 diff --git a/docs/docs/common/utilities.md b/docs/docs/common/utilities.md index c67efb3169..920a507dbf 100644 --- a/docs/docs/common/utilities.md +++ b/docs/docs/common/utilities.md @@ -21,7 +21,7 @@ const token = await generateToken(); You can also generate a token using a secret. The secret is used to *sign* the token to provide extra security. It must be encoded in base64. You can generate one with the following command: ``` -foal createsecret +npx foal createsecret ``` **Generate a signed token** diff --git a/docs/docs/databases/other-orm/introduction.md b/docs/docs/databases/other-orm/introduction.md index fa39125473..f4f4cfd2a6 100644 --- a/docs/docs/databases/other-orm/introduction.md +++ b/docs/docs/databases/other-orm/introduction.md @@ -31,4 +31,4 @@ To do so, you will have to remove TypeORM and all its utilities. When using another ORM than TypeORM some features are not available: - the *Groups & Permissions* system, -- and the `foal g rest-api` command. \ No newline at end of file +- and the `npx foal g rest-api` command. \ No newline at end of file diff --git a/docs/docs/databases/typeorm/create-models-and-queries.md b/docs/docs/databases/typeorm/create-models-and-queries.md index 1216c8ba52..727e52c49d 100644 --- a/docs/docs/databases/typeorm/create-models-and-queries.md +++ b/docs/docs/databases/typeorm/create-models-and-queries.md @@ -4,7 +4,7 @@ title: Models & Queries ```shell -foal generate entity my-entity +npx foal generate entity my-entity ``` ## Entities diff --git a/docs/docs/databases/typeorm/mongodb.md b/docs/docs/databases/typeorm/mongodb.md index addd7f3806..3157c7a54f 100644 --- a/docs/docs/databases/typeorm/mongodb.md +++ b/docs/docs/databases/typeorm/mongodb.md @@ -12,7 +12,7 @@ import TabItem from '@theme/TabItem'; To generate a new project that uses MongoDB, run the command `createapp` with the flag `--mongodb`. ``` -foal createapp my-app --mongodb +npx @foal/cli createapp my-app --mongodb ``` ## Configuration @@ -136,6 +136,6 @@ If you use sessions with `@UseSessions`, you must use the `MongoDBStore` from `@ ## Limitations When using MongoDB, there are some features that are not available: -- the `foal g rest-api ` command, +- the `npx foal g rest-api ` command, - and the *Groups & Permissions* system. diff --git a/docs/docs/deployment-and-environments/checklist.md b/docs/docs/deployment-and-environments/checklist.md index aaab35e289..0e5c5d4b89 100644 --- a/docs/docs/deployment-and-environments/checklist.md +++ b/docs/docs/deployment-and-environments/checklist.md @@ -49,7 +49,7 @@ SETTINGS_JWT_SECRET=YZP0iv6gM+VBTxk61l8nKUno2QxsQHO9hm8XfeedZUw You can generate 256-bit secrets encoded in base64 with the following command: ```bash -foal createsecret +npx foal createsecret ``` ## Database Credentials & Migrations diff --git a/docs/docs/frontend/angular-react-vue.md b/docs/docs/frontend/angular-react-vue.md index 773320334e..6685c21997 100644 --- a/docs/docs/frontend/angular-react-vue.md +++ b/docs/docs/frontend/angular-react-vue.md @@ -4,9 +4,9 @@ title: Angular, React & Vue ``` -foal connect angular ../frontend -foal connect react ../frontend -foal connect vue ../frontend +npx foal connect angular ../frontend +npx foal connect react ../frontend +npx foal connect vue ../frontend ``` Angular, React and Vue all provide powerful CLIs for creating frontend applications. These tools are widely used, regularly improved and extensively documented. That's why Foal CLI do not provide ready-made features to build the frontend in their place. @@ -21,11 +21,11 @@ Instead, FoalTS offers a convenient command, named `connect`, to configure your mkdir my-app cd my-app -foal createapp backend +npx @foal/cli createapp backend ng new frontend cd backend -foal connect angular ../frontend +npx foal connect angular ../frontend ``` ### React @@ -34,11 +34,11 @@ foal connect angular ../frontend mkdir my-app cd my-app -foal createapp backend +npx @foal/cli createapp backend npx create-react-app frontend --template typescript cd backend -foal connect react ../frontend +npx foal connect react ../frontend ``` ### Vue @@ -47,11 +47,11 @@ foal connect react ../frontend mkdir my-app cd my-app -foal createapp backend +npx @foal/cli createapp backend vue create frontend cd backend -foal connect vue ../frontend +npx foal connect vue ../frontend ``` ## Problems Solved by the `connect` Command diff --git a/docs/docs/frontend/nuxt.js.md b/docs/docs/frontend/nuxt.js.md index d66956a759..8b5fbaadef 100644 --- a/docs/docs/frontend/nuxt.js.md +++ b/docs/docs/frontend/nuxt.js.md @@ -11,7 +11,7 @@ This document explains how to use it in conjunction with FoalTS. Create your frontend and backend projects in two different folders. ``` -foal createapp backend +npx @foal/cli createapp backend npx create-nuxt-app frontend ``` diff --git a/docs/docs/tutorials/real-world-example-with-react/1-introduction.md b/docs/docs/tutorials/real-world-example-with-react/1-introduction.md index 784d07077a..ea6028e9e2 100644 --- a/docs/docs/tutorials/real-world-example-with-react/1-introduction.md +++ b/docs/docs/tutorials/real-world-example-with-react/1-introduction.md @@ -48,7 +48,7 @@ Generate the backend application. ```bash cd foal-react-tuto -foal createapp backend-app +npx @foal/cli createapp backend-app ``` Then start the development server. diff --git a/docs/docs/tutorials/real-world-example-with-react/12-file-upload.md b/docs/docs/tutorials/real-world-example-with-react/12-file-upload.md index bd502c784f..55a817f85a 100644 --- a/docs/docs/tutorials/real-world-example-with-react/12-file-upload.md +++ b/docs/docs/tutorials/real-world-example-with-react/12-file-upload.md @@ -38,7 +38,7 @@ Then create the directory `assets/images/profiles/uploaded` where the profile im You are ready to create the controller. Generate a new one. ```bash -foal generate controller api/profile --register +npx foal generate controller api/profile --register ``` Open the new file `profile.controller.ts` and add two new routes. diff --git a/docs/docs/tutorials/real-world-example-with-react/14-production-build.md b/docs/docs/tutorials/real-world-example-with-react/14-production-build.md index b7ad0b9a3b..7358ae68f6 100644 --- a/docs/docs/tutorials/real-world-example-with-react/14-production-build.md +++ b/docs/docs/tutorials/real-world-example-with-react/14-production-build.md @@ -18,7 +18,7 @@ This command builds the React application for production and saves the files in Open it and copy all its contents to the `public` directory of your Foal application. -> When you use `foal connect` with Angular or Vue, the frontend build will automatically save the files in `public`. +> When you use `npx foal connect` with Angular or Vue, the frontend build will automatically save the files in `public`. Now, if you navigate to [http://localhost:3001](http://localhost:3001), you will see the frontend application served by the backend server. diff --git a/docs/docs/tutorials/real-world-example-with-react/15-social-auth.md b/docs/docs/tutorials/real-world-example-with-react/15-social-auth.md index 92caa379c7..b0609ca731 100644 --- a/docs/docs/tutorials/real-world-example-with-react/15-social-auth.md +++ b/docs/docs/tutorials/real-world-example-with-react/15-social-auth.md @@ -100,7 +100,7 @@ GOOGLE_CLIENT_SECRET="your Google client secret" Create the controller. ```bash -foal generate controller api/social-auth --register +npx foal generate controller api/social-auth --register ``` Open the file and add two new routes. diff --git a/docs/docs/tutorials/real-world-example-with-react/3-the-models.md b/docs/docs/tutorials/real-world-example-with-react/3-the-models.md index 38d8643f2d..20b76edc21 100644 --- a/docs/docs/tutorials/real-world-example-with-react/3-the-models.md +++ b/docs/docs/tutorials/real-world-example-with-react/3-the-models.md @@ -48,7 +48,7 @@ export { DatabaseSession } from '@foal/typeorm'; Then create your second entity. ``` -foal generate entity story +npx foal generate entity story ``` Open the new file and add three new properties: `author`, `title` and `link`. diff --git a/docs/docs/tutorials/real-world-example-with-react/4-the-shell-scripts.md b/docs/docs/tutorials/real-world-example-with-react/4-the-shell-scripts.md index ed674fee83..ddd67c5cd1 100644 --- a/docs/docs/tutorials/real-world-example-with-react/4-the-shell-scripts.md +++ b/docs/docs/tutorials/real-world-example-with-react/4-the-shell-scripts.md @@ -68,8 +68,8 @@ npm run build Then create two new users. ```bash -foal run create-user email="john@foalts.org" password="john_password" name="John" -foal run create-user email="mary@foalts.org" password="mary_password" name="Mary" +npx foal run create-user email="john@foalts.org" password="john_password" name="John" +npx foal run create-user email="mary@foalts.org" password="mary_password" name="Mary" ``` > If you try to re-run one of these commands, you'll get the MySQL error below as the email key is unique. @@ -81,7 +81,7 @@ foal run create-user email="mary@foalts.org" password="mary_password" name="Mary The `create-story` script is a bit more complex as `Story` has a many-to-one relation with `User`. ```bash -foal generate script create-story +npx foal generate script create-story ``` Open the `create-story.ts` file and replace its content. @@ -135,7 +135,7 @@ npm run build And create new stories for each user. ```bash -foal run create-story author="john@foalts.org" title="How to build a simple to-do list" link="https://foalts.org/docs/tutorials/simple-todo-list/1-installation" -foal run create-story author="mary@foalts.org" title="FoalTS architecture overview" link="https://foalts.org/docs/architecture/architecture-overview" -foal run create-story author="mary@foalts.org" title="Authentication with Foal" link="https://foalts.org/docs/authentication/quick-start" +npx foal run create-story author="john@foalts.org" title="How to build a simple to-do list" link="https://foalts.org/docs/tutorials/simple-todo-list/1-installation" +npx foal run create-story author="mary@foalts.org" title="FoalTS architecture overview" link="https://foalts.org/docs/architecture/architecture-overview" +npx foal run create-story author="mary@foalts.org" title="Authentication with Foal" link="https://foalts.org/docs/authentication/quick-start" ``` diff --git a/docs/docs/tutorials/real-world-example-with-react/5-our-first-route.md b/docs/docs/tutorials/real-world-example-with-react/5-our-first-route.md index ad7e0c4b8a..7a381c074a 100644 --- a/docs/docs/tutorials/real-world-example-with-react/5-our-first-route.md +++ b/docs/docs/tutorials/real-world-example-with-react/5-our-first-route.md @@ -13,7 +13,7 @@ The database is now filled with some stories. Let's implement the first route to First, generate the story controller. ```bash -foal generate controller api/stories --register +npx foal generate controller api/stories --register ``` A new file appears in the `api` subdirectory. Open it and replace its contents. diff --git a/docs/docs/tutorials/real-world-example-with-react/6-swagger-interface.md b/docs/docs/tutorials/real-world-example-with-react/6-swagger-interface.md index cccbca3843..a0325cced6 100644 --- a/docs/docs/tutorials/real-world-example-with-react/6-swagger-interface.md +++ b/docs/docs/tutorials/real-world-example-with-react/6-swagger-interface.md @@ -38,7 +38,7 @@ export class ApiController { Then generate a new controller. This one will be in charge of rendering the new page. ```bash -foal generate controller openapi --register +npx foal generate controller openapi --register ``` Make the generated class extend the abstract class `SwaggerController`. And then provide the root controller of your API as an option to the controller. diff --git a/docs/docs/tutorials/real-world-example-with-react/7-add-frontend.md b/docs/docs/tutorials/real-world-example-with-react/7-add-frontend.md index d97773a5f7..103ae478ab 100644 --- a/docs/docs/tutorials/real-world-example-with-react/7-add-frontend.md +++ b/docs/docs/tutorials/real-world-example-with-react/7-add-frontend.md @@ -30,7 +30,7 @@ Another way to solve this problem is to *connect* your front-end development ser ```bash cd ../backend-app -foal connect react ../frontend-app +npx foal connect react ../frontend-app ``` If you restart the frontend server, the stories should display correctly on the *feed* page (except for the images). diff --git a/docs/docs/tutorials/real-world-example-with-react/8-authentication.md b/docs/docs/tutorials/real-world-example-with-react/8-authentication.md index c372e5c140..f1b6456d2f 100644 --- a/docs/docs/tutorials/real-world-example-with-react/8-authentication.md +++ b/docs/docs/tutorials/real-world-example-with-react/8-authentication.md @@ -47,7 +47,7 @@ When used with the `cookie` option, this hook ensures that `ctx.session` is alwa Create a new controller. ```bash -foal generate controller api/auth --register +npx foal generate controller api/auth --register ``` Open the new created file and add two routes. diff --git a/docs/docs/tutorials/simple-todo-list/1-installation.md b/docs/docs/tutorials/simple-todo-list/1-installation.md index 336877aab6..2dd07ae3be 100644 --- a/docs/docs/tutorials/simple-todo-list/1-installation.md +++ b/docs/docs/tutorials/simple-todo-list/1-installation.md @@ -21,7 +21,7 @@ npm install -g @foal/cli Then create a new application. ```sh -foal createapp my-app +npx @foal/cli createapp my-app ``` :::note diff --git a/docs/docs/tutorials/simple-todo-list/3-the-todo-model.md b/docs/docs/tutorials/simple-todo-list/3-the-todo-model.md index 103e7f6556..5393f56862 100644 --- a/docs/docs/tutorials/simple-todo-list/3-the-todo-model.md +++ b/docs/docs/tutorials/simple-todo-list/3-the-todo-model.md @@ -9,7 +9,7 @@ The next step is to take care of the database. By default, every new project in Let’s start by creating your first model. The CLI provides a useful command to generate a new file with an empty model. ```sh -foal generate entity todo +npx foal generate entity todo ``` :::info diff --git a/docs/docs/tutorials/simple-todo-list/4-the-shell-script-create-todo.md b/docs/docs/tutorials/simple-todo-list/4-the-shell-script-create-todo.md index 09d6270f42..0c392683c2 100644 --- a/docs/docs/tutorials/simple-todo-list/4-the-shell-script-create-todo.md +++ b/docs/docs/tutorials/simple-todo-list/4-the-shell-script-create-todo.md @@ -11,7 +11,7 @@ You could run the command line interface of your database (in that case *SQLite* That's why you are going to create and use a *shell script* instead. ```sh -foal generate script create-todo +npx foal generate script create-todo ``` A *shell script* is a piece of code intended to be called from the command line. It has access to all the components of your application, including your models. A shell script is divided in two parts: @@ -64,9 +64,9 @@ npm run build Then run the script to create tasks in the database. ```sh -foal run create-todo text="Read the docs" -foal run create-todo text="Create my first application" -foal run create-todo text="Write tests" +npx foal run create-todo text="Read the docs" +npx foal run create-todo text="Create my first application" +npx foal run create-todo text="Write tests" ``` > Note that if you try to create a new to-do without specifying the text argument, you'll get the error below. diff --git a/e2e_test.sh b/e2e_test.sh index 0c8e069367..52130ddace 100755 --- a/e2e_test.sh +++ b/e2e_test.sh @@ -2,7 +2,6 @@ set -e rm -rf ./node_modules -npm install -g @foal/cli rm -rf e2e-test-temp @@ -10,7 +9,7 @@ mkdir e2e-test-temp cd e2e-test-temp # Test app creation -foal createapp my-app +npx --yes @foal/cli createapp my-app cd my-app # Check some compilation errors @@ -20,12 +19,12 @@ if grep -Rl "../../Users/loicp" .; then fi # Test the generators -foal g entity flight -foal g hook foo-bar -foal g service foo -foal g controller bar --register -foal g rest-api product --register -foal g script bar-script +npx foal g entity flight +npx foal g hook foo-bar +npx foal g service foo +npx foal g controller bar --register +npx foal g rest-api product --register +npx foal g script bar-script # Test linting npm run lint @@ -123,7 +122,7 @@ test_rest_api DELETE "http://localhost:3001/products/ab" 400 kill -9 $(ps aux | grep '\snode\s') # Test the default shell scripts to create users. -foal run create-user +npx foal run create-user ################################################################# # Repeat (almost) the same tests with a MongoDB and YAML project @@ -132,7 +131,7 @@ foal run create-user cd .. # Test app creation -foal createapp my-mongodb-app --mongodb --yaml +npx @foal/cli createapp my-mongodb-app --mongodb --yaml cd my-mongodb-app # Check some compilation errors @@ -156,17 +155,17 @@ npm run start:e2e npm run build # Test the application when it is started -# PORT=3001 pm2 start build/index.js -# sleep 1 -# response=$( -# curl http://localhost:3001 \ -# --write-out %{http_code} \ -# --silent \ -# --output /dev/null \ -# ) -# test "$response" -ge 200 && test "$response" -le 299 - -# pm2 delete index +node build/index.js & +sleep 1 +response=$( + curl http://localhost:3001 \ + --write-out %{http_code} \ + --silent \ + --output /dev/null \ +) +test "$response" -ge 200 && test "$response" -le 299 + +kill -9 $(ps aux | grep '\snode\s') # Test the default shell scripts to create users. -foal run create-user +npx foal run create-user diff --git a/packages/acceptance-tests/src/additional/shell-scripts/create-group.spec.ts b/packages/acceptance-tests/src/additional/shell-scripts/create-group.spec.ts index e609321c20..a56e005e62 100644 --- a/packages/acceptance-tests/src/additional/shell-scripts/create-group.spec.ts +++ b/packages/acceptance-tests/src/additional/shell-scripts/create-group.spec.ts @@ -21,7 +21,7 @@ describe('[Shell scripts] create-perm', () => { }); it('should work as expected.', async () => { - // foal run create-group name="Administrators" codeName="admin" permissions='[ "delete-users" ]' + // npx foal run create-group name="Administrators" codeName="admin" permissions='[ "delete-users" ]' const args = { codeName: 'admin', name: 'Administrators', diff --git a/packages/acceptance-tests/src/additional/shell-scripts/create-perm.spec.ts b/packages/acceptance-tests/src/additional/shell-scripts/create-perm.spec.ts index c242771b39..4566c7c3f6 100644 --- a/packages/acceptance-tests/src/additional/shell-scripts/create-perm.spec.ts +++ b/packages/acceptance-tests/src/additional/shell-scripts/create-perm.spec.ts @@ -15,7 +15,7 @@ describe('[Shell scripts] create-perm', () => { }); it('should work as expected.', async () => { - // foal run create-perm name="Permission to access the secret" codeName="access-secret" + // npx foal run create-perm name="Permission to access the secret" codeName="access-secret" const args = { codeName: 'access-secret', name: 'Permission to access the secret' diff --git a/packages/cli/src/generate/generators/rest-api/create-rest-api.spec.ts b/packages/cli/src/generate/generators/rest-api/create-rest-api.spec.ts index 165f56ba02..9ed62151a1 100644 --- a/packages/cli/src/generate/generators/rest-api/create-rest-api.spec.ts +++ b/packages/cli/src/generate/generators/rest-api/create-rest-api.spec.ts @@ -19,7 +19,7 @@ describe('createRestApi', () => { throws( () => createRestApi({ name: 'test-fooBar', register: false }), - new ClientError('"foal generate|g rest-api " cannot be used in a MongoDB project.') + new ClientError('"npx foal generate|g rest-api " cannot be used in a MongoDB project.') ); }); diff --git a/packages/cli/src/generate/generators/rest-api/create-rest-api.ts b/packages/cli/src/generate/generators/rest-api/create-rest-api.ts index 064cc066fa..4de21d8360 100644 --- a/packages/cli/src/generate/generators/rest-api/create-rest-api.ts +++ b/packages/cli/src/generate/generators/rest-api/create-rest-api.ts @@ -14,7 +14,7 @@ export function createRestApi({ name, register, auth }: { name: string, register const fs = new FileSystem(); if (fs.projectHasDependency('mongodb')) { - throw new ClientError('"foal generate|g rest-api " cannot be used in a MongoDB project.'); + throw new ClientError('"npx foal generate|g rest-api " cannot be used in a MongoDB project.'); } if (fs.exists('src/app/entities') && fs.exists('src/app/controllers')) { diff --git a/packages/cli/src/generate/specs/app/package.json b/packages/cli/src/generate/specs/app/package.json index 645ca0a4ef..cbc0447a42 100644 --- a/packages/cli/src/generate/specs/app/package.json +++ b/packages/cli/src/generate/specs/app/package.json @@ -5,18 +5,18 @@ "license": "MIT", "repository": {}, "scripts": { - "build": "foal rmdir build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && tsc -p tsconfig.app.json", "start": "node ./build/index.js", "dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && tsc -p tsconfig.test.json", "start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"", "test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && tsc -p tsconfig.e2e.json", "start:e2e": "mocha --timeout 4000 --file ./build/e2e.js \"./build/e2e/**/*.js\"", "e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"", "lint": "eslint --ext ts src", "lint:fix": "eslint --ext ts --fix src", - "makemigrations": "foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json", + "makemigrations": "npx foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json", "migrations": "npx typeorm migration:run -d build/db", "revertmigration": "npx typeorm migration:revert -d build/db" }, diff --git a/packages/cli/src/generate/specs/app/package.mongodb.json b/packages/cli/src/generate/specs/app/package.mongodb.json index 37290017a2..0dd2251d70 100644 --- a/packages/cli/src/generate/specs/app/package.mongodb.json +++ b/packages/cli/src/generate/specs/app/package.mongodb.json @@ -5,13 +5,13 @@ "license": "MIT", "repository": {}, "scripts": { - "build": "foal rmdir build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && tsc -p tsconfig.app.json", "start": "node ./build/index.js", "dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && tsc -p tsconfig.test.json", "start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"", "test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && tsc -p tsconfig.e2e.json", "start:e2e": "mocha --timeout 4000 --file ./build/e2e.js \"./build/e2e/**/*.js\"", "e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"", "lint": "eslint --ext ts src", diff --git a/packages/cli/src/generate/specs/app/package.mongodb.yaml.json b/packages/cli/src/generate/specs/app/package.mongodb.yaml.json index 7dcd6a0e74..5c36b2e8f0 100644 --- a/packages/cli/src/generate/specs/app/package.mongodb.yaml.json +++ b/packages/cli/src/generate/specs/app/package.mongodb.yaml.json @@ -5,13 +5,13 @@ "license": "MIT", "repository": {}, "scripts": { - "build": "foal rmdir build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && tsc -p tsconfig.app.json", "start": "node ./build/index.js", "dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && tsc -p tsconfig.test.json", "start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"", "test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && tsc -p tsconfig.e2e.json", "start:e2e": "mocha --timeout 4000 --file ./build/e2e.js \"./build/e2e/**/*.js\"", "e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"", "lint": "eslint --ext ts src", diff --git a/packages/cli/src/generate/specs/app/package.yaml.json b/packages/cli/src/generate/specs/app/package.yaml.json index acb5f0ada1..222c37049c 100644 --- a/packages/cli/src/generate/specs/app/package.yaml.json +++ b/packages/cli/src/generate/specs/app/package.yaml.json @@ -5,18 +5,18 @@ "license": "MIT", "repository": {}, "scripts": { - "build": "foal rmdir build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && tsc -p tsconfig.app.json", "start": "node ./build/index.js", "dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && tsc -p tsconfig.test.json", "start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"", "test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && tsc -p tsconfig.e2e.json", "start:e2e": "mocha --timeout 4000 --file ./build/e2e.js \"./build/e2e/**/*.js\"", "e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"", "lint": "eslint --ext ts src", "lint:fix": "eslint --ext ts --fix src", - "makemigrations": "foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json", + "makemigrations": "npx foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json", "migrations": "npx typeorm migration:run -d build/db", "revertmigration": "npx typeorm migration:revert -d build/db" }, diff --git a/packages/cli/src/generate/templates/app/package.json b/packages/cli/src/generate/templates/app/package.json index 72364f39d4..b51cd22f3e 100644 --- a/packages/cli/src/generate/templates/app/package.json +++ b/packages/cli/src/generate/templates/app/package.json @@ -5,18 +5,18 @@ "license": "MIT", "repository": {}, "scripts": { - "build": "foal rmdir build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && tsc -p tsconfig.app.json", "start": "node ./build/index.js", "dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && tsc -p tsconfig.test.json", "start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"", "test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && tsc -p tsconfig.e2e.json", "start:e2e": "mocha --timeout 4000 --file ./build/e2e.js \"./build/e2e/**/*.js\"", "e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"", "lint": "eslint --ext ts src", "lint:fix": "eslint --ext ts --fix src", - "makemigrations": "foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json", + "makemigrations": "npx foal rmdir build && tsc -p tsconfig.app.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.app.json", "migrations": "npx typeorm migration:run -d build/db", "revertmigration": "npx typeorm migration:revert -d build/db" }, diff --git a/packages/cli/src/generate/templates/app/package.mongodb.json b/packages/cli/src/generate/templates/app/package.mongodb.json index 377208b4b4..d871e2b1d4 100644 --- a/packages/cli/src/generate/templates/app/package.mongodb.json +++ b/packages/cli/src/generate/templates/app/package.mongodb.json @@ -5,13 +5,13 @@ "license": "MIT", "repository": {}, "scripts": { - "build": "foal rmdir build && tsc -p tsconfig.app.json", + "build": "npx foal rmdir build && tsc -p tsconfig.app.json", "start": "node ./build/index.js", "dev": "npm run build && concurrently -r \"tsc -p tsconfig.app.json -w\" \"supervisor -w ./build,./config -e js,json,yml --no-restart-on error ./build/index.js\"", - "build:test": "foal rmdir build && tsc -p tsconfig.test.json", + "build:test": "npx foal rmdir build && tsc -p tsconfig.test.json", "start:test": "mocha --file ./build/test.js \"./build/**/*.spec.js\"", "test": "npm run build:test && concurrently -r \"tsc -p tsconfig.test.json -w\" \"mocha --file ./build/test.js -w \\\"./build/**/*.spec.js\\\"\"", - "build:e2e": "foal rmdir build && tsc -p tsconfig.e2e.json", + "build:e2e": "npx foal rmdir build && tsc -p tsconfig.e2e.json", "start:e2e": "mocha --timeout 4000 --file ./build/e2e.js \"./build/e2e/**/*.js\"", "e2e": "npm run build:e2e && concurrently -r \"tsc -p tsconfig.e2e.json -w\" \"mocha --file ./build/e2e.js -w \\\"./build/e2e/**/*.js\\\"\"", "lint": "eslint --ext ts src", diff --git a/packages/cli/src/run-script/get-command-line-arguments.util.spec.ts b/packages/cli/src/run-script/get-command-line-arguments.util.spec.ts index fad364882f..083948cabd 100644 --- a/packages/cli/src/run-script/get-command-line-arguments.util.spec.ts +++ b/packages/cli/src/run-script/get-command-line-arguments.util.spec.ts @@ -6,7 +6,7 @@ import { getCommandLineArguments } from './get-command-line-arguments.util'; describe('getCommandLineArguments', () => { it('should convert the arguments to an object.', () => { - // foal run-script foo foo=barfoo bar='hello world' + // npx foal run-script foo foo=barfoo bar='hello world' const argv = [ '/Users/loicpoullain/.nvm/versions/node/v8.11.3/bin/node', '/Users/loicpoullain/.nvm/versions/node/v8.11.3/bin/foal', diff --git a/packages/cli/src/run-script/run-script.spec.ts b/packages/cli/src/run-script/run-script.spec.ts index 282e3c76e6..e5457f4f10 100644 --- a/packages/cli/src/run-script/run-script.spec.ts +++ b/packages/cli/src/run-script/run-script.spec.ts @@ -27,7 +27,7 @@ describe('runScript', () => { await runScript({ name: 'my-script' }, [], log); strictEqual( - msg, 'The script "my-script" does not exist. You can create it by running the command "foal g script my-script".' + msg, 'The script "my-script" does not exist. You can create it by running the command "npx foal g script my-script".' ); }); diff --git a/packages/cli/src/run-script/run-script.ts b/packages/cli/src/run-script/run-script.ts index ae396ecd3f..61eefef6a5 100644 --- a/packages/cli/src/run-script/run-script.ts +++ b/packages/cli/src/run-script/run-script.ts @@ -17,7 +17,7 @@ export async function runScript({ name }: { name: string }, argv: string[], log + ' Please build your script by running the command "npm run build" or using "npm run dev".' ); } else { - log(`The script "${name}" does not exist. You can create it by running the command "foal g script ${name}".`); + log(`The script "${name}" does not exist. You can create it by running the command "npx foal g script ${name}".`); } return; } diff --git a/packages/examples/package.json b/packages/examples/package.json index 0ff36bf1ea..7d85b0f3d1 100644 --- a/packages/examples/package.json +++ b/packages/examples/package.json @@ -16,7 +16,7 @@ "test": "npm run build:test && npm run start:test", "dev:test": "npm run build:test && concurrently \"npm run build:test:w\" \"npm run start:test:w\"", "lint": "tslint -c tslint.json -p tsconfig.json", - "makemigrations": "foal rmdir build && tsc -p tsconfig.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.json", + "makemigrations": "npx foal rmdir build && tsc -p tsconfig.json && npx typeorm migration:generate src/migrations/migration -d build/db -p && tsc -p tsconfig.json", "migrations": "npx typeorm migration:run -d build/db", "revertmigration": "npx typeorm migration:revert -d build/db" }, From cee0f7ddc235f3f63c8c3dbc1879eb3de5522c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poullain?= Date: Sat, 3 Aug 2024 18:48:19 +0200 Subject: [PATCH 2/4] Install @foal/cli globally to make the CI pass --- e2e_test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e_test.sh b/e2e_test.sh index 52130ddace..309ef67e06 100755 --- a/e2e_test.sh +++ b/e2e_test.sh @@ -2,6 +2,7 @@ set -e rm -rf ./node_modules +npm install -g @foal/cli rm -rf e2e-test-temp From a6ae74d46aeb793b1284c354796ee1b568b0aaa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poullain?= Date: Sat, 3 Aug 2024 19:08:24 +0200 Subject: [PATCH 3/4] [Blog] Add deprecating of global use of CLI --- docs/blog/version-4.5-release-notes.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/blog/version-4.5-release-notes.md b/docs/blog/version-4.5-release-notes.md index 910ecc6be2..6c5982a26f 100644 --- a/docs/blog/version-4.5-release-notes.md +++ b/docs/blog/version-4.5-release-notes.md @@ -14,3 +14,24 @@ Version 4.5 of [Foal](https://foalts.org/) is out! +## Global use of CLI deprecated + +In previous versions, the tutorial suggested installing the CLI globally to create a new application or generate files. However, it is considered bad practice to install a dependency globally for local use. + +In addition, the CLI was also installed locally so that the build command would work when deploying the application to a CI or to production. This maintained two versions of the same CLI + +To correct this, in the documentation and examples, the CLI is now always installed and used locally. To use it, simply add `npx` before each command (except for `createapp`). + +```bash +# Before +foal createapp my-app + +foal generate script foobar +foal createsecret + +# After +npx @foal/cli createapp my-app + +npx foal generate script foobar +npx foal createsecret +``` \ No newline at end of file From c506815e7a7750bdf3a08a1641c6ed4d5043035d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Poullain?= Date: Sat, 3 Aug 2024 19:10:36 +0200 Subject: [PATCH 4/4] [Blog] Fix sentence --- docs/blog/version-4.5-release-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/blog/version-4.5-release-notes.md b/docs/blog/version-4.5-release-notes.md index 6c5982a26f..b380d54653 100644 --- a/docs/blog/version-4.5-release-notes.md +++ b/docs/blog/version-4.5-release-notes.md @@ -18,7 +18,7 @@ Version 4.5 of [Foal](https://foalts.org/) is out! In previous versions, the tutorial suggested installing the CLI globally to create a new application or generate files. However, it is considered bad practice to install a dependency globally for local use. -In addition, the CLI was also installed locally so that the build command would work when deploying the application to a CI or to production. This maintained two versions of the same CLI +In addition, the CLI was also installed locally so that the build command would work when deploying the application to a CI or to production. This was maintaining two versions of the CLI. To correct this, in the documentation and examples, the CLI is now always installed and used locally. To use it, simply add `npx` before each command (except for `createapp`).