forked from revisit-studies/study
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibraryExampleStudyGenerator.cjs
More file actions
99 lines (85 loc) · 3.51 KB
/
Copy pathlibraryExampleStudyGenerator.cjs
File metadata and controls
99 lines (85 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* eslint-disable @typescript-eslint/no-require-imports */
// This script generates example study configurations for libraries in the public/libraries directory
// It creates a new directory for each library (library-{name}) with a basic config.json and an assets folder
// It will run libraryDocGenerator.cjs to generate library.md files, which will be placed in the assets/ folder of each example study to serve as the introduction component
// The script will skip:
// - Libraries that already have a library-{name} folder (e.g. if library-demographics exists)
const fs = require('fs');
const path = require('path');
const { generateLibraryDocs, getLibraries } = require('./libraryDocGenerator.cjs');
// Create example study config template
const createExampleConfig = (libraryName) => ({
$schema: 'https://raw.githubusercontent.com/revisit-studies/study/dev/src/parser/StudyConfigSchema.json',
studyMetadata: {
title: `${libraryName} Example Study`,
version: '1.0.0',
authors: ['The reVISit Team'],
date: new Date().toISOString().split('T')[0],
description: `Example study using the ${libraryName} library.`,
organizations: ['University of Utah', 'WPI'],
},
uiConfig: {
contactEmail: 'contact@revisit.dev',
logoPath: 'revisitAssets/revisitLogoSquare.svg',
withProgressBar: true,
withSidebar: false,
},
importedLibraries: [libraryName],
components: {
introduction: {
type: 'markdown',
path: `library-${libraryName}/assets/${libraryName}.md`,
response: [],
},
},
sequence: {
order: 'fixed',
components: [
'introduction',
],
},
});
const generateLibraryExamples = (base, generateDocsFn = generateLibraryDocs) => {
const librariesPath = path.join(base, 'public', 'libraries');
const publicPath = path.join(base, 'public');
// Process each library
const libraries = getLibraries(librariesPath);
libraries.forEach((library) => {
const exampleFolderName = `library-${library}`;
const examplePath = path.join(publicPath, exampleFolderName);
// Check if example folder already exists
if (!fs.existsSync(examplePath)) {
// Create the example folder
fs.mkdirSync(examplePath);
// eslint-disable-next-line no-console
console.log(`Created ${exampleFolderName} directory`);
// Create assets directory
const assetsPath = path.join(examplePath, 'assets');
fs.mkdirSync(assetsPath);
// eslint-disable-next-line no-console
console.log(`Created ${exampleFolderName}/assets directory`);
// Create config.json
const configPath = path.join(examplePath, 'config.json');
const configContent = createExampleConfig(library);
fs.writeFileSync(configPath, `${JSON.stringify(configContent, null, 2)}\n`);
// eslint-disable-next-line no-console
console.log(`Created/Updated ${exampleFolderName}/config.json`);
}
});
// eslint-disable-next-line no-console
console.log('Library example generation complete');
// Generate library.md files in the same base directory so example-study assets
// are written to the requested target tree, not the caller's current working directory.
// eslint-disable-next-line no-console
console.log('Generating library documentation...');
try {
generateDocsFn(base);
} catch (error) {
console.error(`Error running libraryDocGenerator.cjs: ${error}`);
throw error;
}
};
if (require.main === module) {
generateLibraryExamples(__dirname);
}
module.exports = { createExampleConfig, getLibraries, generateLibraryExamples };