Skip to content

Commit

Permalink
add modified rollup config
Browse files Browse the repository at this point in the history
  • Loading branch information
joeluong-sfcc committed Dec 23, 2024
1 parent c9c116f commit 8d0bb70
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 9 deletions.
40 changes: 40 additions & 0 deletions listFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const fs = require('fs');

Check failure on line 1 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

missing header

Check failure on line 1 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Require statement not part of import statement

Check failure on line 1 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

missing header

Check failure on line 1 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Require statement not part of import statement

Check failure on line 1 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

missing header

Check failure on line 1 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Require statement not part of import statement
const path = require('path');

Check failure on line 2 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Require statement not part of import statement

Check failure on line 2 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Require statement not part of import statement

Check failure on line 2 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Require statement not part of import statement

/**
* Recursively collects all file paths in a directory.
* @param {string} dir - The directory to scan.
* @param {string} baseDir - The base directory for relative paths.
* @param {Array<string>} fileList - Array to collect file paths.
* @returns {Array<string>} The list of file paths.
*/
function getAllFiles(dir, baseDir = dir, fileList = []) {
const files = fs.readdirSync(dir);

Check warning on line 12 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Delete `··`

Check warning on line 12 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Delete `··`

Check warning on line 12 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Delete `··`

files.forEach((file) => {

Check warning on line 14 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Replace `··files.forEach((file)` with `files.forEach(file`

Check warning on line 14 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Replace `··files.forEach((file)` with `files.forEach(file`

Check warning on line 14 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Replace `··files.forEach((file)` with `files.forEach(file`
const filePath = path.join(dir, file);

Check warning on line 15 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Replace `········` with `····`

Check warning on line 15 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Replace `········` with `····`

Check warning on line 15 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Replace `········` with `····`
const stats = fs.statSync(filePath);

Check warning on line 16 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Delete `····`

Check warning on line 16 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Delete `····`

Check warning on line 16 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Delete `····`

if (stats.isDirectory()) {

Check warning on line 18 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Delete `····`

Check warning on line 18 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Delete `····`

Check warning on line 18 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Delete `····`
getAllFiles(filePath, baseDir, fileList); // Recurse into subdirectory

Check warning on line 19 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Delete `······`

Check warning on line 19 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Delete `······`

Check warning on line 19 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Delete `······`
} else {

Check warning on line 20 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Replace `········` with `····`

Check warning on line 20 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Replace `········` with `····`

Check warning on line 20 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Replace `········` with `····`
fileList.push('"src/lib/' + path.relative(baseDir, filePath) + '",'); // Store relative path

Check warning on line 21 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Delete `······`

Check failure on line 21 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Unexpected string concatenation

Check warning on line 21 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Delete `······`

Check failure on line 21 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Unexpected string concatenation

Check warning on line 21 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Delete `······`

Check failure on line 21 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Unexpected string concatenation
}

Check warning on line 22 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Delete `····`

Check warning on line 22 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Delete `····`

Check warning on line 22 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Delete `····`
});

Check warning on line 23 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (12)

Delete `··`

Check warning on line 23 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (16)

Delete `··`

Check warning on line 23 in listFiles.js

View workflow job for this annotation

GitHub Actions / linux-tests (18)

Delete `··`

return fileList;
}

// Usage
const targetDir = process.argv[2]; // Directory passed as argument
if (!targetDir) {
console.error('Please provide a directory path.');
process.exit(1);
}

try {
const relativeFilePaths = getAllFiles(targetDir);
relativeFilePaths.forEach((filePath) => console.log(filePath));
} catch (error) {
console.error(`Error reading directory: ${error.message}`);
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "commerce-sdk-isomorphic",
"version": "3.1.1",
"private": false,
"sideEffects": false,
"description": "Salesforce Commerce SDK Isomorphic",
"bugs": {
"url": "https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic/issues"
Expand All @@ -11,7 +12,7 @@
"url": "git+https://github.com/SalesforceCommerceCloud/commerce-sdk-isomorphic.git"
},
"license": "BSD-3-Clause",
"main": "lib/index.cjs.js",
"main": "lib/index.js",
"module": "lib/index.esm.js",
"style": "lib/default.css",
"files": [
Expand Down Expand Up @@ -122,7 +123,7 @@
"@typescript-eslint/eslint-plugin": "^4.33.0",
"@typescript-eslint/parser": "^4.33.0",
"autoprefixer": "9.8.8",
"bundlesize": "^0.18.1",
"bundlesize": "^0.18.2",
"depcheck": "^1.4.3",
"dotenv": "^16.0.3",
"eslint": "^7.32.0",
Expand Down
49 changes: 42 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,42 @@ import pkg from './package.json';

const extensions = ['.js', '.jsx', '.ts', '.tsx'];

const inputs = [
"src/lib/clientConfig.ts",
"src/lib/config.ts",
"src/lib/helpers/customApi.ts",
"src/lib/helpers/environment.ts",
"src/lib/helpers/fetchHelper.ts",
"src/lib/helpers/index.ts",
"src/lib/helpers/slasHelper.ts",
"src/lib/helpers/types.ts",
"src/lib/index.ts",
"src/lib/responseError.ts",
"src/lib/shopperBaskets.ts",
"src/lib/shopperContexts.ts",
"src/lib/shopperCustomers.ts",
"src/lib/shopperDiscoverySearch.ts",
"src/lib/shopperExperience.ts",
"src/lib/shopperGiftCertificates.ts",
"src/lib/shopperLogin.ts",
"src/lib/shopperOrders.ts",
"src/lib/shopperProducts.ts",
"src/lib/shopperPromotions.ts",
"src/lib/shopperSearch.ts",
"src/lib/shopperSeo.ts",
"src/lib/shopperStores.ts",
"src/lib/templateUrl.ts",
"src/lib/version.ts",
]

const outputs = [
// {
// dir: 'temp/umd',
// file: process.env.REACT_APP_PKG_MAIN || pkg.main,
// format: 'umd',
// },
{
file: process.env.REACT_APP_PKG_MAIN || pkg.main,
format: 'umd',
},
{
dir: 'lib',
file: process.env.REACT_APP_PKG_MODULE || pkg.module,
format: 'es',
},
Expand All @@ -39,10 +69,12 @@ const postcssPlugins = [
autoprefixer(),
];

const config = outputs.map(({file, format}) => ({
input: 'src/lib/index.ts',
const config = outputs.map(({dir, file, format}) => ({
// input: 'src/lib/index.ts',
input: inputs,
output: {
file,
// file,
dir,
format,
name: 'CommerceSdk',
globals: {
Expand Down Expand Up @@ -87,6 +119,9 @@ const config = outputs.map(({file, format}) => ({
terser(),
filesize(),
],
treeshake: {
moduleSideEffects: false, // Ignore side effects
},
}));

export default config;

0 comments on commit 8d0bb70

Please sign in to comment.