8
8
schemaPath :
9
9
description : " The path to the plugin settings schema."
10
10
required : false
11
- default : " ${{ github.workspace }}/src/types/plugin-input.js "
11
+ default : " ${{ github.workspace }}/src/types/plugin-input.ts "
12
12
pluginEntry :
13
13
description : " The path to the plugin entry file."
14
14
required : false
37
37
run : |
38
38
yarn install --immutable --immutable-cache --check-cache
39
39
40
- - name : Compile TypeScript files
41
- shell : bash
42
- run : |
43
- yarn tsc --project tsconfig.json -m commonjs
44
-
45
40
- name : Build project
46
41
shell : bash
47
42
run : |
@@ -55,38 +50,75 @@ runs:
55
50
uses : actions/github-script@v7
56
51
with :
57
52
script : |
58
- const fs = require('fs');
53
+ const fs = require('fs').promises ;
59
54
const path = require('path');
60
55
61
- const { pluginSettingsSchema } = require('${{ github.workspace }}/plugin/index');
56
+ async function updateManifest() {
57
+ const manifestPath = '${{ inputs.manifestPath }}';
58
+ const pluginPath = path.resolve('${{ github.workspace }}', 'plugin', 'index.js');
62
59
63
- const manifestPath = '${{ inputs.manifestPath }}'
64
- const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
60
+ let pluginSettingsSchema;
61
+ try {
62
+ // First, try to load as ESM
63
+ try {
64
+ const pluginModule = await import(`file://${pluginPath}`);
65
+ pluginSettingsSchema = pluginModule.pluginSettingsSchema;
65
66
66
- const configuration = JSON.stringify(pluginSettingsSchema);
67
-
68
- manifest["configuration"] = JSON.parse(configuration);
67
+ if (!pluginSettingsSchema) {
68
+ throw new Error('pluginSettingsSchema not found in the ESM module');
69
+ }
70
+ } catch (esmError) {
71
+ // If ESM import fails, try loading as CJS
72
+ try {
73
+ const pluginModule = require(pluginPath);
74
+ pluginSettingsSchema = pluginModule.pluginSettingsSchema;
69
75
70
- function customReviver(key, value) {
71
- if (typeof value === "object" && value !== null) {
72
- if ("default" in value && "required" in value) {
73
- delete value.required;
76
+ if (!pluginSettingsSchema) {
77
+ throw new Error('pluginSettingsSchema not found in the CJS module');
78
+ }
79
+ } catch (cjsError) {
80
+ console.error('Error loading module as ESM and CJS:', esmError, cjsError);
81
+ process.exit(1);
82
+ }
74
83
}
75
- if (Array.isArray(value.required)) {
76
- value.required = value.required.filter(
77
- (prop) => !(value.properties[prop] && "default" in value.properties[prop])
78
- );
79
- if (!value.required.length) {
80
- delete value.required;
84
+ } catch (error) {
85
+ console.error('Error loading module:', error);
86
+ process.exit(1);
87
+ }
88
+
89
+ const manifest = JSON.parse(await fs.readFile(manifestPath, 'utf8'));
90
+ manifest["configuration"] = pluginSettingsSchema;
91
+
92
+ function customReviver(key, value) {
93
+ if (typeof value === "object" && value !== null) {
94
+ if ("properties" in value && "required" in value) {
95
+ const requiredFields = new Set(value.required);
96
+ for (const [propKey, propValue] of Object.entries(value.properties)) {
97
+ if (typeof propValue === 'object' && 'default' in propValue) {
98
+ requiredFields.delete(propKey);
99
+ }
100
+ }
101
+ value.required = Array.from(requiredFields);
102
+ if (value.required.length === 0) {
103
+ delete value.required;
104
+ }
105
+ }
106
+
107
+ // Recursively apply to nested objects and arrays
108
+ if (Array.isArray(value)) {
109
+ return value.map(item => JSON.parse(JSON.stringify(item), customReviver));
110
+ } else {
111
+ return Object.fromEntries(
112
+ Object.entries(value).map(([k, v]) => [k, JSON.parse(JSON.stringify(v), customReviver)])
113
+ );
81
114
}
82
115
}
116
+ return value;
83
117
}
84
- return value;
118
+
119
+ const updatedManifest = JSON.stringify(manifest, customReviver, 2);
120
+ await fs.writeFile(manifestPath, updatedManifest, 'utf8');
85
121
}
86
-
87
- const updatedManifest = JSON.stringify(manifest, customReviver, 2);
88
- console.log('Updated manifest:', updatedManifest);
89
- fs.writeFileSync(manifestPath, updatedManifest);
90
122
91
123
- name : Format manifest using Prettier
92
124
shell : bash
0 commit comments