Skip to content

Commit

Permalink
fix: dashmate packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
shumkov committed Jun 30, 2024
1 parent b7d4fef commit 12bd894
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/dashmate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"bin",
"configs",
"docker",
"src",
"dist",
"templates",
"docker-compose.*",
"oclif.manifest.json",
Expand Down
17 changes: 15 additions & 2 deletions scripts/pack_dashmate.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

set -e
set -ex

cmd_usage="Usage: pack_dashmate.sh COMMAND
Expand Down Expand Up @@ -32,15 +32,28 @@ ROOT_PATH=$(dirname "$DIR_PATH")
export NODE_ENV=production

cd $ROOT_PATH/packages/dashmate || exit 1

# Build and copy artifacts to package
yarn build

# Isolate dashmate package from workspace
yarn pack --install-if-needed
tar zxvf package.tgz -C .

cd $ROOT_PATH/packages/dashmate/package || exit 1

# Install dependencies
cp $ROOT_PATH/yarn.lock ./yarn.lock
mkdir .yarn
echo "nodeLinker: pnpm" > .yarnrc.yml
# TODO: Remove bundled dependencies from package.json
# Remove already bundled dependencies
node "$DIR_PATH"/patch_dashmate_package_json.js
yarn install --no-immutable

# Create oclif manifest
yarn oclif manifest

# Pack dashmate into package
yarn oclif pack $COMMAND $FLAGS
cd .. || exit 1
rm package.tgz
Expand Down
32 changes: 32 additions & 0 deletions scripts/patch_dashmate_package_json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const fs = require('fs');
const path = require('path');

// Step 1: Read the build.js file and extract the external array
const buildJsContent = fs.readFileSync(path.join(__dirname, '../packages/dashmate/scripts/build.js'), 'utf8');
const externalMatch = buildJsContent.match(/external: \[([^\]]+)\]/);
if (!externalMatch) {
console.error('Could not find external array in build.js');
process.exit(1);
}
const external = externalMatch[1].split(',').map(s => s.trim().replace(/['"]/g, ''));

// Step 2: Read the package.json file and parse it into a JSON object
const packageJsonPath = path.join(__dirname, '../packages/dashmate/package/package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));

// Step 3: Iterate over the dependencies in the package.json object and remove any that are not in the external array
for (const dep in packageJson.dependencies) {
if (!external.includes(dep)) {
delete packageJson.dependencies[dep];
}
}

// Step 3: Iterate over the dependencies in the package.json object and remove any that are not in the external array
for (const dep in packageJson.devDependencies) {
if (dep !== 'oclif') {
delete packageJson.devDependencies[dep];
}
}

// Step 5: Write the modified package.json object back to the package.json file
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));

0 comments on commit 12bd894

Please sign in to comment.