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

[commit mixup] README: shared-code-entry instructions enhanced #184

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions npm-install-subfolders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const { execSync } = require('child_process');
const { readdirSync, statSync } = require('fs');
const { join, resolve } = require('path');


const initialDir = process.cwd(); // Store the initial working directory

function findDirectSubfolders(dir) {
esride-nik marked this conversation as resolved.
Show resolved Hide resolved
const subfolders = [];
const items = readdirSync(dir);

items.forEach(item => {
const fullPath = join(dir, item);
if (statSync(fullPath).isDirectory()) {
// Check if the directory contains a package.json file
if (readdirSync(fullPath).includes('package.json')) {
subfolders.push(fullPath);
}
}
});

return subfolders;
}

function installInSubfolders(subfolders) {
subfolders.forEach(folder => {
try {
console.log(`Installing npm packages in ${folder}...`);
process.chdir(folder);
execSync('npm install', { stdio: 'inherit' });
} catch (error) {
console.error(`Failed to install in ${folder}: ${error}`);
// process.exit(1);
} finally {
process.chdir(initialDir); // Always return to the initial directory
}
});
}

const rootDir = process.argv.length>2 ? resolve(process.argv[2]) : resolve('./widgets'); // Ensure rootDir is an absolute path
console.log(`Searching for widget folders in rootDir '${rootDir}'`);

const subfolders = findDirectSubfolders(rootDir);
console.log('Widget folders found:', subfolders);

installInSubfolders(subfolders);

console.log('npm install completed in all direct subfolders.');
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "exb-workshop",
"version": "1.1.0",
"description": "themes + widgets in root, own package.json",
"main": "",
"scripts": {
"install-subfolders": "node npm-install-subfolders.js"
},
"author": ""
}
30 changes: 22 additions & 8 deletions widgets/react-data-grid/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion widgets/share-code-widgets/share-code-entry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,22 @@ To support i18n, create a `translations` folder within the `shared-code` folder,
* At last, you can import the shared code like using the standard ES6 imports, like this:
```typescript
import { sampleFunction } from 'widgets/shared-code/entry1'
```
```

## Path resolution of ``shared-code``

By default, the ``paths.widgets`` array in your ``tsconfig.json`` only contains a reference to ``"./your-extensions/widgets/*"``. To enable the TS compiler to find your shared code when importing it in your widget and business code, enhance the array with the folder names of the repositories with ``/widgets/`` postfix:

```
"paths": {
[...]
"widgets/*": [
"./your-extensions/widgets/*",
"./<your_repository>/widgets/*"
]
}
```

## Using shared code in multiple web-extension-repos

To ensure that no entries are overwritten, the central ``ts`` file with the collected exports should be named individually. For example, instead of ``entry1.ts``, you would be using ``entry_<project_name>.ts`` in your repository.