Skip to content

Commit

Permalink
Replace Lerna with custom scripts (#3527)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndricimrr authored Nov 30, 2023
1 parent 17acfb4 commit 728f9f7
Show file tree
Hide file tree
Showing 32 changed files with 4,884 additions and 14,232 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,4 @@ jobs:
~/cypress-binary-cache
key: compat_buildcache
- run: cp -r ~/tmp_build/* .
# - run: npm i -g lerna
# - run: lerna bootstrap --ci --force-local --ignore docs
# - run: lerna run bundle --ignore docs --scope luigi-client-private
# - run: lerna run bundle --ignore docs --scope @luigi-project/testing-utilities
#- run: lerna run bundle --ignore docs
- run: bash ./scripts/testCompatibility.sh --tag latest
13 changes: 5 additions & 8 deletions .github/workflows/prepare.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ jobs:
~/cypress-binary-cache
key: ${{ inputs.buildcache_key }}
- run: ls test
- run: npm i -g [email protected]
- run: lerna bootstrap --ci --force-local --ignore docs
- run: lerna run bundle --ignore docs --scope luigi-client-private
- run: lerna run bundle --ignore docs --scope @luigi-project/testing-utilities
- run: lerna run bundle --ignore docs --scope @luigi-project/client-support-angular
- run: lerna run bundle --ignore docs
- run: lerna run bundlesizeOnly --ignore docs
- run: lerna run build --ignore docs
# Bundle all
- run: npm run bootstrap
- run: npm run bundle
# Check bundlesize not exceeded
- run: npm run bundlesize
- run: pwd
- run: sudo cp -r . ~/tmp_build
- run: ls -l ~/tmp_build
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ jobs:
key: buildcache
- run: cp -r ~/tmp_build/* .
- run: npm i -g cypress
- run: npm i -g [email protected]
- run: npm i -g live-server
- run: bash ./test/mockengine.sh || exit 1

Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ node_modules
.vscode/diff
.vscode/settings.json

# Lerna
lerna-debug.log

.changelog

# temporary files and folders
Expand All @@ -25,3 +22,4 @@ core/dev-tools/latest_build.log
core/dev-tools/simple-app
/full_eslint_report.html
test/e2e-test-application/cypress/screenshots
**/.DS_Store
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Once the applications are ready:

### Backward compatibility tests

Use these tests to ensure that applications written for previous versions of Luigi still work after Luigi gets updated with npm. Before running the tests, bundle Luigi by running `lerna run bundle` in the main repository folder.
Use these tests to ensure that applications written for previous versions of Luigi still work after Luigi gets updated with npm. Before running the tests, bundle Luigi by running `npm run bundle` in the main repository folder.

Install [jq](https://stedolan.github.io/jq/) using the `brew install jq` command. It is required for the script to work, however, you can omit it if the command you are using to run your tests is tagged `latest`.

Expand Down
79 changes: 79 additions & 0 deletions bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* This file is used to run (npm install) in all of the folders which have it as a prerequisite in the pipeline and during local development
*/

const { exec } = require('child_process');

// Array of folder names
const folders = [
'./',
'core',
'client',
'client-frameworks-support/client-support-angular',
'client-frameworks-support/testing-utilities',
'container',
'plugins',
'scripts',
'test/e2e-test-application',
'test/e2e-js-test-application',
'client-frameworks-support/testing-utilities/test'
];
// Check for verbose flag
const verboseFlagIndex = process.argv.indexOf('--verbose');
let isVerbose = verboseFlagIndex !== -1;

// Function to install npm packages in given folder
function installPackages(folder, index, totalFolders) {
return new Promise((resolve, reject) => {
const command = `cd ${folder} && npm install`;

exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`\x1b[31mError installing npm packages in ${folder} \x1b[0m`);
reject(error);
} else {
console.log(
`\x1b[32m[${index + 1}/${totalFolders}] : npm packages installed successfully in \x1b[33m${folder}\x1b[0m`
);
// Print logs if needed
if (isVerbose) {
console.log('VERBOSE:', stdout);
}
resolve();
}
});
});
}

// Function to install packages in all folders sequentially
async function installAllPackages() {
for (let i = 0; i < folders.length; i++) {
await installPackages(folders[i], i, folders.length);
}
}

/**
* Function to handle the error case for promises
* @param {*} error error
*/
function errorHandler(error) {
console.error('Stopping execution of the process due to error:', error);
process.exit(1);
}

// EXECUTE CODE STARTS HERE

console.log(
`\x1b[36m\n\nInstalling node_modules packages in these folders in the following order:\x1b[0m ${
isVerbose ? '\x1b[41m\x1b[37m(VERBOSE)\x1b[0m' : ''
}`
);
for (const folder of folders) {
console.log('- ' + folder);
}

console.log('Starting ---------->');

installAllPackages().then(() => {
console.log('\x1b[32m+++++++++++> Finished installing packages successfuly. <++++++++++++++++\x1b[0m\n');
}, errorHandler);
55 changes: 55 additions & 0 deletions bundle-size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* This file is used to check if bundle size threshold is not exceded
*/

const fs = require('fs');
const path = require('path');

const filesAndLimits = [
{
path: 'client/public/luigi-client.js',
limit: 50
},
{
path: 'core/public/luigi.js',
limit: 650
},
{
path: 'core/public/luigi.css',
limit: 800
},
{
path: 'plugins/auth/public/auth-oauth2/plugin.js',
limit: 75
}
];

async function checkFileSizes() {
for (const { path: filePath, limit } of filesAndLimits) {
const fullPath = path.resolve(__dirname, filePath);
console.log(`\x1b[33m\n\nChecking bundlesize in \x1b[32m${filePath}\x1b[0m`);

try {
const stats = await fs.promises.stat(fullPath);
const fileSizeInKB = (stats.size / 1024).toFixed(2);

if (fileSizeInKB > limit) {
console.error(
`\x1b[31m \n ERROR: ${filePath} exceeds the size limit. Actual size: ${fileSizeInKB} KB, Limit: ${limit} KB ! \x1b[0m\n`
);
process.exit(1);
} else {
console.log(
`\x1b[32m\u2713\x1b[0m ${filePath} is within the size limit. Size: \x1b[33m${fileSizeInKB} KB\x1b[0m < \x1b[32m${limit} KB\x1b[0m`
);
}
} catch (error) {
console.error(`Error reading file ${filePath}: ${error.message}`);
process.exit(1);
}
}

console.log('\x1b[32m\u2713\x1b[0m \x1b[32m All files are within their size limits.\x1b[0m \x1b[32m\u2713\x1b[0m');
}

checkFileSizes();
90 changes: 90 additions & 0 deletions bundle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const { exec } = require('child_process');

// Array of folder names
const foldersToBundle = [
'core',
'client',
'client-frameworks-support/testing-utilities',
'client-frameworks-support/client-support-angular',
'container',
'plugins'
];

const foldersToBuild = ['test/e2e-test-application'];

let timeToBundle = 0;
let timeToBuild = 0;

// Check for verbose flag
const verboseFlagIndex = process.argv.indexOf('--verbose');
let isVerbose = verboseFlagIndex !== -1;

// Function to run 'npm run <operation>' in a folder
function runCommand(folder, index, totalFolders, operation) {
const startTime = new Date();

return new Promise((resolve, reject) => {
const command = `cd ${folder} && npm run ${operation}`;

exec(command, (error, stdout, stderr) => {
const endTime = new Date();
const elapsedTime = (endTime - startTime) / 1000;
timeToBundle += operation === 'bundle' ? elapsedTime : 0;
timeToBuild += operation === 'build' ? elapsedTime : 0;

if (error) {
console.error(`\x1b[31mError when trying to ${operation} packages in ${folder} \x1b[0m`);
reject(error);
} else {
console.log(
`\x1b[36m[${index +
1}/${totalFolders}]\x1b[0m: \x1b[33m${folder}\x1b[0m ${operation} successful (\x1b[33m${elapsedTime.toFixed(
2
)}s\x1b[0m)`
);
// Print logs if needed
if (isVerbose) {
console.log('VERBOSE:', stdout);
}
resolve();
}
});
});
}

// Function to run 'npm run bundle' in all specified folders
async function runCommandInAllFolders(folders, operation) {
console.log(
`\x1b[36m\n\nRunning (npm run ${operation}) in these folders in the following order:\x1b[0m ${
isVerbose ? '\x1b[41m\x1b[37m(VERBOSE)\x1b[0m' : ''
}`
);
for (const folder of folders) {
console.log('- ' + folder);
}

for (let i = 0; i < folders.length; i++) {
console.log(`\n\x1b[37m${operation} \x1b[33m${folders[i]}\x1b[0m ...`);
await runCommand(folders[i], i, folders.length, operation);
}
}

// Run the 'npm run bundle' command in the specified folders
runCommandInAllFolders(foldersToBundle, 'bundle').then(() => {
console.log(`Bundle finished in ${timeToBundle.toFixed(2)}s`);

// Run the 'npm run build' command in the specified folders
runCommandInAllFolders(foldersToBuild, 'build').then(() => {
console.log(`Build finished in ${timeToBuild.toFixed(2)}s\n`);
console.log(`\nBuild+Bundle finished in ${(timeToBuild + timeToBundle).toFixed(2)}s\n`);
}, errorHandler);
}, errorHandler);

/**
* Function to handle the error case for promises
* @param {*} error error
*/
function errorHandler(error) {
console.error('Stopping execution of the process due to error:', error);
process.exit(1);
}
Loading

0 comments on commit 728f9f7

Please sign in to comment.