diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml index bd08a7a..719bfed 100644 --- a/.github/workflows/node.js.yml +++ b/.github/workflows/node.js.yml @@ -8,6 +8,7 @@ on: branches: - demo env: + CRAWL_API_URL: ${{ vars.CRAWL_API_URL }} AUTH_TOKEN: ${{ vars.AUTH_TOKEN }} jobs: @@ -49,7 +50,7 @@ jobs: output: ${{needs.handle-commit.outputs.output}} run: | echo $output - echo "$output" + echo "${{ env.CRAWL_API_URL }}$output" curl --request GET \ - --url "$output" \ - --header "Authorization: Bearer $AUTH_TOKEN" + --url "${{ env.CRAWL_API_URL }}$output" \ + --header "Authorization: Bearer ${{ env.AUTH_TOKEN }}" diff --git a/apps/server/package.json b/apps/server/package.json index 4ca20ca..2b002a7 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -10,6 +10,8 @@ "start": "node -r ./tsconfig-paths.js dist/index.js", "format": "prettier --write \"**/*.{ts,tsx,md}\"", "crawl": "ts-node -r tsconfig-paths/register src/crawl.ts", + "seed": "ts-node -r tsconfig-paths/register src/seed.ts", + "seed:prod": "node -r ./tsconfig-paths.js dist/seed.js", "test": "ts-node -r tsconfig-paths/register src/test.ts" }, "keywords": [], diff --git a/apps/server/src/controllers/base.controller.ts b/apps/server/src/controllers/base.controller.ts deleted file mode 100644 index 6e02cc2..0000000 --- a/apps/server/src/controllers/base.controller.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Request, Response } from 'express' -import 'dotenv/config' -import { creatorParentCategory } from '@/creator/creatorParentCategory' -import { fsWrapper } from '@/utils/fs/fsWrapper' -import { creatorSocial } from '@/creator/creatorSocial' - -function createCategory(parentFolders) { - parentFolders.map((folder) => { - const path = `/projects/${folder}` - creatorParentCategory(path) - }) -} - -export class BaseController { - public buildBaseDatabase = async (req: Request, res: Response) => { - await creatorSocial() - const rootHierachy = await fsWrapper.readdir(`/projects`) - const parentFolders = rootHierachy.filter( - (value) => value !== 'projects.json' && value !== 'socials.json', - ) - - createCategory(parentFolders) - - res.send('successful') - } - - public test = async (req, res) => { - console.log('come here') - - res.send('successful') - } -} diff --git a/apps/server/src/crawl.ts b/apps/server/src/crawl.ts index 2fd7085..fecaaf3 100644 --- a/apps/server/src/crawl.ts +++ b/apps/server/src/crawl.ts @@ -15,11 +15,6 @@ export function fromFileChangesToQuery(fileChanges: Array): string { return dataReturn } -export function getURL(data: string) { - const server = 'https://44d7-42-119-180-122.ngrok-free.app' - - return `${server}/api/v1/crawl${data}` -} async function main() { // get list file change @@ -27,7 +22,7 @@ async function main() { const query: string = fromFileChangesToQuery(fileChanges) - console.log(`${getURL(query)}`) + console.log(`${query}`) } main() diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index bdfee5b..ac6c8bd 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -4,14 +4,12 @@ import App from './App' import CategoriesRoute from './routes/categories.route' import ProjectsRoute from './routes/projects.route' import TagsRoute from './routes/tags.route' -import { BaseRoute } from './routes/base.route' import { CrawlRoute } from './routes/crawl.route' const app = new App([ new CategoriesRoute(), new ProjectsRoute(), new TagsRoute(), - new BaseRoute(), new CrawlRoute(), ]) diff --git a/apps/server/src/routes/base.route.ts b/apps/server/src/routes/base.route.ts deleted file mode 100644 index dc9a99a..0000000 --- a/apps/server/src/routes/base.route.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { BaseController } from '@/controllers/base.controller' -import { Routes } from '@/decorator/routes' -import { Router } from 'express' - -export class BaseRoute implements Routes { - public path: string = '/api/v1/base' - public router = Router() - private baseController = new BaseController() - - constructor() { - this.initializeRoutes() - } - - private initializeRoutes() { - this.router.get('/', this.baseController.buildBaseDatabase) - this.router.get('/test', this.baseController.test) - } -} diff --git a/apps/server/src/seed.ts b/apps/server/src/seed.ts new file mode 100644 index 0000000..7e85216 --- /dev/null +++ b/apps/server/src/seed.ts @@ -0,0 +1,35 @@ +import { creatorParentCategory } from '@/creator/creatorParentCategory' +import { creatorSocial } from '@/creator/creatorSocial' +import { fsWrapper } from '@/utils/fs/fsWrapper' +import 'dotenv/config' +import { logger } from './utils/logger' +import { connection } from './databases/connection' + +function createCategory(parentFolders) { + parentFolders.map((folder) => { + const path = `/projects/${folder}` + creatorParentCategory(path) + }) +} + +const main = async () => { + try { + connection.initialize() + await creatorSocial() + const rootHierachy = await fsWrapper.readdir(`/projects`) + const parentFolders = rootHierachy.filter( + (value) => value !== 'projects.json' && value !== 'socials.json', + ) + + createCategory(parentFolders) + console.log('\x1b[32m databases build successfully \x1b[0m') + logger.verbose('databases build successfully') + process.exit() + } catch (error) { + console.error(error) + logger.error(error) + process.exit(1) + } +} + +main()