Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New file utils.js, moved teardown function #1080

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@

### 🪛 Refactoring

- Improve organization of the build scripts by isolating utilities ([#1080](https://github.com/opensearch-project/oui/pull/1080))


### 🔩 Tests

## [`1.3.0`](https://github.com/opensearch-project/oui/tree/1.3.0)
Expand Down
5 changes: 5 additions & 0 deletions scripts/compile-clean.js
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should also get an empty line at the end of the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright will change this

Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
*/

const { rimraf } = require('rimraf');
const { euiBuildTimeAliasTearDown } = require('./utils'); // Import the utility function

rimraf.sync('.cache-loader');
rimraf.sync('dist');
rimraf.sync('lib');
rimraf.sync('es');
rimraf.sync('test-env');
rimraf.sync('types');

/* OUI -> EUI Aliases */
euiBuildTimeAliasTearDown();
/* End of Aliases */
19 changes: 1 addition & 18 deletions scripts/compile-oui.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const path = require('path');
const glob = require('glob');
const fs = require('fs');
const dtsGenerator = require('dts-generator').default;
const { euiBuildTimeAliasTearDown} = require('./utils'); // Import the utility functions

/* OUI -> EUI Aliases */
function euiBuildTimeAliasSetup() {
Expand Down Expand Up @@ -157,24 +158,6 @@ function euiBuildTimeAliasTypeDef(file) {
fs.writeFileSync(file, '\n' + reExportStatements.join('\n'), { flag: 'a', encoding: 'utf8' });
}

function euiBuildTimeAliasTearDown() {
console.log('Tearing down build-time EUI aliases');
shell.rm('-rf', 'src/eui_components');

// Remove any changes made at build time
shell.ls('src/components/**/*.*').forEach(file => {
if (/__snapshots__|\.d\.ts|\.test\.|\.scss/.test(file)) return;
let changed;
const content = fs.readFileSync(file, 'utf8')
.replace(/\n\/\* OUI -> EUI Aliases: Build-Time \*\/.*$/mg, () => {
changed = true;
return '';
});
if (changed) fs.writeFileSync(file, content, 'utf8');
});
}
/* End of Aliases */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This marker should remain in the codebase


function compileLib() {
shell.mkdir(
'-p',
Expand Down
29 changes: 29 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const shell = require('shelljs');
const fs = require('fs');

<<<<<<< HEAD

=======
>>>>>>> cc445de2f11c9b8239d710133673ddc534d73b8f
Comment on lines +4 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a merge conflict remnant here

/* OUI -> EUI Aliases */
function euiBuildTimeAliasTearDown() {
console.log('Tearing down build-time EUI aliases');
shell.rm('-rf', 'src/eui_components');

// Remove any changes made at build time
shell.ls('src/components/**/*.*').forEach(file => {
if (/__snapshots__|\.d\.ts|\.test\.|\.scss/.test(file)) return;
let changed;
const content = fs.readFileSync(file, 'utf8')
.replace(/\n\/\* OUI -> EUI Aliases: Build-Time \*\/.*$/mg, () => {
changed = true;
return '';
});
if (changed) fs.writeFileSync(file, content, 'utf8');
});
}
AwesomeSauce42 marked this conversation as resolved.
Show resolved Hide resolved
/* End of Aliases */

module.exports = {
euiBuildTimeAliasTearDown,
};
Loading