Skip to content

Commit a2df781

Browse files
authored
fix: check if we have an output dir in generators (#146)
1 parent bbf44c4 commit a2df781

File tree

3 files changed

+42
-27
lines changed

3 files changed

+42
-27
lines changed

src/generators/json-simple/index.mjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ export default {
5454
// This simply grabs all the different files and stringifies them
5555
const stringifiedContent = JSON.stringify(mappedInput);
5656

57-
// Writes all the API docs stringified content into one file
58-
// Note: The full JSON generator in the future will create one JSON file per top-level API doc file
59-
await writeFile(join(options.output, 'api-docs.json'), stringifiedContent);
57+
if (options.output) {
58+
// Writes all the API docs stringified content into one file
59+
// Note: The full JSON generator in the future will create one JSON file per top-level API doc file
60+
await writeFile(
61+
join(options.output, 'api-docs.json'),
62+
stringifiedContent
63+
);
64+
}
65+
66+
return mappedInput;
6067
},
6168
};

src/generators/legacy-html-all/index.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { getRemarkRehype } from '../../utils/remark.mjs';
2929
*
3030
* @typedef {Array<TemplateValues>} Input
3131
*
32-
* @type {import('../types.d.ts').GeneratorMetadata<Input, void>}
32+
* @type {import('../types.d.ts').GeneratorMetadata<Input, string>}
3333
*/
3434
export default {
3535
name: 'legacy-html-all',
@@ -96,6 +96,10 @@ export default {
9696
minifyJS: true,
9797
});
9898

99-
await writeFile(join(output, 'all.html'), minified);
99+
if (output) {
100+
await writeFile(join(output, 'all.html'), minified);
101+
}
102+
103+
return minified;
100104
},
101105
};

src/generators/legacy-html/index.mjs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -150,30 +150,34 @@ export default {
150150
for (const node of headNodes) {
151151
const result = processModuleNodes(node);
152152

153-
// We minify the html result to reduce the file size and keep it "clean"
154-
const minified = await minify(result, {
155-
collapseWhitespace: true,
156-
minifyJS: true,
157-
});
158-
159-
await writeFile(join(output, `${node.api}.html`), minified);
153+
if (output) {
154+
// We minify the html result to reduce the file size and keep it "clean"
155+
const minified = await minify(result, {
156+
collapseWhitespace: true,
157+
minifyJS: true,
158+
});
159+
160+
await writeFile(join(output, `${node.api}.html`), minified);
161+
}
160162
}
161163

162-
// Define the output folder for API docs assets
163-
const assetsFolder = join(output, 'assets');
164-
165-
// Removes the current assets directory to copy the new assets
166-
// and prevent stale assets from existing in the output directory
167-
// If the path does not exists, it will simply ignore and continue
168-
await rm(assetsFolder, { recursive: true, force: true });
169-
170-
// We copy all the other assets to the output folder at the end of the process
171-
// to ensure that all latest changes on the styles are applied to the output
172-
// Note.: This is not meant to be used for DX/developer purposes.
173-
await cp(join(baseDir, 'assets'), assetsFolder, {
174-
recursive: true,
175-
force: true,
176-
});
164+
if (output) {
165+
// Define the output folder for API docs assets
166+
const assetsFolder = join(output, 'assets');
167+
168+
// Removes the current assets directory to copy the new assets
169+
// and prevent stale assets from existing in the output directory
170+
// If the path does not exists, it will simply ignore and continue
171+
await rm(assetsFolder, { recursive: true, force: true });
172+
173+
// We copy all the other assets to the output folder at the end of the process
174+
// to ensure that all latest changes on the styles are applied to the output
175+
// Note.: This is not meant to be used for DX/developer purposes.
176+
await cp(join(baseDir, 'assets'), assetsFolder, {
177+
recursive: true,
178+
force: true,
179+
});
180+
}
177181

178182
return generatedValues;
179183
},

0 commit comments

Comments
 (0)