@keshavsoft/monaco-json-studio 0.0.0-stage → 1.2.1
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/README.md +60 -2
- package/assets/css/base.css +45 -0
- package/assets/css/footer.css +27 -0
- package/assets/css/header.css +172 -0
- package/assets/css/style.css +4 -0
- package/assets/css/workspace.css +143 -0
- package/assets/data/columns.json +30 -0
- package/assets/data/data.json +26 -0
- package/assets/data/instructions.json +650 -0
- package/assets/data/studio-spec.json +525 -0
- package/assets/specs/footer.spec.json +60 -0
- package/assets/specs/header.spec.json +171 -0
- package/assets/specs/pane.spec.json +99 -0
- package/assets/templates/index.js +111 -0
- package/assets/templates/state.js +45 -0
- package/bin/index.js +100 -0
- package/package.json +50 -5
- package/src/index.js +2 -0
- package/src/v1/assembleSpec/index.js +87 -0
- package/src/v1/generateStudio/index.js +242 -0
- package/src/v1/index.js +15 -0
- package/src/v1/specToHtml/index.js +52 -0
- package/src/v2/assembleSpec/index.js +99 -0
- package/src/v2/buildHtml/index.js +161 -0
- package/src/v2/generateStudio/index.js +136 -0
- package/src/v2/index.js +18 -0
- package/src/v2/specToHtml/index.js +56 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { buildHtml } from '../buildHtml/index.js';
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
const assetsDir = path.resolve(__dirname, '..', '..', '..', 'assets');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* generateStudio (v2) - The Story of Scaffolding a Physical Monaco Studio.
|
|
12
|
+
*
|
|
13
|
+
* Narrative Flow:
|
|
14
|
+
* - Chapter 1: Prepare Clean Directory Architecture (css/, data/, js/)
|
|
15
|
+
* - Chapter 2: Compile & Emit 100% Static HTML (via buildHtml)
|
|
16
|
+
* - Chapter 3: Deploy Control-Scoped Modular CSS (base, header, workspace, footer)
|
|
17
|
+
* - Chapter 4: Deploy Sample JSON Data & JS Controller
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} inArgs
|
|
20
|
+
* @param {number} [inArgs.inPanes=2] - Number of editor panes (1, 2, or 3)
|
|
21
|
+
* @param {string} inArgs.inTargetDir - Output directory path
|
|
22
|
+
* @param {string} [inArgs.inTitle="Monaco Studio"] - Studio branding title
|
|
23
|
+
* @returns {Object} Result summary { success: true, targetDir, panes }
|
|
24
|
+
*/
|
|
25
|
+
const generateStudio = ({ inPanes = 2, inTargetDir, inTitle = "Monaco Studio" } = {}) => {
|
|
26
|
+
const localPanes = Math.max(1, Math.min(3, parseInt(inPanes, 10) || 2));
|
|
27
|
+
if (!inTargetDir) {
|
|
28
|
+
throw new Error("Missing required parameter: inTargetDir");
|
|
29
|
+
}
|
|
30
|
+
const localTargetDir = path.resolve(process.cwd(), inTargetDir);
|
|
31
|
+
const localTitle = inTitle;
|
|
32
|
+
const defaultDataFiles = ['instructions.json', 'data.json', 'columns.json'];
|
|
33
|
+
|
|
34
|
+
// -------------------------------------------------------------------------
|
|
35
|
+
// Chapter 1: Prepare Clean Directory Architecture
|
|
36
|
+
// -------------------------------------------------------------------------
|
|
37
|
+
fs.mkdirSync(path.join(localTargetDir, 'css'), { recursive: true });
|
|
38
|
+
fs.mkdirSync(path.join(localTargetDir, 'data'), { recursive: true });
|
|
39
|
+
fs.mkdirSync(path.join(localTargetDir, 'js'), { recursive: true });
|
|
40
|
+
|
|
41
|
+
// -------------------------------------------------------------------------
|
|
42
|
+
// Chapter 2: Compile & Emit 100% Static HTML
|
|
43
|
+
// -------------------------------------------------------------------------
|
|
44
|
+
const staticHtml = buildHtml({
|
|
45
|
+
inPanes: localPanes,
|
|
46
|
+
inTitle: localTitle,
|
|
47
|
+
inFiles: defaultDataFiles.slice(0, localPanes)
|
|
48
|
+
});
|
|
49
|
+
fs.writeFileSync(path.join(localTargetDir, 'index.html'), staticHtml, 'utf-8');
|
|
50
|
+
|
|
51
|
+
// -------------------------------------------------------------------------
|
|
52
|
+
// Chapter 3: Deploy Control-Scoped Modular CSS
|
|
53
|
+
// -------------------------------------------------------------------------
|
|
54
|
+
const cssSourceDir = path.join(assetsDir, 'css');
|
|
55
|
+
const cssFiles = ['base.css', 'header.css', 'workspace.css', 'footer.css'];
|
|
56
|
+
for (const f of cssFiles) {
|
|
57
|
+
const srcPath = path.join(cssSourceDir, f);
|
|
58
|
+
if (fs.existsSync(srcPath)) {
|
|
59
|
+
fs.copyFileSync(srcPath, path.join(localTargetDir, 'css', f));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// -------------------------------------------------------------------------
|
|
64
|
+
// Chapter 4: Deploy Sample JSON Data & JS Controller
|
|
65
|
+
// -------------------------------------------------------------------------
|
|
66
|
+
// 4a. Copy sample data files for the requested pane count
|
|
67
|
+
const dataSourceDir = path.join(assetsDir, 'data');
|
|
68
|
+
for (let i = 0; i < localPanes; i++) {
|
|
69
|
+
const f = defaultDataFiles[i];
|
|
70
|
+
const srcPath = path.join(dataSourceDir, f);
|
|
71
|
+
if (fs.existsSync(srcPath)) {
|
|
72
|
+
fs.copyFileSync(srcPath, path.join(localTargetDir, 'data', f));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// 4b. Deploy functional JS controller
|
|
77
|
+
const templatesDir = path.join(assetsDir, 'templates');
|
|
78
|
+
fs.copyFileSync(path.join(templatesDir, 'index.js'), path.join(localTargetDir, 'js', 'index.js'));
|
|
79
|
+
|
|
80
|
+
const stateContent = `export const $ = (id) => document.getElementById(id);
|
|
81
|
+
|
|
82
|
+
export const state = {
|
|
83
|
+
paneCount: ${localPanes},
|
|
84
|
+
editors: [],
|
|
85
|
+
fileNames: ${JSON.stringify(defaultDataFiles.slice(0, localPanes))},
|
|
86
|
+
contents: []
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export const pretty = (v) => {
|
|
90
|
+
if (typeof v === 'string') {
|
|
91
|
+
try {
|
|
92
|
+
return JSON.stringify(JSON.parse(v), null, 2);
|
|
93
|
+
} catch {
|
|
94
|
+
return v;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return JSON.stringify(v, null, 2);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export async function loadInitialData(filename) {
|
|
101
|
+
try {
|
|
102
|
+
const res = await fetch(\`./data/\${filename}\`);
|
|
103
|
+
if (!res.ok) throw new Error(\`HTTP \${res.status}\`);
|
|
104
|
+
const data = await res.json();
|
|
105
|
+
return pretty(data);
|
|
106
|
+
} catch (err) {
|
|
107
|
+
console.warn('Fallback loading', filename, err);
|
|
108
|
+
return pretty({ "status": "ready", "file": filename });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function setStatus(text) {
|
|
113
|
+
const pill = $('statusPill');
|
|
114
|
+
const textEl = $('statusText');
|
|
115
|
+
if (!pill || !textEl) return;
|
|
116
|
+
|
|
117
|
+
textEl.textContent = text;
|
|
118
|
+
pill.classList.remove('hidden');
|
|
119
|
+
|
|
120
|
+
clearTimeout(setStatus._timer);
|
|
121
|
+
setStatus._timer = setTimeout(() => {
|
|
122
|
+
pill.classList.add('hidden');
|
|
123
|
+
}, 3000);
|
|
124
|
+
}
|
|
125
|
+
`;
|
|
126
|
+
fs.writeFileSync(path.join(localTargetDir, 'js', 'state.js'), stateContent, 'utf-8');
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
success: true,
|
|
130
|
+
targetDir: localTargetDir,
|
|
131
|
+
panes: localPanes
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export { generateStudio };
|
|
136
|
+
export default generateStudio;
|
package/src/v2/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { buildHtml } from './buildHtml/index.js';
|
|
2
|
+
import { generateStudio } from './generateStudio/index.js';
|
|
3
|
+
import { specToHtml } from './specToHtml/index.js';
|
|
4
|
+
import { assembleSpec } from './assembleSpec/index.js';
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
buildHtml,
|
|
8
|
+
generateStudio,
|
|
9
|
+
specToHtml,
|
|
10
|
+
assembleSpec
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export default {
|
|
14
|
+
buildHtml,
|
|
15
|
+
generateStudio,
|
|
16
|
+
specToHtml,
|
|
17
|
+
assembleSpec
|
|
18
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* specToHtml (v2) - Compiles a KeshavSoft JSON specification object into indented, valid static HTML.
|
|
3
|
+
* Completely self-contained: zero cross-version dependencies.
|
|
4
|
+
* Follows strict parameter convention: inArgs object with 'in'-prefix and 'local'-prefixed internal variables.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object} inArgs
|
|
7
|
+
* @param {Object} inArgs.inSpec - The JSON specification node
|
|
8
|
+
* @param {number} [inArgs.inIndent=0] - Leading space indentation
|
|
9
|
+
* @returns {string} Formatted HTML string
|
|
10
|
+
*/
|
|
11
|
+
const specToHtml = ({ inSpec, inIndent = 0 } = {}) => {
|
|
12
|
+
const localSpec = inSpec;
|
|
13
|
+
const localIndent = inIndent;
|
|
14
|
+
|
|
15
|
+
if (localSpec === null || localSpec === undefined) return '';
|
|
16
|
+
if (typeof localSpec === 'string' || typeof localSpec === 'number') {
|
|
17
|
+
return ' '.repeat(localIndent) + String(localSpec);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const spaces = ' '.repeat(localIndent);
|
|
21
|
+
const tagName = localSpec.tagName || 'div';
|
|
22
|
+
|
|
23
|
+
let attrStr = '';
|
|
24
|
+
if (localSpec.attributes && typeof localSpec.attributes === 'object') {
|
|
25
|
+
for (const [k, v] of Object.entries(localSpec.attributes)) {
|
|
26
|
+
attrStr += ` ${k}="${String(v).replace(/"/g, '"')}"`;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// W3C HTML void elements
|
|
31
|
+
const voidElements = new Set(['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr']);
|
|
32
|
+
if (voidElements.has(tagName.toLowerCase())) {
|
|
33
|
+
return `${spaces}<${tagName}${attrStr}>`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Leaf text node
|
|
37
|
+
if (localSpec.textContent !== undefined && localSpec.textContent !== null && (!localSpec.children || localSpec.children.length === 0)) {
|
|
38
|
+
return `${spaces}<${tagName}${attrStr}>${localSpec.textContent}</${tagName}>`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Container children
|
|
42
|
+
if (Array.isArray(localSpec.children) && localSpec.children.length > 0) {
|
|
43
|
+
const childHtmls = localSpec.children.map(child => {
|
|
44
|
+
if (typeof child === 'string') {
|
|
45
|
+
return `${spaces} ${child}`;
|
|
46
|
+
}
|
|
47
|
+
return specToHtml({ inSpec: child, inIndent: localIndent + 4 });
|
|
48
|
+
}).join('\n');
|
|
49
|
+
return `${spaces}<${tagName}${attrStr}>\n${childHtmls}\n${spaces}</${tagName}>`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return `${spaces}<${tagName}${attrStr}></${tagName}>`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { specToHtml };
|
|
56
|
+
export default specToHtml;
|