Skip to content

Commit 512aedf

Browse files
committed
ci(nestjs-json-rpc-sdk): Prepare task for publish npm
1 parent 26d3365 commit 512aedf

File tree

11 files changed

+185
-22
lines changed

11 files changed

+185
-22
lines changed

libs/json-api/json-api-nestjs-sdk/project.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"commands": [
3131
"node tools/scripts/preparation-hybrid-npm-package.mjs json-api-nestjs-sdk",
3232
"node tools/scripts/preparation-npm-package.mjs json-api-nestjs-sdk",
33-
"node tools/scripts/prepare-for-angular.mjs"
33+
"node tools/scripts/prepare-for-angular.mjs json-api-nestjs-sdk json-api-angular"
3434
],
3535
"cwd": "./",
3636
"parallel": false

libs/json-rpc/nestjs-json-rpc-sdk/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ const { rpc, rpcBatch } = RpcFactory<MapperRpc>(
8787
false
8888
);
8989
//TS2345: Argument of type string is not assignable to parameter of type number
90-
const call = rpcForBatch.RpcService.someMethod('inccorectParam');
90+
const call = rpc.RpcService.someMethod('inccorectParam');
9191
//TS2339: Property IncorrectService does not exist on type MapperRpc
92-
const call2 = rpcForBatch.IncorrectService.someMethod(1);
92+
const call2 = rpc.IncorrectService.someMethod(1);
9393
//TS2339: Property incorrectMethod does not exist on type RpcService
94-
const call3 = rpcForBatch.RpcService.incorrectMethod(1);
94+
const call3 = rpc.RpcService.incorrectMethod(1);
9595

9696
```
9797

@@ -151,7 +151,7 @@ const { rpc, rpcBatch, rpcForBatch } = RpcFactory<MapperRpc>(
151151
},
152152
true // need true for use promise as result
153153
);
154-
const result = await rpcForBatch.RpcService.someMethod(1)
154+
const result = await rpc.RpcService.someMethod(1)
155155

156156
const call1 = rpcForBatch.RpcService.someMethod(1);
157157
const call2 = rpcForBatch.RpcService.methodWithObjectParams({
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../../tmp/angular-lib/nestjs-json-rpc-sdk",
4+
"lib": {
5+
"entryFile": "../../index.ts"
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
11
{
22
"name": "@klerick/nestjs-json-rpc-sdk",
3-
"version": "0.0.1",
4-
"dependencies": {
5-
"tslib": "^2.3.0"
6-
}
3+
"version": "1.0.0",
4+
"engines": {
5+
"node": ">= 16.0.0"
6+
},
7+
"description": "Client for RPS server, which use @klerick/nestjs-json-rpc",
8+
"contributors": [
9+
{
10+
"email": "[email protected]",
11+
"name": "Aleksandr Kharkovey"
12+
}
13+
],
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/klerick/nestjs-json-api.git"
17+
},
18+
"private": false,
19+
"license": "MIT",
20+
"main": "./src/index.js",
21+
"files": [
22+
"**/*"
23+
],
24+
"keywords": [
25+
"nestjs",
26+
"nest",
27+
"RPC",
28+
"JSON-RPC"
29+
]
730
}

libs/json-rpc/nestjs-json-rpc-sdk/project.json

+81-2
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,98 @@
44
"sourceRoot": "libs/json-rpc/nestjs-json-rpc-sdk/src",
55
"projectType": "library",
66
"targets": {
7+
"compile-for-angular": {
8+
"executor": "@nx/angular:package",
9+
"outputs": ["{workspaceRoot}/dist/{projectRoot}"],
10+
"options": {
11+
"project": "libs/json-rpc/nestjs-json-rpc-sdk/ng-package.json"
12+
},
13+
"configurations": {
14+
"production": {
15+
"tsConfig": "libs/json-rpc/nestjs-json-rpc-sdk/tsconfig-mjs.lib.json"
16+
},
17+
"development": {
18+
"tsConfig": "libs/json-rpc/nestjs-json-rpc-sdk/tsconfig-mjs.lib.json"
19+
}
20+
},
21+
"defaultConfiguration": "production"
22+
},
723
"build": {
24+
"executor": "nx:run-commands",
25+
"dependsOn": [
26+
"build-cjs"
27+
],
28+
"options": {
29+
"outputPath": "dist/libs/json-rpc/nestjs-json-rpc-sdk",
30+
"commands": [
31+
"node tools/scripts/preparation-hybrid-npm-package.mjs nestjs-json-rpc-sdk",
32+
"node tools/scripts/preparation-npm-package.mjs nestjs-json-rpc-sdk",
33+
"node tools/scripts/prepare-for-angular.mjs nestjs-json-rpc-sdk json-rpc-angular",
34+
"cp tmp/angular-lib/nestjs-json-rpc-sdk/esm2022/json-rpc/nestjs-json-rpc-sdk/src/lib/angular/json-rpc-angular.module.mjs dist/libs/json-rpc/nestjs-json-rpc-sdk/mjs/src/lib/angular/json-rpc-angular.module.js"
35+
],
36+
"cwd": "./",
37+
"parallel": false
38+
}
39+
},
40+
"build-cjs": {
841
"executor": "@nx/js:tsc",
942
"outputs": ["{options.outputPath}"],
43+
"dependsOn": [
44+
"build-mjs"
45+
],
1046
"options": {
11-
"outputPath": "dist/libs/json-rpc/nestjs-json-rpc-sdk",
47+
"outputPath": "dist/libs/json-rpc/nestjs-json-rpc-sdk/cjs",
1248
"main": "libs/json-rpc/nestjs-json-rpc-sdk/src/index.ts",
1349
"tsConfig": "libs/json-rpc/nestjs-json-rpc-sdk/tsconfig.lib.json",
14-
"assets": ["libs/json-rpc/nestjs-json-rpc-sdk/*.md"]
50+
"assets": ["libs/json-rpc/nestjs-json-rpc-sdk/*.md"],
51+
"external": "none",
52+
"updateBuildableProjectDepsInPackageJson": true,
53+
"buildableProjectDepsInPackageJsonType": "peerDependencies",
54+
"additionalEntryPoints": [
55+
"libs/json-rpc/nestjs-json-rpc-sdk/src/json-rpc-sdk.module.ts"
56+
],
57+
"generateExportsField": true
58+
}
59+
},
60+
"build-mjs": {
61+
"executor": "@nx/js:tsc",
62+
"outputs": ["{options.outputPath}"],
63+
"options": {
64+
"outputPath": "dist/libs/json-rpc/nestjs-json-rpc-sdk/mjs",
65+
"main": "libs/json-rpc/nestjs-json-rpc-sdk/src/index.ts",
66+
"tsConfig": "libs/json-rpc/nestjs-json-rpc-sdk/tsconfig-mjs.lib.json",
67+
"assets": ["libs/json-rpc/nestjs-json-rpc-sdk/*.md"],
68+
"external": "none",
69+
"updateBuildableProjectDepsInPackageJson": true,
70+
"buildableProjectDepsInPackageJsonType": "peerDependencies",
71+
"additionalEntryPoints": [
72+
"libs/json-rpc/nestjs-json-rpc-sdk/src/json-rpc-sdk.module.ts"
73+
],
74+
"generateExportsField": true
1575
}
1676
},
1777
"publish": {
1878
"command": "node tools/scripts/publish.mjs nestjs-json-rpc-sdk {args.ver} {args.tag}",
1979
"dependsOn": ["build"]
80+
},
81+
"upload-badge": {
82+
"executor": "nx:run-commands",
83+
"dependsOn": [
84+
{
85+
"target": "test"
86+
}
87+
],
88+
"options": {
89+
"outputPath": "{workspaceRoot}/libs/json-rpc/nestjs-json-rpc-sdk",
90+
"commands": ["node tools/scripts/upload-badge.mjs nestjs-json-rpc-sdk"],
91+
"cwd": "./",
92+
"parallel": false
93+
}
94+
},
95+
"nx-release-publish": {
96+
"options": {
97+
"packageRoot": "dist/libs/json-rpc/nestjs-json-rpc-sdk"
98+
}
2099
}
21100
},
22101
"tags": []

libs/json-rpc/nestjs-json-rpc-sdk/src/lib/angular/tokens.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { InjectionToken } from '@angular/core';
2-
import { LoopFunc, RpcBatch, RpcReturnList, Transport } from '../types';
2+
import {
3+
LoopFunc,
4+
RpcBatch,
5+
RpcReturnList,
6+
Transport,
7+
JsonRpcAngularConfig,
8+
} from '../types';
39

4-
import { JsonRpcAngularConfig } from '@klerick/nestjs-json-rpc-sdk/json-rpc-sdk.module';
510
import {
611
angularTransportFactory,
712
rpcBatchFactory,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"types": ["node"],
5+
"module": "es2015",
6+
"target": "ES2022",
7+
"removeComments": false,
8+
"declaration": true,
9+
},
10+
"include": ["src/**/*.ts"],
11+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
12+
"angularCompilerOptions": {
13+
"compilationMode": "partial",
14+
"enableI18nLegacyMessageIdFormat": false,
15+
"strictInjectionParameters": true,
16+
"strictInputAccessModifiers": true,
17+
"strictTemplates": true
18+
}
19+
}

libs/json-rpc/nestjs-json-rpc-sdk/tsconfig.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
{
22
"extends": "../../../tsconfig.base.json",
33
"compilerOptions": {
4-
"module": "commonjs",
4+
"outDir": "../../../dist/out-tsc",
55
"forceConsistentCasingInFileNames": true,
66
"strict": true,
77
"noImplicitOverride": true,
88
"noPropertyAccessFromIndexSignature": true,
99
"noImplicitReturns": true,
10-
"noFallthroughCasesInSwitch": true
10+
"noFallthroughCasesInSwitch": true,
11+
"inlineSources": true,
12+
"inlineSourceMap": true,
13+
"sourceMap": false
1114
},
1215
"files": [],
1316
"include": [],
1417
"references": [
1518
{
1619
"path": "./tsconfig.lib.json"
1720
},
21+
{
22+
"path": "./tsconfig-mjs.lib.json"
23+
},
1824
{
1925
"path": "./tsconfig.spec.json"
2026
}

libs/json-rpc/nestjs-json-rpc-sdk/tsconfig.lib.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"extends": "./tsconfig.json",
33
"compilerOptions": {
4-
"outDir": "../../../dist/out-tsc",
5-
"declaration": true,
4+
"module": "commonjs",
5+
"declaration": false,
66
"types": ["node"]
77
},
88
"include": ["src/**/*.ts"],

tools/scripts/preparation-hybrid-npm-package.mjs

+7-1
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ invariant(
4545
);
4646
process.chdir(outputPath);
4747

48+
const angularModuleMap = {
49+
'nestjs-json-rpc-sdk': 'json-rpc-sdk.module',
50+
'json-api-nestjs-sdk': 'json-api-nestjs-sdk.module'
51+
}
52+
4853
const mjsJson = readJson();
49-
const angularModule = 'json-api-nestjs-sdk.module';
54+
const angularModule = angularModuleMap[name];
5055
const angularModulePath = `./${angularModule}`;
56+
5157
const angularPath = mjsJson.exports[angularModulePath]
5258

5359
mjsJson.module = addTypeToPath(mjsJson.main)

tools/scripts/prepare-for-angular.mjs

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1+
import devkit from '@nx/devkit';
12
import { readFileSync, writeFileSync, unlinkSync } from 'fs';
23
import { exec } from 'child_process';
34
import { promisify } from 'util';
45

6+
const { readCachedProjectGraph } = devkit;
7+
8+
const [, , name, angularName] = process.argv;
9+
10+
const graph = readCachedProjectGraph();
11+
const project = graph.nodes[name];
12+
13+
const outputPath = project.data?.targets?.build?.options?.outputPath;
14+
const sourceRoot = project.data?.sourceRoot
15+
16+
const packageJson = JSON.parse(readFileSync(`${outputPath}/package.json`).toString());
17+
const angularFile = Object.keys(packageJson.exports).filter(i => !['./package.json', '.'].includes(i)).pop().replace('./', '')
18+
const [_, ...pathToModule] = sourceRoot.split('/')
19+
20+
const [nameSpace] = pathToModule
521

622
const TEMP_FILE_PATH = 'libs/index.ts'
7-
const ANGULAR_MODULE_PATH = 'tmp/angular-lib/json-api-nestjs-sdk/esm2022/json-api/json-api-nestjs-sdk/src/lib/json-api-angular.mjs'
8-
const LIB_ANGULAR_MODULE_PATH = 'dist/libs/json-api/json-api-nestjs-sdk/mjs/src/lib/json-api-angular.js'
23+
const ANGULAR_MODULE_PATH = `tmp/angular-lib/${name}/esm2022/${nameSpace}/${name}/src/lib/${angularName}.mjs`
24+
const LIB_ANGULAR_MODULE_PATH = `${outputPath}/mjs/src/lib/${angularName}.js`
25+
26+
927
writeFileSync(
1028
TEMP_FILE_PATH,
11-
'export * from \'./json-api/json-api-nestjs-sdk/src/json-api-nestjs-sdk.module\';'
29+
`export * from './${pathToModule.join('/')}/${angularFile}';`
1230
);
1331

1432
promisify(exec)(
15-
`nx run json-api-nestjs-sdk:compile-for-angular`
33+
`nx run ${name}:compile-for-angular`
1634
).then(r => {
1735
writeFileSync(LIB_ANGULAR_MODULE_PATH, readFileSync(ANGULAR_MODULE_PATH))
1836
}).finally(() => {

0 commit comments

Comments
 (0)