codify-plugin-lib 1.0.182-beta52 → 1.0.182-beta53

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.
Files changed (2) hide show
  1. package/bin/build.js +86 -5
  2. package/package.json +1 -1
package/bin/build.js CHANGED
@@ -5,9 +5,8 @@ import mergeJsonSchemas from 'merge-json-schemas';
5
5
  import { fork } from 'node:child_process';
6
6
  import fs from 'node:fs';
7
7
  import path from 'node:path';
8
- import * as url from 'node:url';
9
8
 
10
- import { VerbosityLevel, SequentialPty } from '../dist/index.js';
9
+ import { SequentialPty, VerbosityLevel } from '../dist/index.js';
11
10
 
12
11
  const ajv = new Ajv({
13
12
  strict: true
@@ -36,6 +35,58 @@ function sendMessageAndAwaitResponse(process, message) {
36
35
  });
37
36
  }
38
37
 
38
+ function fetchDocumentationMaps() {
39
+ console.log('Building documentation...');
40
+
41
+ const results = new Map();
42
+ const resourcesPath = path.resolve(process.cwd(), 'src', 'resources');
43
+ const resourcesDir = fs.readdirSync(resourcesPath);
44
+
45
+ for (const resource of resourcesDir) {
46
+ const resourcePath = path.join(resourcesPath, resource);
47
+ if (!isDirectory(resourcePath)) continue;
48
+
49
+ const contents = fs.readdirSync(resourcePath);
50
+ const isGroup = contents.some((content) => isDirectory(path.join(resourcePath, content)));
51
+ const isAllDir = contents.every((content) => isDirectory(path.join(resourcePath, content)));
52
+
53
+ if (isGroup && !isAllDir) {
54
+ throw new Error(`Documentation groups must only contain directories. ${resourcePath} does not`);
55
+ }
56
+
57
+ if (!isGroup) {
58
+ if (contents.includes('README.md')) {
59
+ results.set(resource, resource);
60
+ }
61
+ } else {
62
+ for (const innerDir of contents) {
63
+ const innerDirReadme = path.join(resourcePath, innerDir, 'README.md');
64
+ if (isFile(innerDirReadme)) {
65
+ results.set(innerDir, path.relative('./src/resources', path.join(resourcePath, innerDir)));
66
+ }
67
+ }
68
+ }
69
+ }
70
+
71
+ return results;
72
+ }
73
+
74
+ function isDirectory(path) {
75
+ try {
76
+ return fs.statSync(path).isDirectory();
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ function isFile(path) {
83
+ try {
84
+ return fs.statSync(path).isFile();
85
+ } catch {
86
+ return false;
87
+ }
88
+ }
89
+
39
90
  VerbosityLevel.set(3);
40
91
  const $ = new SequentialPty();
41
92
 
@@ -60,6 +111,7 @@ const initializeResult = await sendMessageAndAwaitResponse(plugin, {
60
111
 
61
112
  const { resourceDefinitions } = initializeResult;
62
113
  const resourceTypes = resourceDefinitions.map((i) => i.type);
114
+ const resourceInfoMap = new Map();
63
115
 
64
116
  const schemasMap = new Map()
65
117
  for (const type of resourceTypes) {
@@ -69,8 +121,11 @@ for (const type of resourceTypes) {
69
121
  })
70
122
 
71
123
  schemasMap.set(type, resourceInfo.schema);
124
+ resourceInfoMap.set(type, resourceInfo);
72
125
  }
73
126
 
127
+ console.log(resourceInfoMap);
128
+
74
129
  const mergedSchemas = [...schemasMap.entries()].map(([type, schema]) => {
75
130
  // const resolvedSchema = await $RefParser.dereference(schema)
76
131
  const resourceSchema = JSON.parse(JSON.stringify(ResourceSchema));
@@ -97,12 +152,38 @@ await $.spawn('npm run rollup', { interactive: true }); // re-run rollup without
97
152
 
98
153
  console.log('Generated JSON Schemas for all resources')
99
154
 
100
- const distFolder = path.resolve(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'dist');
155
+ const distFolder = path.resolve(process.cwd(), 'dist');
101
156
  const schemaOutputPath = path.resolve(distFolder, 'schemas.json');
102
157
  fs.writeFileSync(schemaOutputPath, JSON.stringify(mergedSchemas, null, 2));
103
158
 
104
- console.log('Successfully wrote schema to ./dist/schemas.json')
105
-
159
+ console.log('Successfully wrote schema to ./dist/schemas.json');
160
+
161
+ const documentationMap = fetchDocumentationMaps();
162
+
163
+ const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf8'));
164
+
165
+ fs.writeFileSync('./dist/manifest.json', JSON.stringify({
166
+ name: packageJson.name,
167
+ version: packageJson.version,
168
+ description: packageJson.description,
169
+ resources: [...resourceInfoMap.values()].map((info) => ({
170
+ type: info.type,
171
+ description: info.description ?? info.schema?.description,
172
+ sensitiveParameters: info.sensitiveParameters,
173
+ schema: info.schema,
174
+ operatingSystems: info.operatingSystems,
175
+ documentationKey: documentationMap.get(info.type),
176
+ })),
177
+ }, null, 2), 'utf8');
178
+
179
+ for (const key of documentationMap.values()) {
180
+ fs.mkdirSync(path.join('dist', 'documentation', key), { recursive: true })
181
+
182
+ fs.copyFileSync(
183
+ path.resolve(path.join('src', 'resources', key, 'README.md')),
184
+ path.resolve(path.join('dist', 'documentation', key, 'README.md')),
185
+ );
186
+ }
106
187
 
107
188
  plugin.kill(9);
108
189
  process.exit(0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.182-beta52",
3
+ "version": "1.0.182-beta53",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",