Skip to content

Commit

Permalink
Use Logger in build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch committed Dec 9, 2024
1 parent 0c20475 commit a92226a
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import StarterKit from '@tiptap/starter-kit'
import {convertFromRaw, RawDraftContentState} from 'draft-js'
import {Options, stateToHTML} from 'draft-js-export-html'
import type {Kysely} from 'kysely'
import {Logger} from '../../utils/Logger'

export const serverTipTapExtensions = [
StarterKit,
Expand Down Expand Up @@ -46,7 +47,7 @@ const getNameFromEntity = (content: RawDraftContentState, userId: string) => {
const {length, offset} = entityRange
return text.slice(offset, offset + length)
}
console.log('found unknown for', userId, JSON.stringify(content))
Logger.log('found unknown for', userId, JSON.stringify(content))
return 'Unknown User'
}

Expand Down Expand Up @@ -95,7 +96,7 @@ export async function up(db: Kysely<any>): Promise<void> {
.orderBy('id asc')
.limit(1000)
.execute()
console.log('converting tasks', i * 1000)
Logger.log('converting tasks', i * 1000)
if (tasks.length === 0) break
const updatePromises = [] as Promise<any>[]
for (const task of tasks) {
Expand All @@ -112,7 +113,7 @@ export async function up(db: Kysely<any>): Promise<void> {
.where('id', '=', id)
.execute()
} catch (e) {
console.log('GOT ERR', id, contentStr, e)
Logger.log('GOT ERR', id, contentStr, e)
throw e
}
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/buildServers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require('sucrase/register')
const webpack = require('webpack')
const waitForFileExists = require('./waitForFileExists').default
const path = require('path')
const {Logger} = require('../packages/server/utils/Logger')

const buildServers = async () => {
const config = require('./webpack/dev.servers.config')
Expand All @@ -17,11 +18,11 @@ const buildServers = async () => {
if (!queryMapExists) throw Error('QueryMap Not Available. Run `yarn relay:build`')
compiler.watch({aggregateTimeout: 100}, (err, stats) => {
if (err) {
console.log('Webpack error:', err)
Logger.log('Webpack error:', err)
}
const errors = stats?.compilation?.errors ?? []
if (errors.length > 0) {
console.log('COMPILATION ERRORS:', errors)
Logger.log('COMPILATION ERRORS:', errors)
}
/* servers finished rebuilding */
})
Expand Down
7 changes: 4 additions & 3 deletions scripts/generateGraphQLArtifacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const relayCompilerPath = require('relay-compiler')
const cp = require('child_process')
const runSchemaUpdater = require('./runSchemaUpdater').default
const RelayPersistServer = require('./RelayPersistServer').default
const {Logger} = require('../packages/server/utils/Logger')

const generateGraphQLArtifacts = async () => {
await runSchemaUpdater(true)
Expand All @@ -17,11 +18,11 @@ const generateGraphQLArtifacts = async () => {
})
relayCompiler.stderr.pipe(process.stderr)
})
console.log('gen graphql artifacts start')
Logger.log('gen graphql artifacts start')
await generate(codegenSchema)
console.log('codegen complete')
Logger.log('codegen complete')
await runCompiler()
console.log('relay compiler complete')
Logger.log('relay compiler complete')
persistServer.close()
}

Expand Down
9 changes: 5 additions & 4 deletions scripts/prod.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const generateGraphQLArtifacts = require('./generateGraphQLArtifacts')
const cp = require('child_process')
const {Logger} = require('../packages/server/utils/Logger')

const runChild = (cmd) => {
return new Promise((resolve, reject) => {
Expand All @@ -19,15 +20,15 @@ const runChild = (cmd) => {
}

const prod = async (isDeploy, noDeps) => {
console.log('🙏🙏🙏 Building Production Server 🙏🙏🙏')
Logger.log('🙏🙏🙏 Building Production Server 🙏🙏🙏')
try {
await generateGraphQLArtifacts()
} catch (e) {
console.log('ERR generating artifacts', e)
Logger.log('ERR generating artifacts', e)
process.exit(1)
}

console.log('starting webpack build')
Logger.log('starting webpack build')
try {
await Promise.all([
runChild(
Expand All @@ -38,7 +39,7 @@ const prod = async (isDeploy, noDeps) => {
)
])
} catch (e) {
console.log('error webpackifying', e)
Logger.log('error webpackifying', e)
process.exit(1)
}
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/runSchemaUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
They are included in the build to minimize the number of webpack builds we perform
*/
import webpack from 'webpack'
import {Logger} from 'parabol-server/utils/Logger'

const compileToolbox = async (ignoreErrors: boolean) => {
return new Promise<void>((resolve) => {
const config = require('./webpack/toolbox.config')
const compiler = webpack(config)
compiler.run((err, stats) => {
if (err) {
console.log('Webpack error:', err)
Logger.log('Webpack error:', err)
}
const errors = stats?.compilation?.errors ?? []
if (!ignoreErrors && errors.length > 0) {
console.log('COMPILATION ERRORS:', errors)
Logger.log('COMPILATION ERRORS:', errors)
}
resolve()
})
Expand Down
7 changes: 4 additions & 3 deletions scripts/toolboxSrc/assignSURole.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getPg from '../../packages/server/postgres/getPg'
import yargs from 'yargs'
import {Logger} from '../../packages/server/utils/Logger'

async function assignSURole() {
const argv = await yargs(process.argv.slice(2))
Expand All @@ -26,15 +27,15 @@ async function assignSURole() {
const pg = getPg()
if (argv.removeAll) {
const res = await pg.query(`UPDATE "User" SET rol = null WHERE rol = 'su' RETURNING email`)
console.log('Removed all', res.rows)
Logger.log('Removed all', res.rows)
}
if (argv.add) {
const res = await pg.query(`UPDATE "User" SET rol = 'su' WHERE email = ANY ($1) RETURNING email`, [argv.add])
console.log('Added', res.rows)
Logger.log('Added', res.rows)
}
if (argv.remove) {
const res = await pg.query('UPDATE "User" SET rol = null WHERE email = ANY ($1) RETURNING email', [argv.remove])
console.log('Removed', res.rows)
Logger.log('Removed', res.rows)
}
await pg.end()
}
Expand Down
9 changes: 5 additions & 4 deletions scripts/toolboxSrc/pgEnsureExtensions.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {sql} from 'kysely'
import getKysely from '../../packages/server/postgres/getKysely'
import {Logger} from '../../packages/server/utils/Logger'

export default async () => {
console.log('🔩 Postgres Extension Checks Started')
Logger.log('🔩 Postgres Extension Checks Started')
if (process.env.POSTGRES_USE_PGVECTOR === 'true') {
console.log(' pgvector')
Logger.log(' pgvector')
const pg = getKysely()
await sql`CREATE EXTENSION IF NOT EXISTS "vector";`.execute(pg)
} else {
console.log(' pgvector: skipping check (POSTGRES_USE_PGVECTOR !== true)')
Logger.log(' pgvector: skipping check (POSTGRES_USE_PGVECTOR !== true)')
}
console.log('🔩 Postgres Extension Checks Completed')
Logger.log('🔩 Postgres Extension Checks Completed')
}
3 changes: 2 additions & 1 deletion scripts/toolboxSrc/pgRestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {promisify} from 'util'
import getPg from '../../packages/server/postgres/getPg'
import getPgConfig from '../../packages/server/postgres/getPgConfig'
import getProjectRoot from '../webpack/utils/getProjectRoot'
import {Logger} from '../../packages/server/utils/Logger'

async function pgRestore() {
const exec = promisify(cp.exec)
Expand All @@ -22,7 +23,7 @@ async function pgRestore() {
const requiredFiles = [SCHEMA_ROOT, DATA_ROOT]
for (const file of requiredFiles) {
if (!fs.existsSync(file)) {
console.log(`${file} does not exist`)
Logger.log(`${file} does not exist`)
return
}
}
Expand Down
5 changes: 3 additions & 2 deletions scripts/toolboxSrc/primeIntegrations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getPg from '../../packages/server/postgres/getPg'
import upsertIntegrationProvider from '../../packages/server/postgres/queries/upsertIntegrationProvider'
import {Logger} from '../../packages/server/utils/Logger'

const upsertGlobalIntegrationProvidersFromEnv = async () => {
const providers = [
Expand Down Expand Up @@ -40,9 +41,9 @@ const upsertGlobalIntegrationProvidersFromEnv = async () => {
}

const primeIntegrations = async () => {
console.log('⛓️ Prime Integrationgs Started')
Logger.log('⛓️ Prime Integrationgs Started')
await upsertGlobalIntegrationProvidersFromEnv()
console.log('⛓️ Prime Integrations Complete')
Logger.log('⛓️ Prime Integrations Complete')
}

export default primeIntegrations
15 changes: 8 additions & 7 deletions scripts/toolboxSrc/pushToCDN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import fs from 'fs'
import getFileStoreManager from 'parabol-server/fileStorage/getFileStoreManager'
import path from 'path'
import getProjectRoot from '../webpack/utils/getProjectRoot'
import {Logger} from 'parabol-server/utils/Logger'

const PROJECT_ROOT = getProjectRoot()

Expand All @@ -12,7 +13,7 @@ const pushClientAssetsToCDN = async () => {
const fileStoreManager = getFileStoreManager()
const localClientAssetsDir = path.join(PROJECT_ROOT, 'build')
if (process.env.FILE_STORE_PROVIDER === 'local') {
console.log('⛅️ Using Local File Store for client assets. Skipping...')
Logger.log('⛅️ Using Local File Store for client assets. Skipping...')
return
}

Expand All @@ -29,7 +30,7 @@ const pushClientAssetsToCDN = async () => {
})
)
}
console.log(`⛅️ Uploaded ${dirEnts.length} client assets to CDN`)
Logger.log(`⛅️ Uploaded ${dirEnts.length} client assets to CDN`)
}

const pushServerAssetsToCDN = async () => {
Expand All @@ -56,7 +57,7 @@ const pushServerAssetsToCDN = async () => {
const buffer = await fs.promises.readFile(path.join(localServerAssetsDir, filename))
const {name, ext} = path.parse(filename)
const url = await fileStoreManager.putTemplateIllustration(buffer, 'aGhostOrg', ext, name)
console.log(`⛅️ Uploaded template ${filename} to ${url}`)
Logger.log(`⛅️ Uploaded template ${filename} to ${url}`)
return true
}

Expand All @@ -69,7 +70,7 @@ const pushServerAssetsToCDN = async () => {
if (exists) return false
const buffer = await fs.promises.readFile(path.join(localServerAssetsDir, filename))
const url = await fileStoreManager.putBuildFile(buffer, targetObject)
console.log(`⛅️ Uploaded server asset ${targetObject} to ${url}`)
Logger.log(`⛅️ Uploaded server asset ${targetObject} to ${url}`)
return true
}

Expand All @@ -92,15 +93,15 @@ const pushServerAssetsToCDN = async () => {
)
}

console.log(`⛅️ Server upload complete. Pushed ${pushed} assets to CDN`)
Logger.log(`⛅️ Server upload complete. Pushed ${pushed} assets to CDN`)
}

const pushToCDN = async () => {
console.log('⛅️ Push to CDN Started')
Logger.log('⛅️ Push to CDN Started')
// Perform in serial to guarantee no more than 50 uploads at a time
await pushClientAssetsToCDN()
await pushServerAssetsToCDN()
console.log('⛅️ Push to CDN Complete')
Logger.log('⛅️ Push to CDN Complete')
}

// If called via CLI
Expand Down
3 changes: 2 additions & 1 deletion scripts/toolboxSrc/setIsEnterprise.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getKysely from 'parabol-server/postgres/getKysely'
import {defaultTier} from '../../packages/server/utils/defaultTier'
import {defaultTier} from 'parabol-server/utils/defaultTier'
import {Logger} from 'parabol-server/utils/Logger'

export default async function setIsEnterprise() {
if (defaultTier !== 'enterprise') {
Expand Down

0 comments on commit a92226a

Please sign in to comment.