@justeattakeaway/pie-webc 0.0.0-snapshot-release-20240513075515 → 0.0.0-snapshot-release-20240515132004
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/componentService.js +50 -0
- package/src/index.js +8 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-webc",
|
|
3
3
|
"description": "Component bundle containing all PIE web components",
|
|
4
|
-
"version": "0.0.0-snapshot-release-
|
|
4
|
+
"version": "0.0.0-snapshot-release-20240515132004",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"**/*.js",
|
|
@@ -190,13 +190,13 @@
|
|
|
190
190
|
"@justeattakeaway/pie-assistive-text": "0.3.6",
|
|
191
191
|
"@justeattakeaway/pie-button": "0.47.4",
|
|
192
192
|
"@justeattakeaway/pie-card": "0.19.4",
|
|
193
|
-
"@justeattakeaway/pie-checkbox": "0.
|
|
193
|
+
"@justeattakeaway/pie-checkbox": "0.2.0",
|
|
194
194
|
"@justeattakeaway/pie-chip": "0.6.2",
|
|
195
195
|
"@justeattakeaway/pie-cookie-banner": "0.19.6",
|
|
196
196
|
"@justeattakeaway/pie-divider": "0.13.4",
|
|
197
197
|
"@justeattakeaway/pie-form-label": "0.13.4",
|
|
198
198
|
"@justeattakeaway/pie-icon-button": "0.28.5",
|
|
199
|
-
"@justeattakeaway/pie-input": "0.
|
|
199
|
+
"@justeattakeaway/pie-input": "0.0.0-snapshot-release-20240515132004",
|
|
200
200
|
"@justeattakeaway/pie-link": "0.17.4",
|
|
201
201
|
"@justeattakeaway/pie-modal": "0.42.5",
|
|
202
202
|
"@justeattakeaway/pie-notification": "0.6.0",
|
package/src/componentService.js
CHANGED
|
@@ -6,6 +6,11 @@ export class ComponentService {
|
|
|
6
6
|
this.path = path;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Helper function to get some frequently-used paths for the script.
|
|
11
|
+
* @param {string} workingDir - The current working directory.
|
|
12
|
+
* @returns {Object} - An object containing useful paths for the script.
|
|
13
|
+
*/
|
|
9
14
|
getPathShortcuts (workingDir) {
|
|
10
15
|
const componentsSourceDir = this.path.resolve(workingDir, 'packages/components');
|
|
11
16
|
const pieWebcDir = this.path.join(componentsSourceDir, 'pie-webc');
|
|
@@ -21,12 +26,22 @@ export class ComponentService {
|
|
|
21
26
|
};
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Checks if a directory exists and creates it if it doesn't.
|
|
31
|
+
* @param {string} dir - The directory to create if it doesn't exist.
|
|
32
|
+
*/
|
|
24
33
|
ensureDirectoryExists (dir) {
|
|
25
34
|
if (!this.fs.existsSync(dir)) {
|
|
26
35
|
this.fs.mkdirSync(dir, { recursive: true });
|
|
27
36
|
}
|
|
28
37
|
}
|
|
29
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Reads and returns the package.json file at the given path,
|
|
41
|
+
* making sure that the `exports` and `dependencies` fields are present.
|
|
42
|
+
* @param {string} packageJsonPath - Path to the package.json file, including the file name.
|
|
43
|
+
* @returns - The prepared package.json object.
|
|
44
|
+
*/
|
|
30
45
|
readAndPreparePackageJson (packageJsonPath) {
|
|
31
46
|
const packageJsonData = this.fs.readFileSync(packageJsonPath, 'utf-8');
|
|
32
47
|
const packageJson = JSON.parse(packageJsonData);
|
|
@@ -36,6 +51,12 @@ export class ComponentService {
|
|
|
36
51
|
return packageJson;
|
|
37
52
|
}
|
|
38
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Verifies that the script is run from the root of the monorepo
|
|
56
|
+
* and that the package name matches the expected package name.
|
|
57
|
+
* @param {string} workingDir - The working directory from which the script is being run.
|
|
58
|
+
* @param {*} expectedPackageName - The expected package name for the directory the script should be run from.
|
|
59
|
+
*/
|
|
39
60
|
verifyRootDirectory (workingDir, expectedPackageName) {
|
|
40
61
|
const packageJsonPath = this.path.join(workingDir, 'package.json');
|
|
41
62
|
|
|
@@ -50,6 +71,11 @@ export class ComponentService {
|
|
|
50
71
|
}
|
|
51
72
|
}
|
|
52
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Creates the exports for a component to be added to the pie-webc package.json.
|
|
76
|
+
* @param {string} componentName - The name of the component to create exports for, omitting the `'pie-'` prefix.
|
|
77
|
+
* @returns {Object} - An object containing the exports for the component.
|
|
78
|
+
*/
|
|
53
79
|
createPackageJsonExports (componentName) {
|
|
54
80
|
const exports = {
|
|
55
81
|
[`./components/${componentName}.js`]: {
|
|
@@ -67,6 +93,16 @@ export class ComponentService {
|
|
|
67
93
|
return exports;
|
|
68
94
|
}
|
|
69
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Writes a `.js` and `.d.ts` file for the given component to the target directory.
|
|
98
|
+
* @param {*} componentName - The name of the component to write files for, omitting the `'pie-'` prefix.
|
|
99
|
+
* @param {*} target - An object containing the target directory and the export path.
|
|
100
|
+
* @param {*} target.dir - The target directory to write the files to.
|
|
101
|
+
* Either `'components'` or `'react'`.
|
|
102
|
+
* @param {*} target.exportPath - The export path for the component.
|
|
103
|
+
* For react components, this should be the path to the react.js file including the package name, e.g., `'@justeattakeaway/pie-button/dist/react.js'`.
|
|
104
|
+
* Otherwise, this should be the package name, e.g., `'@justeattakeaway/pie-button'`.
|
|
105
|
+
*/
|
|
70
106
|
writeFilesForComponent (componentName, target) {
|
|
71
107
|
const jsFilePath = this.path.join(target.dir, `${componentName}.js`);
|
|
72
108
|
const tsFilePath = this.path.join(target.dir, `${componentName}.d.ts`);
|
|
@@ -76,10 +112,23 @@ export class ComponentService {
|
|
|
76
112
|
this.fs.writeFileSync(tsFilePath, fileContent);
|
|
77
113
|
}
|
|
78
114
|
|
|
115
|
+
/**
|
|
116
|
+
* Writes the package.json file to the given path.
|
|
117
|
+
* @param {string} path - The path to write the package.json file to.
|
|
118
|
+
* @param {Object} content - The content to write to the package.json file.
|
|
119
|
+
*/
|
|
79
120
|
writePackageJson (path, content) {
|
|
80
121
|
this.fs.writeFileSync(path, `${JSON.stringify(content, null, 2)}\n`);
|
|
81
122
|
}
|
|
82
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Processes all components in the components directory, adding them to the pie-webc package.
|
|
126
|
+
* @param {*} workingDir - The working directory from which the script is run.
|
|
127
|
+
* @param {*} excludedFolders - An array of folder names to exclude from the processing.
|
|
128
|
+
* By default, any folder starting with 'pie-' will be processed, unless excluded.
|
|
129
|
+
* @param {*} packageJson - The package.json object to update with the new dependencies and exports.
|
|
130
|
+
* @returns - The updated package.json object.
|
|
131
|
+
*/
|
|
83
132
|
processComponents (workingDir, excludedFolders, packageJson) {
|
|
84
133
|
const newPackageJson = { ...packageJson };
|
|
85
134
|
const {
|
|
@@ -102,6 +151,7 @@ export class ComponentService {
|
|
|
102
151
|
const componentPackageJsonData = this.fs.readFileSync(componentPackageJsonPath, 'utf-8');
|
|
103
152
|
const componentPackageJson = JSON.parse(componentPackageJsonData);
|
|
104
153
|
|
|
154
|
+
// Add the component to dependencies
|
|
105
155
|
newPackageJson.dependencies[packageName] = componentPackageJson.version;
|
|
106
156
|
|
|
107
157
|
const targets = [
|
package/src/index.js
CHANGED
|
@@ -5,7 +5,12 @@ import chalk from 'chalk';
|
|
|
5
5
|
|
|
6
6
|
import { ComponentService } from './componentService.js';
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The main entry point of the script which adds all components to the pie-webc package.
|
|
10
|
+
* @param {*} fs - Node.js file system module
|
|
11
|
+
* @param {*} path - Node.js path module
|
|
12
|
+
*/
|
|
13
|
+
const addComponents = (fs, path) => {
|
|
9
14
|
const workingDir = process.cwd();
|
|
10
15
|
const componentService = new ComponentService(fs, path);
|
|
11
16
|
componentService.verifyRootDirectory(workingDir, 'pie-monorepo');
|
|
@@ -24,4 +29,5 @@ const main = (fs, path) => {
|
|
|
24
29
|
console.info(chalk.green('\nAll components added to pie-webc!'));
|
|
25
30
|
};
|
|
26
31
|
|
|
27
|
-
|
|
32
|
+
// Run the script
|
|
33
|
+
addComponents(fs, path);
|