From 613abbbef7def6739feb541fb7eaf40b63c2e350 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Burkard?= <22095555+JeromeBu@users.noreply.github.com> Date: Fri, 28 Feb 2025 16:52:01 +0100 Subject: [PATCH] remove unused scripts --- api/package.json | 2 - api/scripts/compile-data.ts | 21 -- api/scripts/link-in-app.ts | 151 -------------- api/scripts/migration/agent.ts | 70 ------- api/scripts/migration/instance.ts | 71 ------- api/scripts/migration/software.ts | 229 ---------------------- api/scripts/migration/softwareReferent.ts | 76 ------- api/scripts/reset-data-test.ts | 39 ---- api/scripts/tools/getProjectRoot.ts | 19 -- 9 files changed, 678 deletions(-) delete mode 100644 api/scripts/compile-data.ts delete mode 100644 api/scripts/link-in-app.ts delete mode 100644 api/scripts/migration/agent.ts delete mode 100644 api/scripts/migration/instance.ts delete mode 100644 api/scripts/migration/software.ts delete mode 100644 api/scripts/migration/softwareReferent.ts delete mode 100644 api/scripts/reset-data-test.ts delete mode 100644 api/scripts/tools/getProjectRoot.ts diff --git a/api/package.json b/api/package.json index 6bac2870..c89e1cac 100644 --- a/api/package.json +++ b/api/package.json @@ -24,8 +24,6 @@ "format": "yarn run _format --write", "format:check": "yarn run _format --list-different", "link-in-web": "ts-node --skipProject scripts/link-in-app.ts sill-web", - "reset-data-test": "ts-node --skipProject scripts/reset-data-test.ts", - "compile-data": "./.env.local.sh ts-node --skipProject scripts/compile-data.ts", "load-git-repo-in-pg": "dotenv -e ../.env -- node --loader ts-node/esm --experimental-specifier-resolution=node scripts/load-git-repo-in-pg.ts", "typecheck": "tsc --noEmit", "dev:db": "docker compose -f ../docker-compose.resources.yml up -d", diff --git a/api/scripts/compile-data.ts b/api/scripts/compile-data.ts deleted file mode 100644 index c2d06612..00000000 --- a/api/scripts/compile-data.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Kysely } from "kysely"; -import { bootstrapCore } from "../src/core"; -import type { Database } from "../src/core/adapters/dbApi/kysely/kysely.database"; -import { createPgDialect } from "../src/core/adapters/dbApi/kysely/kysely.dialect"; -import { env } from "../src/env"; - -(async () => { - const kyselyDb = new Kysely({ dialect: createPgDialect(env.databaseUrl) }); - const { useCases } = await bootstrapCore({ - "dbConfig": { - "dbKind": "kysely", - "kyselyDb": kyselyDb - }, - "githubPersonalAccessTokenForApiRateLimit": env.githubPersonalAccessTokenForApiRateLimit, - "externalSoftwareDataOrigin": env.externalSoftwareDataOrigin - }); - - await useCases.fetchAndSaveExternalDataForAllSoftwares(); - - process.exit(0); -})(); diff --git a/api/scripts/link-in-app.ts b/api/scripts/link-in-app.ts deleted file mode 100644 index a35a488e..00000000 --- a/api/scripts/link-in-app.ts +++ /dev/null @@ -1,151 +0,0 @@ -import { execSync } from "child_process"; -import { join as pathJoin, relative as pathRelative } from "path"; -import * as fs from "fs"; - -const singletonDependencies: string[] = [ - //"react", - //"@types/react" -]; - -const rootDirPath = pathJoin(__dirname, ".."); - -//NOTE: This is only required because of: https://github.com/garronej/ts-ci/blob/c0e207b9677523d4ec97fe672ddd72ccbb3c1cc4/README.md?plain=1#L54-L58 -fs.writeFileSync( - pathJoin(rootDirPath, "dist", "package.json"), - Buffer.from( - JSON.stringify( - (() => { - const packageJsonParsed = JSON.parse( - fs.readFileSync(pathJoin(rootDirPath, "package.json")).toString("utf8") - ); - - return { - ...packageJsonParsed, - "main": packageJsonParsed["main"]?.replace(/^dist\//, ""), - "types": packageJsonParsed["types"]?.replace(/^dist\//, ""), - "module": packageJsonParsed["module"]?.replace(/^dist\//, ""), - "exports": !("exports" in packageJsonParsed) - ? undefined - : Object.fromEntries( - Object.entries(packageJsonParsed["exports"]).map(([key, value]) => [ - key, - (value as string).replace(/^\.\/dist\//, "./") - ]) - ) - }; - })(), - null, - 2 - ), - "utf8" - ) -); - -const commonThirdPartyDeps = (() => { - // For example [ "@emotion" ] it's more convenient than - // having to list every sub emotion packages (@emotion/css @emotion/utils ...) - // in singletonDependencies - const namespaceSingletonDependencies: string[] = []; - - return [ - ...namespaceSingletonDependencies - .map(namespaceModuleName => - fs - .readdirSync(pathJoin(rootDirPath, "node_modules", namespaceModuleName)) - .map(submoduleName => `${namespaceModuleName}/${submoduleName}`) - ) - .reduce((prev, curr) => [...prev, ...curr], []), - ...singletonDependencies - ]; -})(); - -const yarnGlobalDirPath = pathJoin(rootDirPath, ".yarn_home"); - -fs.rmSync(yarnGlobalDirPath, { "recursive": true, "force": true }); -fs.mkdirSync(yarnGlobalDirPath); - -const execYarnLink = (params: { targetModuleName?: string; cwd: string }) => { - const { targetModuleName, cwd } = params; - - const cmd = ["yarn", "link", ...(targetModuleName !== undefined ? [targetModuleName] : ["--no-bin-links"])].join( - " " - ); - - console.log(`$ cd ${pathRelative(rootDirPath, cwd) || "."} && ${cmd}`); - - execSync(cmd, { - cwd, - "env": { - ...process.env, - "HOME": yarnGlobalDirPath - } - }); -}; - -const testAppPaths = (() => { - const [, , ...testAppNames] = process.argv; - - return testAppNames - .map(testAppName => { - const testAppPath = pathJoin(rootDirPath, "..", testAppName); - - if (fs.existsSync(testAppPath)) { - return testAppPath; - } - - console.warn(`Skipping ${testAppName} since it cant be found here: ${testAppPath}`); - - return undefined; - }) - .filter((path): path is string => path !== undefined); -})(); - -if (testAppPaths.length === 0) { - console.error("No test app to link into!"); - process.exit(-1); -} - -testAppPaths.forEach(testAppPath => execSync("yarn install", { "cwd": testAppPath })); - -console.log("=== Linking common dependencies ==="); - -const total = commonThirdPartyDeps.length; -let current = 0; - -commonThirdPartyDeps.forEach(commonThirdPartyDep => { - current++; - - console.log(`${current}/${total} ${commonThirdPartyDep}`); - - const localInstallPath = pathJoin( - ...[ - rootDirPath, - "node_modules", - ...(commonThirdPartyDep.startsWith("@") ? commonThirdPartyDep.split("/") : [commonThirdPartyDep]) - ] - ); - - execYarnLink({ "cwd": localInstallPath }); -}); - -commonThirdPartyDeps.forEach(commonThirdPartyDep => - testAppPaths.forEach(testAppPath => - execYarnLink({ - "cwd": testAppPath, - "targetModuleName": commonThirdPartyDep - }) - ) -); - -console.log("=== Linking in house dependencies ==="); - -execYarnLink({ "cwd": pathJoin(rootDirPath, "dist") }); - -testAppPaths.forEach(testAppPath => - execYarnLink({ - "cwd": testAppPath, - "targetModuleName": JSON.parse(fs.readFileSync(pathJoin(rootDirPath, "package.json")).toString("utf8"))["name"] - }) -); - -export {}; diff --git a/api/scripts/migration/agent.ts b/api/scripts/migration/agent.ts deleted file mode 100644 index 8801d6bd..00000000 --- a/api/scripts/migration/agent.ts +++ /dev/null @@ -1,70 +0,0 @@ -import type { Db } from "../../src/core/ports/DbApi"; -import * as fs from "fs"; -import { join as pathJoin } from "path"; -import { assert } from "tsafe/assert"; -import type { Equals } from "tsafe"; -import { z } from "zod"; -import { id as tsafeId } from "tsafe/id"; -import type { OptionalIfCanBeUndefined } from "../../src/tools/OptionalIfCanBeUndefined"; - -/* -npm -g install ts-node -cd ~/github/sill/sill-data -ts-node --skipProject ../sill-api/scripts/migration/agent.ts -*/ - -const zAgentRow = z.object({ - "email": z.string(), - "organization": z.string(), - "about": z.string().optional(), - "isPublic": z.boolean() -}); - -{ - type Got = ReturnType<(typeof zAgentRow)["parse"]>; - type Expected = OptionalIfCanBeUndefined; - - assert>(); -} - -const agentFilePath = pathJoin(process.cwd(), "agent.json"); - -fs.writeFileSync( - agentFilePath, - Buffer.from( - JSON.stringify( - JSON.parse(fs.readFileSync(agentFilePath).toString("utf8")).map((agentRow: Db.AgentRow) => { - try { - zAgentRow.parse(agentRow); - } catch (exception) { - console.log(agentRow); - - throw exception; - } - - const { email, organization, isPublic, about, ...rest } = agentRow; - - // eslint-disable-next-line @typescript-eslint/ban-types - assert>(); - - try { - assert(Object.keys(rest).length === 0); - } catch (error) { - console.log(rest); - - throw error; - } - - return tsafeId({ - email, - organization, - isPublic, - about - }); - }), - null, - 2 - ), - "utf8" - ) -); diff --git a/api/scripts/migration/instance.ts b/api/scripts/migration/instance.ts deleted file mode 100644 index 8cf861cf..00000000 --- a/api/scripts/migration/instance.ts +++ /dev/null @@ -1,71 +0,0 @@ -import type { Db } from "../../src/core/ports/DbApi"; -import { z } from "zod"; -import * as fs from "fs"; -import { join as pathJoin } from "path"; -import { assert } from "tsafe/assert"; -import type { Equals } from "tsafe"; -import { id as tsafeId } from "tsafe/id"; -import type { OptionalIfCanBeUndefined } from "../../src/tools/OptionalIfCanBeUndefined"; - -const instanceFilePath = pathJoin(process.cwd(), "instance.json"); - -const zInstanceRow = z.object({ - "id": z.number(), - "mainSoftwareSillId": z.number(), - "organization": z.string(), - "targetAudience": z.string(), - "publicUrl": z.string().optional(), - "addedByAgentEmail": z.string(), - "referencedSinceTime": z.number(), - "updateTime": z.number() -}); - -type Got = ReturnType<(typeof zInstanceRow)["parse"]>; -type Expected = OptionalIfCanBeUndefined; - -assert>(); - -fs.writeFileSync( - instanceFilePath, - Buffer.from( - JSON.stringify( - JSON.parse(fs.readFileSync(instanceFilePath).toString("utf8")).map((instanceRow: Db.InstanceRow) => { - try { - zInstanceRow.parse(instanceRow); - } catch (exception) { - console.log(instanceRow); - - throw exception; - } - - const { - id, - mainSoftwareSillId, - organization, - publicUrl, - targetAudience, - addedByAgentEmail, - referencedSinceTime, - updateTime, - ...rest - } = instanceRow; - - assert>(); - - return tsafeId({ - id, - mainSoftwareSillId, - organization, - publicUrl, - targetAudience, - addedByAgentEmail, - referencedSinceTime, - updateTime - }); - }), - null, - 2 - ), - "utf8" - ) -); diff --git a/api/scripts/migration/software.ts b/api/scripts/migration/software.ts deleted file mode 100644 index 2c1f8aae..00000000 --- a/api/scripts/migration/software.ts +++ /dev/null @@ -1,229 +0,0 @@ -import type { Db, Os, SoftwareType } from "../../src/core/ports/DbApi"; -import * as fs from "fs"; -import { join as pathJoin } from "path"; -import { assert } from "tsafe/assert"; -import type { Equals } from "tsafe"; -import { z } from "zod"; -import { id as tsafeId } from "tsafe/id"; -import type { OptionalIfCanBeUndefined } from "../../src/tools/OptionalIfCanBeUndefined"; - -/* -npm -g install ts-node -cd ~/github/sill/sill-data -ts-node --skipProject ../sill-api/src/scripts/migration/software.ts -*/ - -const zOs = z.enum(["windows", "linux", "mac", "android", "ios"]); - -{ - type Got = ReturnType<(typeof zOs)["parse"]>; - type Expected = Os; - - assert>(); -} - -const zSoftwareType = z.union([ - z.object({ - "type": z.literal("desktop/mobile"), - "os": z.object({ - "windows": z.boolean(), - "linux": z.boolean(), - "mac": z.boolean(), - "android": z.boolean(), - "ios": z.boolean() - }) - }), - z.object({ - "type": z.literal("cloud") - }), - z.object({ - "type": z.literal("stack") - }) -]); - -{ - type Got = ReturnType<(typeof zSoftwareType)["parse"]>; - type Expected = SoftwareType; - - assert>(); -} - -// Previous version, kept until the new one reach production : - -// const zSoftwareRow = z.object({ -// "id": z.number(), -// "name": z.string(), -// "description": z.string(), -// "referencedSinceTime": z.number(), -// "updateTime": z.number(), -// "dereferencing": z -// .object({ -// "reason": z.string().optional(), -// "time": z.number(), -// "lastRecommendedVersion": z.string().optional() -// }) -// .optional(), -// "isStillInObservation": z.boolean(), -// "parentSoftwareWikidataId": z.string().optional(), -// "doRespectRgaa": z.boolean().or(z.null()), -// "isFromFrenchPublicService": z.boolean(), -// "isPresentInSupportContract": z.boolean(), -// "similarSoftwareWikidataIds": z.array(z.string()), -// "wikidataId": z.string().optional(), -// "comptoirDuLibreId": z.number().optional(), -// "license": z.string(), -// "softwareType": zSoftwareType, -// "catalogNumeriqueGouvFrId": z.string().optional(), -// "versionMin": z.string(), -// "workshopUrls": z.array(z.string()), -// "testUrls": z.array( -// z.object({ -// "description": z.string(), -// "url": z.string() -// }) -// ), -// "categories": z.array(z.string()), -// "generalInfoMd": z.string().optional(), -// "addedByAgentEmail": z.string(), -// "logoUrl": z.string().optional(), -// "keywords": z.array(z.string()) -// }); - -const zSoftwareRow = z.object({ - "id": z.number(), - "name": z.string(), - "description": z.string(), - "referencedSinceTime": z.number(), - "updateTime": z.number(), - "dereferencing": z - .object({ - "reason": z.string().optional(), - "time": z.number(), - "lastRecommendedVersion": z.string().optional() - }) - .optional(), - "isStillInObservation": z.boolean(), - "parentSoftwareWikidataId": z.string().optional(), - "doRespectRgaa": z.boolean().or(z.null()), - "isFromFrenchPublicService": z.boolean(), - "isPresentInSupportContract": z.boolean(), - "similarSoftwareExternalDataIds": z.array(z.string()), - "externalId": z.string().optional(), - "externalDataOrigin": z.enum(["wikidata", "HAL"]).optional(), - "comptoirDuLibreId": z.number().optional(), - "license": z.string(), - "softwareType": zSoftwareType, - "catalogNumeriqueGouvFrId": z.string().optional(), - "versionMin": z.string().optional(), - "workshopUrls": z.array(z.string()), - "testUrls": z.array( - z.object({ - "description": z.string(), - "url": z.string() - }) - ), - "categories": z.array(z.string()), - "generalInfoMd": z.string().optional(), - "addedByAgentEmail": z.string(), - "logoUrl": z.string().optional(), - "keywords": z.array(z.string()) -}); - -{ - type Got = ReturnType<(typeof zSoftwareRow)["parse"]>; - type Expected = OptionalIfCanBeUndefined; - - assert>(); -} - -const softwareFilePath = pathJoin(process.cwd(), "software.json"); - -fs.writeFileSync( - softwareFilePath, - Buffer.from( - JSON.stringify( - JSON.parse(fs.readFileSync(softwareFilePath).toString("utf8")).map((softwareRow: Db.SoftwareRow) => { - try { - zSoftwareRow.parse(softwareRow); - } catch (exception) { - console.log(softwareRow); - - throw exception; - } - - const { - id, - name, - description, - referencedSinceTime, - dereferencing, - isStillInObservation, - parentSoftwareWikidataId, - isFromFrenchPublicService, - isPresentInSupportContract, - externalId, - externalDataOrigin, - comptoirDuLibreId, - license, - catalogNumeriqueGouvFrId, - versionMin, - workshopUrls, - testUrls, - generalInfoMd, - updateTime, - doRespectRgaa, - similarSoftwareExternalDataIds, - softwareType, - categories, - addedByAgentEmail, - logoUrl, - keywords, - ...rest - } = softwareRow; - - // eslint-disable-next-line @typescript-eslint/ban-types - assert>(); - - try { - assert(Object.keys(rest).length === 0); - } catch (error) { - console.log(rest); - - throw error; - } - - return tsafeId({ - id, - name, - description, - referencedSinceTime, - dereferencing, - isStillInObservation, - parentSoftwareWikidataId, - isFromFrenchPublicService, - isPresentInSupportContract, - externalId, - externalDataOrigin, - comptoirDuLibreId, - license, - catalogNumeriqueGouvFrId, - versionMin, - workshopUrls, - testUrls, - generalInfoMd, - updateTime, - doRespectRgaa, - similarSoftwareExternalDataIds, - softwareType, - categories, - addedByAgentEmail, - logoUrl, - keywords - }); - }), - null, - 2 - ), - "utf8" - ) -); diff --git a/api/scripts/migration/softwareReferent.ts b/api/scripts/migration/softwareReferent.ts deleted file mode 100644 index 4e9e9789..00000000 --- a/api/scripts/migration/softwareReferent.ts +++ /dev/null @@ -1,76 +0,0 @@ -import type { Db } from "../../src/core/ports/DbApi"; -import { z } from "zod"; -import * as fs from "fs"; -import { join as pathJoin } from "path"; -import { assert } from "tsafe/assert"; -import type { Equals } from "tsafe"; -import { id } from "tsafe/id"; -import { OptionalIfCanBeUndefined } from "../../src/tools/OptionalIfCanBeUndefined"; - -/* - -This script is meant to help edit and make sure it is well formatted sill-data/software.json - -cd ~/github/sill-api && npx tsc -w -cd ~/github/sill-data -node ../sill-api/dist/bin/editSoftwareReferent.js - -*/ - -const softwareReferentFilePath = pathJoin(process.cwd(), "softwareReferent.json"); - -const zSoftwareReferentRow = z.object({ - "softwareId": z.number(), - "agentEmail": z.string(), - "isExpert": z.boolean(), - "useCaseDescription": z.string(), - "serviceUrl": z.string().optional() -}); - -{ - type Got = ReturnType<(typeof zSoftwareReferentRow)["parse"]>; - type Expected = OptionalIfCanBeUndefined; - - assert>(); -} - -fs.writeFileSync( - softwareReferentFilePath, - Buffer.from( - JSON.stringify( - JSON.parse(fs.readFileSync(softwareReferentFilePath).toString("utf8")).map( - (softwareReferentRow: Db.SoftwareReferentRow) => { - try { - zSoftwareReferentRow.parse(softwareReferentRow); - } catch (exception) { - console.log(softwareReferentRow); - - throw exception; - } - - const { softwareId, agentEmail, isExpert, useCaseDescription, serviceUrl, ...rest } = - softwareReferentRow; - - try { - assert(Object.keys(rest).length === 0); - } catch (error) { - console.log(rest); - - throw error; - } - - return id({ - softwareId, - agentEmail, - isExpert, - useCaseDescription, - serviceUrl - }); - } - ), - null, - 2 - ), - "utf8" - ) -); diff --git a/api/scripts/reset-data-test.ts b/api/scripts/reset-data-test.ts deleted file mode 100644 index f1855f52..00000000 --- a/api/scripts/reset-data-test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { execSync } from "child_process"; - -const tmpDirBasename = "tmp_x3dL4bZdj4dbq2Td"; -const repoUrl = "git@github.com:codegouvfr/sill-data.git"; - -function executeCommand(command: string) { - console.log(`Executing: ${command}`); - execSync(command, { stdio: "inherit" }); -} - -try { - // Remove the temporary directory if it exists - executeCommand(`rm -rf ${tmpDirBasename}`); - - // Clone the entire repo (including all branches and commit history) - executeCommand(`git clone ${repoUrl} ${tmpDirBasename}`); - - // Change directory - process.chdir(tmpDirBasename); - - // Fetch all branches from origin - executeCommand(`git fetch origin`); - - // Change remote URL - executeCommand(`git remote set-url origin ${repoUrl.replace(".git", "-test.git")}`); - - // Push all branches to the new origin - executeCommand(`git push -f --all`); - - // Change directory back - process.chdir(".."); - - // Remove the temporary directory - executeCommand(`rm -rf ${tmpDirBasename}`); - - executeCommand("sleep 30"); -} catch (error) { - console.error("An error occurred:", String(error)); -} diff --git a/api/scripts/tools/getProjectRoot.ts b/api/scripts/tools/getProjectRoot.ts deleted file mode 100644 index ea458855..00000000 --- a/api/scripts/tools/getProjectRoot.ts +++ /dev/null @@ -1,19 +0,0 @@ -import * as fs from "fs"; -import * as path from "path"; - -function getProjectRootRec(dirPath: string): string { - if (fs.existsSync(path.join(dirPath, "tsconfig.json"))) { - return dirPath; - } - return getProjectRootRec(path.join(dirPath, "..")); -} - -let result: string | undefined = undefined; - -export function getProjectRoot(): string { - if (result !== undefined) { - return result; - } - - return (result = getProjectRootRec(__dirname)); -}