From ff5d4b52d38e204451fbb2c390360994583d9abc Mon Sep 17 00:00:00 2001 From: Florian Richter Date: Thu, 9 Jan 2020 12:50:56 +0100 Subject: [PATCH] Create custom README for scaffolded projects (#46) * Create custom README for scaffolded projects * Adjust test * Update snapshot --- src/commands/init.ts | 4 ++ src/templates/scaffold-readme/README.md | 71 +++++++++++++++++++ src/utils/scaffold.ts | 1 + test/init.spec.ts | 1 + .../utils/__snapshots__/scaffold.spec.ts.snap | 1 - 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 src/templates/scaffold-readme/README.md diff --git a/src/commands/init.ts b/src/commands/init.ts index 1802abf2..9567cb92 100644 --- a/src/commands/init.ts +++ b/src/commands/init.ts @@ -139,12 +139,16 @@ export default class Init extends Command { private getTemplateNames(isScaffold: boolean, addCds: boolean): string[] { const templates = ['init']; + if (addCds) { templates.push('add-cds'); if (isScaffold) { templates.push('add-cds-scaffold'); } } + if (isScaffold) { + templates.push('scaffold-readme'); + } return templates; } diff --git a/src/templates/scaffold-readme/README.md b/src/templates/scaffold-readme/README.md new file mode 100644 index 00000000..52809d2d --- /dev/null +++ b/src/templates/scaffold-readme/README.md @@ -0,0 +1,71 @@ +SAP Cloud SDK for JavaScript Logo + +# Welcome to Your Application! + +This is your **SAP Cloud Platform Cloud Foundry** application powered by the [SAP Cloud SDK for JavaScript](https://community.sap.com/topics/cloud-sdk) and [NestJS](https://nestjs.com/). + +## Getting started + +Everything is ready to go. + +```bash +# Run the application locally +$ npm run start:dev + +# Open the application in your default browser +$ open http://localhost:3000/ +``` + +If you have the [Cloud Foundry CLI](https://docs.cloudfoundry.org/cf-cli/install-go-cli.html) and are [logged in](https://docs.cloudfoundry.org/cf-cli/getting-started.html#login), you can deploy the application without any changes to the application. + +```bash +# Deploy your application to SAP Cloud Platform Cloud Foundry +$ cf push +``` + +## Testing + +The project comes with unit and end-to-end tests. +Unit tests are located in the `src/` folder next to the modules and controllers, while end-to-end tests are in the `test/` folder. + +```bash +# Run unit tests +$ npm run test + +# Run e2e tests +$ npm run test:e2e +``` + +## Continuous Integration + +This project is preconfigured to run with the [SAP Cloud SDK Pipeline](https://github.com/SAP/cloud-s4-sdk-pipeline). +To get the installer follow the short [guide](https://github.com/SAP/cloud-s4-sdk-pipeline#download-and-installation). + +```bash +# If you have the SAP Cloud SDK CLI installed, it can download the install script for you +sap-cloud-sdk add-cx-server + +# Execute the script to start the Jenkins server +$ ./cx-server start +``` + +Point the new Jenkins to your repository and it will automatically run the pipeline. +If the pipeline should deploy your application as well, you need to modify the `pipeline_config.yml`. + +## NestJS + +NestJS is a progressive [Node.js](http://nodejs.org) framework for building efficient and scalable server-side applications, heavily inspired by [Angular](https://angular.io). + +The [Nest CLI](https://docs.nestjs.com/cli/usages) is a powerful tool and can help you create new controllers, modules and interfaces. + +## Support + +If you need support with the SAP Cloud SDK, the SAP Cloud SDK CLI or this project scaffold, feel free to open an issue on [GitHub](https://github.com/SAP/cloud-sdk-cli) or ask a question on [stackoverflow with tag [sap-cloud-sdk]](https://stackoverflow.com/questions/tagged/sap-cloud-sdk). + +## License and Notice + +The SAP Cloud SDK CLI is licensed under the [Apache Software License, v. 2](https://github.com/SAP/cloud-sdk-cli/blob/master/LICENSE). +Nest is [MIT licensed](https://github.com/nestjs/nest/blob/master/LICENSE). + +The SAP Cloud SDK is in no way affiliated with or endorsed by Nest and its maintainers. +While Nest is our recommendation, the SAP Cloud SDK can be used with any framework, so you are free to choose what you are comfortable with. diff --git a/src/utils/scaffold.ts b/src/utils/scaffold.ts index 2e93b428..51e88873 100644 --- a/src/utils/scaffold.ts +++ b/src/utils/scaffold.ts @@ -48,6 +48,7 @@ export async function buildScaffold(projectDir: string, verbose: boolean, addCds await execa('npx', ['-p', '@nestjs/cli', 'nest', 'new', '.', '--skip-install', '--package-manager', 'npm'], options); + fs.unlinkSync(path.resolve(projectDir, 'README.md')); modifyMainTs(path.resolve(projectDir, 'src', 'main.ts')); if (addCds) { addCatalogueModule(path.resolve(projectDir, 'src', 'app.module.ts')); diff --git a/test/init.spec.ts b/test/init.spec.ts index 45098de1..cab44b8c 100644 --- a/test/init.spec.ts +++ b/test/init.spec.ts @@ -42,6 +42,7 @@ describe('Init', () => { }); const reportsPath = path.resolve(projectDir, 's4hana_pipeline', 'reports'); + expect(fs.readFileSync(path.resolve(projectDir, 'README.md'), { encoding: 'utf8' })).toInclude('SAP Cloud SDK'); // execute the ci scripts and check if the reports are written await execa('npm', ['run', 'ci-backend-unit-test'], { cwd: projectDir, stdio: 'inherit' }); diff --git a/test/utils/__snapshots__/scaffold.spec.ts.snap b/test/utils/__snapshots__/scaffold.spec.ts.snap index 38dcdbd3..0bf16a30 100644 --- a/test/utils/__snapshots__/scaffold.spec.ts.snap +++ b/test/utils/__snapshots__/scaffold.spec.ts.snap @@ -4,7 +4,6 @@ exports[`Scaffold Utils should build the scaffold 1`] = ` Array [ ".git", ".gitignore", - "README.md", "nest-cli.json", "package.json", "src",