Files
directus/docker/pack.js
Sean Goff b67b9d824a Build improvements (#6759)
* test

* ci improvements

* fix image names

* improve docs

* Update .github/workflows/release.yml

Co-authored-by: Pascal Jufer <paescuj@users.noreply.github.com>

* Update docker/pack.js

Co-authored-by: Pascal Jufer <paescuj@users.noreply.github.com>

* improvements proposed by @paescuj

* improve Dockerfile comment

* fix .PHONY

* rm tarballs before building final image

Co-authored-by: Pascal Jufer <paescuj@users.noreply.github.com>
2021-07-14 16:40:38 -04:00

42 lines
1.4 KiB
JavaScript

const { execSync } = require('child_process');
const { writeFileSync, mkdirSync, existsSync } = require('fs');
const path = require('path/posix');
const lernaListResult = execSync('npx lerna list --json'); //The "proper" way to do this with --include-dependencies and --scope won't work here because it includes devDependencies!
const list = JSON.parse(String(lernaListResult));
const apiPackageJSON = require(path.resolve(__dirname, '../api/package.json'));
const projectPackageJSON = {
name: 'directus-project',
private: true,
description: 'Directus Project',
dependencies: apiPackageJSON.optionalDependencies,
};
const directusPackage = list.find((list) => list.name === 'directus');
if (!existsSync('dist')) {
mkdirSync('dist');
}
function addPackageRecursive(package) {
const tarName = String(
execSync(`npm pack ${package.location}`, { cwd: path.resolve(__dirname, '..', 'dist') })
).trim();
projectPackageJSON.dependencies[package.name] = `file:${tarName}`;
const packageJSON = require(path.join(package.location, 'package.json'));
Object.keys(packageJSON.dependencies || {}).forEach((dependencyName) => {
if (!projectPackageJSON.dependencies[dependencyName]) {
const package = list.find((list) => list.name === dependencyName);
if (package) {
addPackageRecursive(package);
}
}
});
}
addPackageRecursive(directusPackage);
writeFileSync(path.resolve(__dirname, '../dist/package.json'), JSON.stringify(projectPackageJSON, null, 4));