1
0
Fork 0

fix(shared): Get rid of build:sitedeps

Recently I refactored the prebuild code. One thing I did not touch (yet)
was the various site dependencies. They were then ported to NX over the
previous system with build priorities we had in place. And while that
was a welcome improvement, it did not really address the bigger picture:
we don't actually need to build any of these dependencies to build the
site.

All we need to do is help NodeJS so it can resolve everything from the
source. So this commit does that by adding a top-level run script
`yarn buildsiteconfigure` which calls `yarn reconfigure` but with the
BUILDSITE variable set.

When that variable is set, the reconfigure script will skip all optional
steps and generate a slightly different package.json file that tells
NodeJS to looks the package from source, rather than to look for the
build files.

After running this script, the prebuild step for the various sites will
run without problems, even on a fresh repo where nothing has ever been
build.

So I've updated the prebuild script in the sites to run this. For local
development, please use `uyarn predev` so that you don't muck with all
the package.json files.
If you do so (by accident or not) a `yarn reconfigure` run will put
everything back in its place.
This commit is contained in:
joostdecock 2023-07-26 19:51:51 +02:00
parent dd6b8a89e7
commit 009e1c1cc9
78 changed files with 80 additions and 222 deletions

View file

@ -12,6 +12,15 @@ import { capitalize } from '../packages/core/src/index.mjs'
// Working directory
const cwd = process.cwd()
/*
* When we're building a site (on Vercel for example) SITEBUILD
* will be set and we'll do things differently to speed up the build.
* To make that check easy, we setup this SITEBUILD variable
*/
const SITEBUILD = process.env.SITEBUILD || false
if (SITEBUILD) console.log('Site build | Configure monorepo accordingly')
/*
* This object holds info about the repository
*/
@ -19,24 +28,26 @@ const repo = {
path: cwd,
defaults: readConfigFile('defaults.yaml'),
keywords: readConfigFile('keywords.yaml'),
badges: readConfigFile('badges.yaml'),
badges: SITEBUILD ? null : readConfigFile('badges.yaml'),
scripts: readConfigFile('scripts.yaml'),
changelog: readConfigFile('changelog.yaml'),
changelog: SITEBUILD ? null : readConfigFile('changelog.yaml'),
changetypes: ['Breaking', 'Added', 'Changed', 'Deprecated', 'Removed', 'Fixed', 'Security'],
dependencies: readConfigFile('dependencies.yaml', { version }),
exceptions: readConfigFile('exceptions.yaml'),
templates: {
pkg: readTemplateFile('package.dflt.json'),
changelog: readTemplateFile('changelog.dflt.md'),
readme: readTemplateFile('readme.dflt.md'),
build: readTemplateFile('build.dflt.mjs'),
pluginTests: readTemplateFile('plugin.test.mjs'),
designTests: readTemplateFile('design.test.mjs.mustache'),
data: readTemplateFile('data.dflt.mjs.mustache'),
changelog: SITEBUILD ? null : readTemplateFile('changelog.dflt.md'),
readme: SITEBUILD ? null : readTemplateFile('readme.dflt.md'),
build: SITEBUILD ? null : readTemplateFile('build.dflt.mjs'),
pluginTests: SITEBUILD ? null : readTemplateFile('plugin.test.mjs'),
designTests: SITEBUILD ? null : readTemplateFile('design.test.mjs.mustache'),
data: SITEBUILD ? null : readTemplateFile('data.dflt.mjs.mustache'),
},
dirs: foldersByType(),
contributors: fs.readFileSync(path.join(cwd, 'CONTRIBUTORS.md'), 'utf-8'),
ac: JSON.parse(fs.readFileSync(path.join(cwd, '.all-contributorsrc'), 'utf-8')),
contributors: SITEBUILD ? null : fs.readFileSync(path.join(cwd, 'CONTRIBUTORS.md'), 'utf-8'),
ac: SITEBUILD
? null
: JSON.parse(fs.readFileSync(path.join(cwd, '.all-contributorsrc'), 'utf-8')),
}
/*
@ -56,19 +67,23 @@ for (const cp of copyThese) {
}
// Step 1: Generate main README file from template
log.write(chalk.blueBright('Generating out main README file...'))
fs.writeFileSync(
path.join(repo.path, 'README.md'),
mustache.render(
fs.readFileSync(path.join(repo.path, 'config', 'templates', 'readme.main.md'), 'utf-8'),
{ allcontributors: repo.ac.contributors.length }
) + repo.contributors
)
log.write(chalk.green(' Done\n'))
if (!SITEBUILD) {
log.write(chalk.blueBright('Generating out main README file...'))
fs.writeFileSync(
path.join(repo.path, 'README.md'),
mustache.render(
fs.readFileSync(path.join(repo.path, 'config', 'templates', 'readme.main.md'), 'utf-8'),
{ allcontributors: repo.ac.contributors.length }
) + repo.contributors
)
log.write(chalk.green(' Done\n'))
}
// Step 2: Validate package configuration
log.write(chalk.blueBright('Validating configuration...'))
if (validate()) log.write(chalk.green(' Done\n'))
if (!SITEBUILD) {
log.write(chalk.blueBright('Validating configuration...'))
if (validate()) log.write(chalk.green(' Done\n'))
}
// Step 3: Generate package.json, pkg.mjs, README, and CHANGELOG
log.write(chalk.blueBright('Generating package-specific files...'))
@ -77,37 +92,40 @@ for (const pkg of Object.values(software)) {
path.join(cwd, pkg.folder, pkg.name, 'package.json'),
JSON.stringify(packageJson(pkg), null, 2) + '\n'
)
if (pkg.type !== 'site') {
fs.writeFileSync(
path.join(cwd, pkg.folder, pkg.name, 'data.mjs'),
mustache.render(repo.templates.data, { name: fullName(pkg.name), version })
)
fs.writeFileSync(path.join(cwd, pkg.folder, pkg.name, 'README.md'), readme(pkg))
if (repo.exceptions.customBuild.indexOf(pkg.name) === -1) {
fs.writeFileSync(path.join(cwd, pkg.folder, pkg.name, 'build.mjs'), repo.templates.build)
if (!SITEBUILD) {
if (pkg.type !== 'site') {
fs.writeFileSync(
path.join(cwd, pkg.folder, pkg.name, 'data.mjs'),
mustache.render(repo.templates.data, { name: fullName(pkg.name), version })
)
fs.writeFileSync(path.join(cwd, pkg.folder, pkg.name, 'README.md'), readme(pkg))
if (repo.exceptions.customBuild.indexOf(pkg.name) === -1) {
fs.writeFileSync(path.join(cwd, pkg.folder, pkg.name, 'build.mjs'), repo.templates.build)
}
fs.writeFileSync(path.join(cwd, pkg.folder, pkg.name, 'CHANGELOG.md'), changelog(pkg))
}
fs.writeFileSync(path.join(cwd, pkg.folder, pkg.name, 'CHANGELOG.md'), changelog(pkg))
}
}
log.write(chalk.green(' Done\n'))
// Step 4: Generate overall CHANGELOG.md
fs.writeFileSync(path.join(repo.path, 'CHANGELOG.md'), changelog('global'))
if (!SITEBUILD) fs.writeFileSync(path.join(repo.path, 'CHANGELOG.md'), changelog('global'))
// Step 5: Generate tests for designs and plugins
for (const design in designs) {
fs.writeFileSync(
path.join(repo.path, 'designs', design, 'tests', 'shared.test.mjs'),
mustache.render(repo.templates.designTests, { name: design, Name: capitalize(design) })
)
if (!SITEBUILD) {
for (const design in designs) {
fs.writeFileSync(
path.join(repo.path, 'designs', design, 'tests', 'shared.test.mjs'),
mustache.render(repo.templates.designTests, { name: design, Name: capitalize(design) })
)
}
for (const plugin in plugins) {
fs.writeFileSync(
path.join(repo.path, 'plugins', plugin, 'tests', 'shared.test.mjs'),
repo.templates.pluginTests
)
}
}
for (const plugin in plugins) {
fs.writeFileSync(
path.join(repo.path, 'plugins', plugin, 'tests', 'shared.test.mjs'),
repo.templates.pluginTests
)
}
// All done
log.write(chalk.green(' All done\n'))
process.exit()
@ -206,16 +224,6 @@ function scripts(pkg) {
runScripts.wbuild = runScripts.wbuild || runScripts.build
runScripts.prewbuild = runScripts.prewbuild || runScripts.prebuild
// make prebuild:sitedeps and windows versions of build:sitedeps and prebuild:sitedeps
if (runScripts['build:sitedeps'] !== undefined) {
runScripts['wbuild:sitedeps'] =
runScripts['wbuild:sitedeps'] || (runScripts.wbuild && 'yarn wbuild')
runScripts['prebuild:sitedeps'] =
runScripts['prebuild:sitedeps'] || (runScripts.prebuild && 'yarn prebuild')
runScripts['prewbuild:sitedeps'] =
runScripts['prewbuild:sitedeps'] || (runScripts.prewbuild && 'yarn prewbuild')
}
// make prebuild:all and windows versions of build:all and prebuild:all
if (runScripts['build:all'] !== undefined) {
runScripts['wbuild:all'] = runScripts['wbuild:all'] || (runScripts.wbuild && 'yarn wbuild')
@ -266,6 +274,14 @@ function packageJson(pkg) {
}
pkgConf.keywords = pkgConf.keywords.concat(keywords(pkg))
pkgConf.scripts = scripts(pkg)
/*
* If we building a site simply override the module entry so that we don't have
* to build any dependencies, but instead can just load them from source
*/
if (SITEBUILD) {
pkgConf.module = 'src/index.mjs'
pkgConf.exports = { '.': './src/index.mjs' }
}
if (repo.exceptions.skipTests.indexOf(pkg.name) !== -1) {
pkgConf.scripts.test = `echo "skipping tests for ${pkg.name}"`
pkgConf.scripts.testci = `echo "skipping tests for ${pkg.name}"`