@ask-ell/back-end 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/jest.config.ts +1 -1
- package/package.json +1 -1
- package/src/add-ons/implementations/sentry/sentry.add-on.ts +1 -1
- package/src/add-ons/implementations/swagger/swagger.add-on.ts +1 -1
- package/src/scripts/index.ts +1 -0
- package/src/scripts/move-keyv-data.script.ts +3 -3
- package/src/scripts/update-dependencies-versions.script.ts +167 -0
package/jest.config.ts
CHANGED
package/package.json
CHANGED
package/src/scripts/index.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { PercentageIncrementor } from '@ask-ell/core';
|
|
2
|
-
import { Client, QueryResult } from 'pg';
|
|
3
2
|
import { Script, ExecuteOptions } from '@ask-ell/node';
|
|
4
3
|
import { NestLogger } from '@ask-ell/nest';
|
|
4
|
+
import { Client, QueryResult } from 'pg';
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
type KeyvRowData = {
|
|
7
|
+
type KeyvRowData<Value = unknown> = {
|
|
8
8
|
key: string;
|
|
9
|
-
value:
|
|
9
|
+
value: Value;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export class MoveKeyvDataScript extends Script {
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { MaybeUndefined, StringDictionnary, UnknownEnvironmentVariableError } from "@ask-ell/core";
|
|
2
|
+
import { NestLogger } from "@ask-ell/nest";
|
|
3
|
+
import { ExecuteOptions, Script } from "@ask-ell/node";
|
|
4
|
+
import { spawnSync } from 'node:child_process';
|
|
5
|
+
import { writeFileSync } from "node:fs";
|
|
6
|
+
import { mkdir } from 'node:fs/promises';
|
|
7
|
+
import { join } from 'node:path';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const PROJECT_ROOT_PATH: MaybeUndefined<string> = process.env['PWD'];
|
|
11
|
+
|
|
12
|
+
function makeSureThatProjectRootPathIsDefined(projectRootPath: MaybeUndefined<string>): asserts projectRootPath is string {
|
|
13
|
+
if (!projectRootPath) {
|
|
14
|
+
throw new UnknownEnvironmentVariableError('PWD');
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
makeSureThatProjectRootPathIsDefined(PROJECT_ROOT_PATH);
|
|
19
|
+
|
|
20
|
+
const NX_GRAPH_FILE_PATH: string = join(PROJECT_ROOT_PATH, 'tmp/graph.json');
|
|
21
|
+
|
|
22
|
+
type PackageContent = {
|
|
23
|
+
version: string;
|
|
24
|
+
dependencies: StringDictionnary;
|
|
25
|
+
devDependencies: StringDictionnary;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ROOT_PACKAGE_FILE_PATH: string = join(PROJECT_ROOT_PATH, `package.json`);
|
|
29
|
+
const ROOT_PACKAGE_CONTENT: PackageContent = require(ROOT_PACKAGE_FILE_PATH);
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
function getOrganisationPackageFile(packageId: string): PackageContent {
|
|
33
|
+
makeSureThatProjectRootPathIsDefined(PROJECT_ROOT_PATH);
|
|
34
|
+
const packageFilePath = join(PROJECT_ROOT_PATH, `packages/${packageId}/package.json`);
|
|
35
|
+
return require(packageFilePath);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type UpdateDependenciesVersionsScriptParams = {
|
|
39
|
+
organisationPackagePrefix: string;
|
|
40
|
+
blackListedPackages: string[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
type WorkspaceDependenciesMapElement = { id: string; dependencies: string[]; source: PackageContent };
|
|
44
|
+
|
|
45
|
+
type WorkspaceDependenciesMap = {
|
|
46
|
+
[id: string]: WorkspaceDependenciesMapElement;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export class UpdateDependenciesVersionsScript extends Script {
|
|
50
|
+
private organisationPackagePrefix: string;
|
|
51
|
+
private blackListedPackages: string[];
|
|
52
|
+
private workspaceDependenciesMap: WorkspaceDependenciesMap = this.getWorkspaceDependenciesMap();
|
|
53
|
+
|
|
54
|
+
constructor({
|
|
55
|
+
organisationPackagePrefix,
|
|
56
|
+
blackListedPackages
|
|
57
|
+
}: UpdateDependenciesVersionsScriptParams) {
|
|
58
|
+
super({
|
|
59
|
+
logger: NestLogger.fromClass(UpdateDependenciesVersionsScript),
|
|
60
|
+
arguments: [
|
|
61
|
+
{
|
|
62
|
+
name: 'targetedPackage',
|
|
63
|
+
description: "Target package"
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
});
|
|
67
|
+
this.organisationPackagePrefix = organisationPackagePrefix;
|
|
68
|
+
this.blackListedPackages = blackListedPackages;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async execute({
|
|
72
|
+
logger,
|
|
73
|
+
arguments: {
|
|
74
|
+
targetedPackage
|
|
75
|
+
}
|
|
76
|
+
}: ExecuteOptions): Promise<void> {
|
|
77
|
+
const workspaceDependenciesMapElements: WorkspaceDependenciesMapElement[] = Object
|
|
78
|
+
.values(this.workspaceDependenciesMap)
|
|
79
|
+
.filter(({ id }: WorkspaceDependenciesMapElement): boolean => this.isTargetedPackage(targetedPackage)(id));
|
|
80
|
+
|
|
81
|
+
for (const { id, dependencies, source } of workspaceDependenciesMapElements) {
|
|
82
|
+
logger.log(`package.json file updating for project "${id}"...`);
|
|
83
|
+
|
|
84
|
+
if (!PROJECT_ROOT_PATH) {
|
|
85
|
+
throw new UnknownEnvironmentVariableError('PWD');
|
|
86
|
+
}
|
|
87
|
+
const packagePath: string = join(PROJECT_ROOT_PATH, `dist/packages/${id}`);
|
|
88
|
+
|
|
89
|
+
await mkdir(packagePath, { recursive: true });
|
|
90
|
+
const packageFilePath: string = join(PROJECT_ROOT_PATH, 'package.json');
|
|
91
|
+
|
|
92
|
+
const packageFileContent: PackageContent = { ...source };
|
|
93
|
+
|
|
94
|
+
if (dependencies.length && !packageFileContent.dependencies) {
|
|
95
|
+
packageFileContent.dependencies = {};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
dependencies.forEach((dependency: string): void => {
|
|
99
|
+
const versionTag = this.isAOrganisationPackage(dependency)
|
|
100
|
+
? `^${this.workspaceDependenciesMap[dependency.replace(this.organisationPackagePrefix, '')].source.version}`
|
|
101
|
+
: ROOT_PACKAGE_CONTENT.devDependencies[dependency];
|
|
102
|
+
packageFileContent.dependencies[dependency] = versionTag;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
writeFileSync(
|
|
106
|
+
packageFilePath,
|
|
107
|
+
JSON.stringify(packageFileContent, null, 2) + '\n'
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
console.log(`package.json file updated for project "${id}"`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.log('Package files updated.')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
getWorkspaceDependenciesMap(): WorkspaceDependenciesMap {
|
|
117
|
+
const workspaceDependenciesMap: WorkspaceDependenciesMap = {};
|
|
118
|
+
|
|
119
|
+
const nxGraphResult = spawnSync('npx', ['nx', 'graph', '--file', NX_GRAPH_FILE_PATH], { stdio: 'inherit' });
|
|
120
|
+
if (nxGraphResult.status !== 0) {
|
|
121
|
+
throw new Error(`"nx graph" failed with status ${nxGraphResult.status}`);
|
|
122
|
+
}
|
|
123
|
+
const nxGraph = require(NX_GRAPH_FILE_PATH);
|
|
124
|
+
|
|
125
|
+
const packageIds = Object.entries(nxGraph.graph.dependencies).map(([packageId]) => packageId);
|
|
126
|
+
|
|
127
|
+
for (const packageId of packageIds.filter(this.isNotBlackListed)) {
|
|
128
|
+
console.log(`Scanning dependencies for package ${packageId}...`)
|
|
129
|
+
const packageFileContent = getOrganisationPackageFile(packageId);
|
|
130
|
+
const dependencies = packageFileContent.dependencies ? Object.entries(packageFileContent.dependencies).map(([dependency]) => dependency) : [];
|
|
131
|
+
|
|
132
|
+
workspaceDependenciesMap[packageId] = {
|
|
133
|
+
id: packageId,
|
|
134
|
+
dependencies: [],
|
|
135
|
+
source: packageFileContent
|
|
136
|
+
}
|
|
137
|
+
if (packageFileContent.dependencies) {
|
|
138
|
+
for (const dependency of dependencies) {
|
|
139
|
+
workspaceDependenciesMap[packageId].dependencies.push(dependency);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
console.log('Dependencies scan done.');
|
|
145
|
+
|
|
146
|
+
return workspaceDependenciesMap;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private isTargetedPackage = (targetPackageId: MaybeUndefined<string>) => (packageId: string) => {
|
|
150
|
+
if (targetPackageId) {
|
|
151
|
+
return packageId === targetPackageId;
|
|
152
|
+
}
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private isAOrganisationPackage(packageName: string): boolean {
|
|
157
|
+
return packageName.includes(this.organisationPackagePrefix);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private isBlackListed(packageId: string): boolean {
|
|
161
|
+
return this.blackListedPackages.includes(packageId);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private isNotBlackListed(packageId: string): boolean {
|
|
165
|
+
return !this.isBlackListed(packageId);
|
|
166
|
+
}
|
|
167
|
+
}
|