-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathbuild-test-apps.ts
More file actions
99 lines (79 loc) · 3.5 KB
/
build-test-apps.ts
File metadata and controls
99 lines (79 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import fs from 'node:fs'
import path from 'node:path'
import { printLog, runMain } from '../lib/executionUtils.ts'
import { command } from '../lib/command.ts'
import { modifyFile } from '../lib/filesUtils.ts'
const OTHER_EXTENSIONS: Array<{ name: string; options?: { runAt?: string } }> = [
{ name: 'cdn' },
{ name: 'appendChild', options: { runAt: 'document_start' } },
]
runMain(async () => {
printLog('Packing packages...')
command`yarn run pack`.run()
buildApp('test/apps/vanilla')
buildApp('test/apps/react-router-v6-app')
buildApp('test/apps/react-heavy-spa')
buildApp('test/apps/react-shopist-like')
await buildReactRouterv7App()
await buildExtensions()
printLog('Test apps and extensions built successfully.')
})
function buildApp(appPath: string) {
printLog(`Building app at ${appPath}...`)
command`yarn install --no-immutable`.withCurrentWorkingDirectory(appPath).run()
// install peer dependencies if any
// intent: renovate does not allow to generate local packages before install
// so local packages are marked as optional peer dependencies and only installed when we build the test apps
const packageJson = JSON.parse(fs.readFileSync(path.join(appPath, 'package.json'), 'utf-8'))
if (packageJson.peerDependencies) {
// For each peer dependency, install it
for (const [name] of Object.entries(packageJson.peerDependencies)) {
command`yarn add -D ${name}`.withCurrentWorkingDirectory(appPath).run()
}
// revert package.json & yarn.lock changes if they are versioned
const areFilesVersioned = command`git ls-files package.json yarn.lock`.withCurrentWorkingDirectory(appPath).run()
if (areFilesVersioned) {
command`git checkout package.json yarn.lock`.withCurrentWorkingDirectory(appPath).run()
}
}
command`yarn build`.withCurrentWorkingDirectory(appPath).run()
}
async function buildReactRouterv7App() {
const baseAppPath = 'test/apps/react-router-v6-app'
const appPath = 'test/apps/react-router-v7-app'
fs.rmSync(appPath, { recursive: true, force: true })
fs.cpSync(baseAppPath, appPath, { recursive: true })
await modifyFile(path.join(appPath, 'package.json'), (content: string) =>
content
.replace(/"name": "react-router-v6-app"/, '"name": "react-router-v7-app"')
.replace(/"react-router-dom": "[^"]*"/, '"react-router": "7.0.2"')
)
await modifyFile(path.join(appPath, 'app.tsx'), (content: string) =>
content
.replace('@datadog/browser-rum-react/react-router-v6', '@datadog/browser-rum-react/react-router-v7')
.replace("from 'react-router-dom'", "from 'react-router'")
)
await modifyFile(path.join(appPath, 'webpack.config.js'), (content: string) =>
content
.replace('react-router-v6-app.js', 'react-router-v7-app.js')
.replace('react-router-v6-app.js', 'react-router-v7-app.js')
)
buildApp(appPath)
}
async function buildExtensions(): Promise<void> {
const baseExtDir = 'test/apps/base-extension'
buildApp(baseExtDir)
for (const { name, options } of OTHER_EXTENSIONS) {
const targetDir = path.join('test/apps', `${name}-extension`)
fs.rmSync(targetDir, { recursive: true, force: true })
fs.cpSync(baseExtDir, targetDir, { recursive: true })
const manifestPath = path.join(targetDir, 'manifest.json')
await modifyFile(manifestPath, (originalContent: string) => {
let content = originalContent.replace('dist/base.js', `dist/${name}.js`)
if (options?.runAt) {
content = content.replace('document_end', options.runAt)
}
return content
})
}
}