Skip to content

Commit b54465a

Browse files
fix(cli): update the developing.md.tpl in @sourceloop/cli while scaffolding (#2213)
* fix(cli): update the developing.md update the developing.md 791 * fix(cli): update developing.md file update developing.md file 791 --------- Co-authored-by: yeshamavani <[email protected]>
1 parent 78a0875 commit b54465a

File tree

1 file changed

+38
-206
lines changed

1 file changed

+38
-206
lines changed

packages/cli/src/generators/scaffold/templates/DEVELOPING.md.tpl

Lines changed: 38 additions & 206 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ Our monorepo comes with few preconfigured
3636

3737
1. Open root folder of this repo in VS Code.
3838
2. Install lerna globally `npm i -g lerna`
39-
3. Run `lerna bootstrap`
40-
4. Run `npm i`
41-
5. Create .env files for all the micro service packages.
42-
6. Run DB migrations using `lerna run db:migrate`.
43-
7. Build all microservices in one go - `lerna run build`.
44-
8. Run `lerna run start` to start all the micro services in one go.
39+
3. Run `npm i`
40+
4. Create .env files for all the micro service packages.
41+
5. Run DB migrations using `lerna run db:migrate`.
42+
6. Build all microservices in one go - `lerna run build`.
43+
7. Run `lerna run start` to start all the micro services in one go.
4544

4645
## Building the project
4746

@@ -51,10 +50,10 @@ command will install npm dependencies for all packages and create symbolic links
5150
for intra-dependencies:
5251

5352
```sh
54-
lerna bootstrap
53+
npm i
5554
```
5655

57-
As part of `lerna bootstrap`, TypeScript project references are automatically
56+
As part of `npm i`, TypeScript project references are automatically
5857
updated for each package with in the monorepo.
5958

6059
The next step is to compile all packages from TypeScript to JavaScript:
@@ -127,6 +126,28 @@ $ npx lerna add --scope @loopback/rest debug
127126
See [lerna add](https://github.com/lerna/lerna/blob/master/commands/add#readme)
128127
for more details.
129128

129+
**Install a Dependency in a Specific Service via npm workspaces**
130+
131+
To install a dependency only in specific service, you can use the following command from the root of the workspace:
132+
133+
```sh
134+
$ npm install <dependency-name> --workspace=<workspaces-name>
135+
```
136+
The root/package.json should have a workspaces field listing the workspace folders:
137+
138+
```json
139+
{
140+
"name": "monorepo-root",
141+
"private": true,
142+
"workspaces": [
143+
"service-a",
144+
"service-b"
145+
]
146+
}
147+
148+
```
149+
150+
130151
## File naming convention
131152

132153
For consistency, we follow
@@ -156,209 +177,20 @@ src/__tests__/unit/application.unit.ts
156177

157178
## Develop a new microservice
158179

159-
1. **lb4 <service_name>** - Generate a new loopback-next application under the required folder, either facades or services.
160-
2. **.dockerignore** - Replace node_modules with coverage
161-
3. **.prettierignore** - Add coverage
162-
4. **.eslintrc.js** - Just copy below as is
163-
164-
```json
165-
module.exports = {
166-
extends: '@loopback/eslint-config',
167-
rules: {
168-
'no-extra-boolean-cast': 'off',
169-
'@typescript-eslint/interface-name-prefix': 'off',
170-
'no-prototype-builtins': 'off',
171-
},
172-
parserOptions: {
173-
project: './tsconfig.json',
174-
tsconfigRootDir: __dirname,
175-
},
176-
};
177-
```
178-
179-
5. **Necessary deps** - Add symlink-resolver package to devDependencies
180-
181-
```sh
182-
lerna add -D symlink-resolver --scope={service name}
183-
```
184-
185-
then add these two in scripts of package.json
186-
187-
```json
188-
"symlink-resolver": "symlink-resolver",
189-
"resolve-links": "npm run symlink-resolver build ./node_modules",
190-
```
191-
192-
6. **Dotenv** - Add dotenv packages for environment keys handling. Run below
193-
194-
```sh
195-
lerna add dotenv --scope={service name}
196-
lerna add dotenv-extended --scope={service name}
197-
lerna add -D @types/dotenv --scope={service name}
198-
```
199-
200-
7. **Env files** - Add .env.defaults and .env.example and specify required keys
201-
8. **Load .env** - Add below code to the top of `application.ts` before super call.
202-
203-
```ts
204-
const port = 3000;
205-
dotenv.config();
206-
dotenvExt.load({
207-
schema: '.env.example',
208-
errorOnMissing: true,
209-
includeProcessEnv: true,
210-
});
211-
options.rest = options.rest || {};
212-
options.rest.port = +(process.env.PORT || port);
213-
options.rest.host = process.env.HOST;
214-
```
215-
216-
Import dotenv related packages
217-
218-
```ts
219-
import * as dotenv from 'dotenv';
220-
import * as dotenvExt from 'dotenv-extended';
221-
```
222-
223-
9. **Add Sourceloop core** - Add @sourceloop/core as dependency to the module
224-
225-
```sh
226-
lerna add @sourceloop/core --scope={service name}
227-
```
228-
229-
In application.ts,
230-
231-
```ts
232-
import {CoreComponent, ServiceSequence} from '@sourceloop/core';
233-
234-
this.component(CoreComponent);
235-
236-
// Set up the custom sequence
237-
this.sequence(ServiceSequence);
238-
```
239-
240-
10. **Bearer Verifier** - Add bearer verifier to your service
241-
242-
```sh
243-
lerna add loopback4-authentication --scope={service name}
244-
lerna add loopback4-authorization --scope={service name}
245-
```
246-
247-
Add below to application.ts
248-
249-
```ts
250-
...
251-
import {AuthenticationComponent} from 'loopback4-authentication';
252-
import {
253-
AuthorizationBindings,
254-
AuthorizationComponent,
255-
} from 'loopback4-authorization';
256-
import {
257-
BearerVerifierBindings,
258-
BearerVerifierComponent,
259-
BearerVerifierConfig,
260-
BearerVerifierType,
261-
} from '@sourceloop/core';
262-
...
263-
// Add authentication component
264-
this.component(AuthenticationComponent);
265-
266-
// Add bearer verifier component
267-
this.bind(BearerVerifierBindings.Config).to({
268-
authServiceUrl: '',
269-
type: BearerVerifierType.service,
270-
} as BearerVerifierConfig);
271-
this.component(BearerVerifierComponent);
272-
273-
// Add authorization component
274-
this.bind(AuthorizationBindings.CONFIG).to({
275-
allowAlwaysPaths: ['/explorer'],
276-
});
277-
this.component(AuthorizationComponent);
278-
```
279-
280-
Use BearerVerifierType.facade for facades.
281-
282-
11. **Setup project for test coverage** -
283-
284-
Create a file named .nycrc and copy this data in it
285-
286-
```json
287-
{
288-
"extends": "@istanbuljs/nyc-config-typescript",
289-
"all": true,
290-
"reporter": ["html", "text-summary"]
291-
}
292-
```
293-
294-
Install nyc for coverage reporting
295-
296-
```sh
297-
lerna add -D @istanbuljs/nyc-config-typescript --scope={service name}
298-
lerna add -D nyc --scope={service name}
299-
```
300-
301-
then add these in scripts of package.json
180+
1. **sl microservice** - Generate a new sourceloop application under the required folder, either facades or services.
302181

303-
```json
304-
"coverage": "nyc npm run test",
305-
```
306182

307-
12. **Setup sequence** - Remove auto-generated sequence.ts and change to ServiceSequence in application.ts.
308-
13. **Fix api explorer** - Update base path in index.html for facades.
309-
310-
```html
311-
<body>
312-
<div class="info">
313-
<h1>auth-facade</h1>
314-
<p>Version 1.0.0</p>
315-
316-
<h3>OpenAPI spec: <a href="${basePath}/openapi.json">/openapi.json</a></h3>
317-
<h3>API Explorer: <a href="${basePath}/explorer">/explorer</a></h3>
318-
</div>
319-
320-
<footer class="power">
321-
<a href="https://v4.loopback.io" target="_blank">
322-
<img
323-
src="https://loopback.io/images/branding/powered-by-loopback/blue/powered-by-loopback-sm.png"
324-
alt="Powered by loopback"
325-
/>
326-
</a>
327-
</footer>
328-
</body>
329-
```
330-
331-
14. **Update home-page.controller.ts** - Update the home-page.controller.ts with base path related changes, only in facades.
332-
333-
```ts
334-
this.html = fs.readFileSync(
335-
path.join(__dirname, '../../public/index.html'),
336-
'utf-8',
337-
);
338-
// Replace base path placeholder from env
339-
this.html = this.html.replace(/\$\{basePath\}/g, process.env.BASE_PATH ?? '');
340-
```
183+
## How to upgrade to new LB4 dependencies
341184

342-
Create home-page.controller.ts if not already there.
185+
update the dependencies of a loopback project with following command.
343186

344-
## How to upgrade to new LB4 dependencies
187+
```sh
188+
USAGE
189+
$ sl update
345190

346-
1. Upgrade LB4 CLI version first. Use `npm i -g @loopback/cli@latest`.
347-
2. Run `npm i` at project root. This step is mandatory if node.js or npm version support is also needed to upgrade.
348-
3. Upgrade any deps, if needed, at project root. Verify it in the package.json at root. If not needed, skip this step.
349-
4. Navigate to core package. `cd packages/core`.
350-
5. Run `lb4 update`. It will prompt you to confirm the deps upgrade. Verify it carefully and confirm. Let it overwrite package.json.
351-
6. There may be some errors in previous step if there are any breaking changes coming in. If that's so, then, delete package-lock.json and run `npm i` again.
352-
7. Upgrade any other package related, like, loopback4 extensions - loopback4-authentication, etc. In order to ensure upgrade works, all the extensions should support the upgraded LB4 version. For example, `npm i loopback4-authentication@latest loopback4-authorization@latest loopback4-soft-delete@latest tslib@latest loopback-connector-postgresql@latest`.
353-
8. Run `npm audit fix`, if needed.
354-
9. Run `npm run test` to validate upgrade.
355-
10. Now, navigate to individual services. `cd ../../services/audit-service`.
356-
11. Re-execute steps 5-8 again.
357-
12. Before doing test, we need to update the `@sourceloop/core` with local symlinked package. Run `lerna bootstrap --force-local --scope=@sourceloop/audit-service`.
358-
13. Now run `npm run test` to validate upgrade.
359-
14. Repeat steps 10-13 for each service.
360-
361-
After all the steps above done for all services and core package, all your deps are upgraded and tested. You can commit and push them to be released. Make sure to mention any breaking changes if any of the deps upgrade had breaking change.
191+
OPTIONS
192+
--help show manual pages
193+
```
362194

363195
## Sonar Setup in VS Code
364196

0 commit comments

Comments
 (0)