@yannosay/sinth 1.11.6 → 1.12.0
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/bin/sinth.js +1 -4
- package/dist/browser/compile.js +62 -0
- package/dist/cli.js +469 -0
- package/dist/core/builtins.js +117 -0
- package/dist/core/cli-compiler.js +553 -0
- package/dist/core/compiler.js +1344 -0
- package/dist/core/expr.js +122 -0
- package/dist/core/head-builder.js +130 -0
- package/dist/core/lexer.js +414 -0
- package/dist/core/parser.js +1672 -0
- package/dist/core/runtime/custom-element.js +81 -0
- package/dist/core/runtime/functions.js +99 -0
- package/{src/core/runtime/helpers.ts → dist/core/runtime/helpers.js} +24 -34
- package/{src/core/runtime/render.ts → dist/core/runtime/render.js} +48 -63
- package/dist/core/style-processor.js +318 -0
- package/dist/core/types.js +93 -0
- package/dist/resolver.js +175 -0
- package/dist/server.js +168 -0
- package/dist/update-check.js +101 -0
- package/dist/utils.js +73 -0
- package/package.json +12 -8
- package/src/browser/compile.ts +0 -72
- package/src/cli.ts +0 -339
- package/src/core/builtins.ts +0 -117
- package/src/core/cli-compiler.ts +0 -514
- package/src/core/compiler.ts +0 -1351
- package/src/core/expr.ts +0 -113
- package/src/core/head-builder.ts +0 -86
- package/src/core/lexer.ts +0 -276
- package/src/core/parser.ts +0 -1533
- package/src/core/runtime/custom-element.ts +0 -84
- package/src/core/runtime/functions.ts +0 -87
- package/src/core/style-processor.ts +0 -299
- package/src/core/types.ts +0 -197
- package/src/resolver.ts +0 -150
- package/src/server.ts +0 -129
- package/src/utils.ts +0 -77
- package/tsconfig.json +0 -27
package/bin/sinth.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const tsSource = path.join(__dirname, '..', 'src', 'cli.ts');
|
|
4
|
-
require('ts-node').register({ project: path.join(__dirname, '..', 'tsconfig.json') });
|
|
5
|
-
require(path.join(__dirname, '..', 'src', 'cli'));
|
|
2
|
+
require('../dist/cli.js');
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.compileSinth = compileSinth;
|
|
4
|
+
const lexer_1 = require("../core/lexer");
|
|
5
|
+
const parser_1 = require("../core/parser");
|
|
6
|
+
const compiler_1 = require("../core/compiler");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
const style_processor_1 = require("../core/style-processor");
|
|
9
|
+
function compileSinth(source) {
|
|
10
|
+
const tokens = new lexer_1.Lexer(source, "<script>").tokenize();
|
|
11
|
+
const parser = new parser_1.Parser(tokens, "<script>");
|
|
12
|
+
const file = parser.parse();
|
|
13
|
+
if (!file.isPage)
|
|
14
|
+
return null;
|
|
15
|
+
const hash = (0, utils_1.fnv1a)("<script>" + Math.random().toString(36));
|
|
16
|
+
const instanceId = "s" + Math.random().toString(36).slice(2, 8);
|
|
17
|
+
const ctx = {
|
|
18
|
+
allDefs: new Map(),
|
|
19
|
+
functionDefs: file.functions,
|
|
20
|
+
customEls: new Map(),
|
|
21
|
+
cssLinks: [],
|
|
22
|
+
jsLinks: [],
|
|
23
|
+
scopeHash: hash,
|
|
24
|
+
pageFile: "<script>",
|
|
25
|
+
extraCSS: [],
|
|
26
|
+
mixedBlocks: [],
|
|
27
|
+
mixedCounter: 0,
|
|
28
|
+
logicBlocks: [],
|
|
29
|
+
ifIdCounter: 0,
|
|
30
|
+
exprRegistry: [],
|
|
31
|
+
exprMap: new Map(),
|
|
32
|
+
varDecls: file.varDecls,
|
|
33
|
+
actionButtons: [],
|
|
34
|
+
diffingEnabled: false,
|
|
35
|
+
declaredVars: new Set(file.varDecls.map(v => v.name)),
|
|
36
|
+
namespace: instanceId,
|
|
37
|
+
};
|
|
38
|
+
const bodyHTML = file.uses.map(u => (0, compiler_1.renderCompUse)(u, ctx, new Map(), 0)).join("\n");
|
|
39
|
+
const pageCSS = file.styles.map(s => (0, style_processor_1.processStyleBlock)(s, hash, new Map())).join("\n");
|
|
40
|
+
const assignedVars = new Set();
|
|
41
|
+
for (const v of file.varDecls) {
|
|
42
|
+
if (v.value)
|
|
43
|
+
assignedVars.add(v.name);
|
|
44
|
+
}
|
|
45
|
+
const runtime = (0, compiler_1.buildRuntime)({
|
|
46
|
+
varDecls: file.varDecls,
|
|
47
|
+
bodyHTML,
|
|
48
|
+
logicBlocks: ctx.logicBlocks,
|
|
49
|
+
mixedBlocks: ctx.mixedBlocks,
|
|
50
|
+
assignedVars,
|
|
51
|
+
exprRegistry: ctx.exprRegistry,
|
|
52
|
+
sharedRuntime: false,
|
|
53
|
+
functionsJS: "",
|
|
54
|
+
namespace: instanceId,
|
|
55
|
+
});
|
|
56
|
+
const js = typeof runtime === 'string' ? runtime : runtime.page;
|
|
57
|
+
const scopedJs = js;
|
|
58
|
+
return {
|
|
59
|
+
html: `<div data-s="${hash}">${bodyHTML}</div><style>${pageCSS}</style>`,
|
|
60
|
+
js: scopedJs,
|
|
61
|
+
};
|
|
62
|
+
}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const types_1 = require("./core/types");
|
|
39
|
+
const cli_compiler_1 = require("./core/cli-compiler");
|
|
40
|
+
const server_1 = require("./server");
|
|
41
|
+
const readline = __importStar(require("readline"));
|
|
42
|
+
const update_check_1 = require("./update-check");
|
|
43
|
+
function loadConfig(root) {
|
|
44
|
+
const cfgPath = path.join(root, "sinth.config.json");
|
|
45
|
+
if (fs.existsSync(cfgPath)) {
|
|
46
|
+
try {
|
|
47
|
+
return JSON.parse(fs.readFileSync(cfgPath, "utf-8"));
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
types_1.SinthWarning.emit("Could not parse sinth.config.json");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
async function main() {
|
|
56
|
+
const [, , command, ...args] = process.argv;
|
|
57
|
+
const cwd = process.cwd();
|
|
58
|
+
const cfg = loadConfig(cwd);
|
|
59
|
+
const outDirIdx = args.indexOf("--out");
|
|
60
|
+
const outDir = outDirIdx !== -1 ? args[outDirIdx + 1] : cfg.outDir ?? path.join(cwd, "dist");
|
|
61
|
+
const portIdx = args.indexOf("--port");
|
|
62
|
+
const port = portIdx !== -1 ? parseInt(args[portIdx + 1], 10) : cfg.port ?? 3000;
|
|
63
|
+
const minify = args.includes("--prod") || Boolean(cfg.minify);
|
|
64
|
+
const sharedRuntime = args.includes("--shared-runtime") || Boolean(cfg.sharedRuntime);
|
|
65
|
+
const libraryPaths = cfg.libraryPaths ?? [path.join(cwd, "libraries")];
|
|
66
|
+
const flagValues = new Set();
|
|
67
|
+
if (outDirIdx !== -1)
|
|
68
|
+
flagValues.add(args[outDirIdx + 1]);
|
|
69
|
+
if (portIdx !== -1)
|
|
70
|
+
flagValues.add(args[portIdx + 1]);
|
|
71
|
+
const cleanArgs = args.filter(a => !a.startsWith("--") && !flagValues.has(a));
|
|
72
|
+
const opts = { projectRoot: cwd, outDir, libraryPaths, minify, checkOnly: false, sharedRuntime };
|
|
73
|
+
switch (command) {
|
|
74
|
+
case "build": {
|
|
75
|
+
const nonSinth = cleanArgs.filter(a => !a.endsWith(".sinth"));
|
|
76
|
+
const buildStart = Date.now();
|
|
77
|
+
if (nonSinth.length > 0)
|
|
78
|
+
process.stdout.write(`\x1b[33mSkipping non-.sinth files:\x1b[0m ${nonSinth.join(", ")}\n`);
|
|
79
|
+
const fileArgs = cleanArgs.filter(a => a.endsWith(".sinth"));
|
|
80
|
+
const pages = fileArgs.length > 0
|
|
81
|
+
? fileArgs.map(f => path.resolve(cwd, f)).filter(f => fs.existsSync(f))
|
|
82
|
+
: (0, cli_compiler_1.findSinthPages)(cwd, outDir);
|
|
83
|
+
if (pages.length === 0) {
|
|
84
|
+
process.stdout.write("No .sinth files found.\n");
|
|
85
|
+
process.exit(0);
|
|
86
|
+
}
|
|
87
|
+
let hadError = false, built = 0;
|
|
88
|
+
const sharedRuntimes = [];
|
|
89
|
+
for (const p of pages) {
|
|
90
|
+
try {
|
|
91
|
+
const result = (0, cli_compiler_1.compileFile)(p, opts);
|
|
92
|
+
if (!result)
|
|
93
|
+
continue;
|
|
94
|
+
const html = result.html;
|
|
95
|
+
if (result.shared) {
|
|
96
|
+
sharedRuntimes.push(result.shared);
|
|
97
|
+
}
|
|
98
|
+
const rel = path.relative(cwd, p).replace(/\.sinth$/, ".html");
|
|
99
|
+
const out = path.join(outDir, rel);
|
|
100
|
+
fs.mkdirSync(path.dirname(out), { recursive: true });
|
|
101
|
+
fs.writeFileSync(out, html);
|
|
102
|
+
process.stdout.write(` \x1b[32m✓\x1b[0m ${rel}\n`);
|
|
103
|
+
built++;
|
|
104
|
+
}
|
|
105
|
+
catch (e) {
|
|
106
|
+
process.stderr.write(` \x1b[31m✗\x1b[0m ${path.relative(cwd, p)}\n${e.message}\n`);
|
|
107
|
+
hadError = true;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (sharedRuntimes.length > 0) {
|
|
111
|
+
const combined = sharedRuntimes.join("\n");
|
|
112
|
+
fs.writeFileSync(path.join(outDir, "sinth-runtime.js"), combined);
|
|
113
|
+
process.stdout.write(` \x1b[32m✓\x1b[0m sinth-runtime.js (shared)\n`);
|
|
114
|
+
}
|
|
115
|
+
const assetsIn = path.join(cwd, "assets"), assetsOut = path.join(outDir, "assets");
|
|
116
|
+
if (fs.existsSync(assetsIn)) {
|
|
117
|
+
(0, cli_compiler_1.copyDir)(assetsIn, assetsOut);
|
|
118
|
+
process.stdout.write(` \x1b[32m✓\x1b[0m assets/ → ${path.relative(cwd, assetsOut)}/\n`);
|
|
119
|
+
}
|
|
120
|
+
const libIn = path.join(cwd, "libraries"), libOut = path.join(outDir, "libraries");
|
|
121
|
+
if (fs.existsSync(libIn)) {
|
|
122
|
+
(0, cli_compiler_1.copyDir)(libIn, libOut);
|
|
123
|
+
const libFiles = fs.readdirSync(libOut, { recursive: true });
|
|
124
|
+
for (const f of libFiles) {
|
|
125
|
+
if (f.endsWith(".sinth") || f.endsWith(".html")) {
|
|
126
|
+
try {
|
|
127
|
+
fs.unlinkSync(path.join(libOut, f));
|
|
128
|
+
}
|
|
129
|
+
catch { }
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
process.stdout.write(` \x1b[32m✓\x1b[0m libraries/ → ${path.relative(cwd, libOut)}/\n`);
|
|
133
|
+
}
|
|
134
|
+
const buildTime = ((Date.now() - buildStart) / 1000).toFixed(2);
|
|
135
|
+
process.stdout.write(`\n\x1b[1mBuilt ${built} page(s)\x1b[0m${hadError ? " with errors" : ""} \x1b[2min ${buildTime}s\x1b[0m\n`);
|
|
136
|
+
process.exit(hadError ? 1 : 0);
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
case "dev": {
|
|
140
|
+
const fileArgs = cleanArgs.filter(a => a.endsWith(".sinth"));
|
|
141
|
+
const files = fileArgs.length > 0
|
|
142
|
+
? fileArgs.map(f => path.resolve(cwd, f)).filter(f => fs.existsSync(f))
|
|
143
|
+
: undefined;
|
|
144
|
+
await (0, server_1.startDevServer)({ ...opts, port, files });
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case "check": {
|
|
148
|
+
opts.checkOnly = true;
|
|
149
|
+
const pages = (0, cli_compiler_1.findSinthPages)(cwd, outDir);
|
|
150
|
+
let hadError = false;
|
|
151
|
+
for (const p of pages) {
|
|
152
|
+
try {
|
|
153
|
+
(0, cli_compiler_1.compileFile)(p, opts);
|
|
154
|
+
process.stdout.write(` \x1b[32m✓\x1b[0m ${path.relative(cwd, p)}\n`);
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
process.stderr.write(` \x1b[31m✗\x1b[0m ${path.relative(cwd, p)}\n${e.message}\n`);
|
|
158
|
+
hadError = true;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
process.exit(hadError ? 1 : 0);
|
|
162
|
+
}
|
|
163
|
+
case "version":
|
|
164
|
+
case "--version":
|
|
165
|
+
case "-v": {
|
|
166
|
+
const pkgPath = path.join(__dirname, "..", "package.json");
|
|
167
|
+
if (fs.existsSync(pkgPath)) {
|
|
168
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
169
|
+
process.stdout.write(`Sinth Compiler v${pkg.version}\n`);
|
|
170
|
+
(0, update_check_1.checkForUpdate)(pkg.version); // fire & forget
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
process.stdout.write("Sinth Compiler v1.0.0\n");
|
|
174
|
+
}
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
case "init": {
|
|
178
|
+
await interactiveInit(cwd);
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
default: {
|
|
182
|
+
let version = "1.0.0";
|
|
183
|
+
const paths = [
|
|
184
|
+
path.resolve(__dirname, "..", "package.json"),
|
|
185
|
+
path.resolve(__dirname, "package.json"),
|
|
186
|
+
path.resolve(process.cwd(), "package.json"),
|
|
187
|
+
path.resolve(process.cwd(), "..", "package.json"),
|
|
188
|
+
];
|
|
189
|
+
for (const p of paths) {
|
|
190
|
+
if (fs.existsSync(p)) {
|
|
191
|
+
try {
|
|
192
|
+
const pkg = JSON.parse(fs.readFileSync(p, "utf-8"));
|
|
193
|
+
version = pkg.version;
|
|
194
|
+
break;
|
|
195
|
+
}
|
|
196
|
+
catch { }
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
process.stdout.write(`
|
|
200
|
+
\x1b[1mSinth Compiler v${version}\x1b[0m
|
|
201
|
+
|
|
202
|
+
\x1b[1mCommands:\x1b[0m
|
|
203
|
+
sinth build [files] [--out ./dist] [--prod] [--shared-runtime] Compile .sinth pages
|
|
204
|
+
sinth dev [files] [--port 3000] Live-reload dev server
|
|
205
|
+
sinth check Lint without emitting
|
|
206
|
+
sinth init [name] Scaffold a new project
|
|
207
|
+
sinth version Print version
|
|
208
|
+
`);
|
|
209
|
+
break;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const PRESETS = [
|
|
214
|
+
{ value: "basic", label: "Basic", description: "Single page + component" },
|
|
215
|
+
{ value: "full", label: "Full", description: "Multi-page, components, SCSS demo" },
|
|
216
|
+
{ value: "blank", label: "Blank", description: "Folders + config only" },
|
|
217
|
+
];
|
|
218
|
+
async function interactiveInit(cwd) {
|
|
219
|
+
const rl = readline.createInterface({
|
|
220
|
+
input: process.stdin,
|
|
221
|
+
output: process.stdout,
|
|
222
|
+
terminal: true,
|
|
223
|
+
escapeCodeTimeout: 50,
|
|
224
|
+
});
|
|
225
|
+
process.stdout.write("\x1b[1m\n✨ Welcome to Sinth project setup!\n\n\x1b[0m");
|
|
226
|
+
const rawName = await question(rl, "\x1b[45m\x1b[30m Project name: \x1b[0m ", "my-sinth-project");
|
|
227
|
+
process.stdout.write("\n");
|
|
228
|
+
const projectName = rawName.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "");
|
|
229
|
+
rl.close();
|
|
230
|
+
const rl2 = readline.createInterface({
|
|
231
|
+
input: process.stdin,
|
|
232
|
+
output: process.stdout,
|
|
233
|
+
terminal: true,
|
|
234
|
+
escapeCodeTimeout: 50,
|
|
235
|
+
});
|
|
236
|
+
const preset = await select(rl2);
|
|
237
|
+
rl2.close();
|
|
238
|
+
const root = path.resolve(cwd, projectName);
|
|
239
|
+
process.stdout.write("\n");
|
|
240
|
+
const start = Date.now();
|
|
241
|
+
scaffoldByPreset(root, projectName, preset);
|
|
242
|
+
const elapsed = ((Date.now() - start) / 1000).toFixed(2);
|
|
243
|
+
process.stdout.write(`
|
|
244
|
+
\x1b[32m✓ Sinth project scaffolded at \x1b[4m${projectName}/\x1b[0m\x1b[32m in ${elapsed}s\x1b[0m
|
|
245
|
+
|
|
246
|
+
\x1b[1mNext steps:\x1b[0m
|
|
247
|
+
cd ${projectName}
|
|
248
|
+
sinth dev
|
|
249
|
+
sinth build
|
|
250
|
+
`);
|
|
251
|
+
}
|
|
252
|
+
function question(rl, prompt, defaultVal) {
|
|
253
|
+
return new Promise((resolve) => {
|
|
254
|
+
rl.question(prompt, (answer) => {
|
|
255
|
+
resolve(answer.trim() || defaultVal);
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function select(rl) {
|
|
260
|
+
return new Promise((resolve) => {
|
|
261
|
+
const items = PRESETS;
|
|
262
|
+
let selected = 1;
|
|
263
|
+
const prefix = " ";
|
|
264
|
+
const cursor = "\x1b[36m❯\x1b[0m";
|
|
265
|
+
const empty = " ";
|
|
266
|
+
function render(first = false) {
|
|
267
|
+
if (!first) {
|
|
268
|
+
process.stdout.write(`\x1b[${items.length + 1}A`);
|
|
269
|
+
}
|
|
270
|
+
process.stdout.write(`\x1b[43m\x1b[30m Select preset: \x1b[0m\n`);
|
|
271
|
+
for (let i = 0; i < items.length; i++) {
|
|
272
|
+
const pointer = i === selected ? cursor : empty;
|
|
273
|
+
const isFull = items[i].value === "full";
|
|
274
|
+
let label;
|
|
275
|
+
if (i === selected) {
|
|
276
|
+
label = isFull ? `\x1b[1m\x1b[35m${items[i].label}\x1b[0m` : `\x1b[1m${items[i].label}\x1b[0m`;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
label = items[i].label;
|
|
280
|
+
}
|
|
281
|
+
const desc = `\x1b[2m- ${items[i].description}\x1b[0m`;
|
|
282
|
+
process.stdout.write(`${prefix}${pointer} ${label} ${desc}\x1b[0K\n`);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
process.stdin.setRawMode(true);
|
|
286
|
+
process.stdin.resume();
|
|
287
|
+
process.stdin.setEncoding("utf8");
|
|
288
|
+
const onData = (key) => {
|
|
289
|
+
const str = key.toString();
|
|
290
|
+
if (str === "\u001b[A") {
|
|
291
|
+
selected = (selected - 1 + items.length) % items.length;
|
|
292
|
+
render();
|
|
293
|
+
}
|
|
294
|
+
else if (str === "\u001b[B") {
|
|
295
|
+
selected = (selected + 1) % items.length;
|
|
296
|
+
render();
|
|
297
|
+
}
|
|
298
|
+
else if (str === "\r" || str === "\n") {
|
|
299
|
+
process.stdin.setRawMode(false);
|
|
300
|
+
process.stdin.pause();
|
|
301
|
+
process.stdin.removeListener("data", onData);
|
|
302
|
+
process.stdout.write(`\x1b[${items.length - selected}A\x1b[0J`);
|
|
303
|
+
resolve(items[selected].value);
|
|
304
|
+
}
|
|
305
|
+
else if (str === "\u0003") {
|
|
306
|
+
process.stdin.setRawMode(false);
|
|
307
|
+
process.stdin.pause();
|
|
308
|
+
process.exit(0);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
process.stdin.on("data", onData);
|
|
312
|
+
render(true);
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
function scaffoldByPreset(root, name, preset) {
|
|
316
|
+
const dirs = ["pages", "components", "styles", "libraries", "assets"];
|
|
317
|
+
for (const d of dirs)
|
|
318
|
+
fs.mkdirSync(path.join(root, d), { recursive: true });
|
|
319
|
+
fs.writeFileSync(path.join(root, "sinth.config.json"), JSON.stringify({ outDir: "./dist", libraryPaths: ["./libraries"], minify: false }, null, 2));
|
|
320
|
+
fs.writeFileSync(path.join(root, ".gitignore"), "dist/\nnode_modules/\n");
|
|
321
|
+
fs.writeFileSync(path.join(root, "package.json"), JSON.stringify({
|
|
322
|
+
name: name.toLowerCase().replace(/\s+/g, "-"),
|
|
323
|
+
version: "1.0.0",
|
|
324
|
+
scripts: { build: "sinth build", dev: "sinth dev" },
|
|
325
|
+
dependencies: { "sass": "^1.70.0" },
|
|
326
|
+
}, null, 2));
|
|
327
|
+
if (preset === "blank")
|
|
328
|
+
return;
|
|
329
|
+
fs.writeFileSync(path.join(root, "styles", "reset.css"), `*, *::before, *::after { box-sizing: border-box; }\nbody { margin: 0; font-family: system-ui, sans-serif; line-height: 1.6; }\nimg { max-width: 100%; display: block; }\n`);
|
|
330
|
+
fs.writeFileSync(path.join(root, "components", "Navbar.sinth"), `-- Navbar component
|
|
331
|
+
|
|
332
|
+
component Navbar {
|
|
333
|
+
Header {
|
|
334
|
+
Nav {
|
|
335
|
+
Link(href: "/", class: "logo") { "MySite" }
|
|
336
|
+
Div(class: "nav-links") {
|
|
337
|
+
NavLink(href: "/") { "Home" }
|
|
338
|
+
NavLink(href: "/about") { "About" }
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
style {
|
|
344
|
+
header {
|
|
345
|
+
display: "flex"
|
|
346
|
+
alignItems: "center"
|
|
347
|
+
padding: "1rem 2rem"
|
|
348
|
+
backgroundColor: "#1a1a2e"
|
|
349
|
+
color: "white"
|
|
350
|
+
}
|
|
351
|
+
.logo {
|
|
352
|
+
fontSize: "1.5rem"
|
|
353
|
+
fontWeight: "700"
|
|
354
|
+
color: "white"
|
|
355
|
+
textDecoration: "none"
|
|
356
|
+
}
|
|
357
|
+
.nav-links {
|
|
358
|
+
marginLeft: "auto"
|
|
359
|
+
display: "flex"
|
|
360
|
+
gap: "1.5rem"
|
|
361
|
+
}
|
|
362
|
+
.nav-links a {
|
|
363
|
+
color: "rgba(255,255,255,0.8)"
|
|
364
|
+
textDecoration: "none"
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
`);
|
|
369
|
+
if (preset === "basic") {
|
|
370
|
+
fs.writeFileSync(path.join(root, "pages", "index.sinth"), `-- My Sinth Site
|
|
371
|
+
page
|
|
372
|
+
|
|
373
|
+
import "../components/Navbar.sinth"
|
|
374
|
+
import css "../styles/reset.css"
|
|
375
|
+
|
|
376
|
+
title = "My Site"
|
|
377
|
+
fav = "assets/favicon.ico"
|
|
378
|
+
descr = "Built with Sinth."
|
|
379
|
+
|
|
380
|
+
Navbar
|
|
381
|
+
|
|
382
|
+
Main {
|
|
383
|
+
Heading(level: 1) { "Hello, Sinth!" }
|
|
384
|
+
Paragraph { "Edit pages/index.sinth to get started." }
|
|
385
|
+
}
|
|
386
|
+
`);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
fs.writeFileSync(path.join(root, "pages", "index.sinth"), `-- My Sinth Site
|
|
390
|
+
page
|
|
391
|
+
|
|
392
|
+
import "../components/Navbar.sinth"
|
|
393
|
+
import css "../styles/reset.css"
|
|
394
|
+
|
|
395
|
+
title = "My Site"
|
|
396
|
+
fav = "assets/favicon.ico"
|
|
397
|
+
descr = "Built with Sinth v1.0.0."
|
|
398
|
+
|
|
399
|
+
var int score = 0
|
|
400
|
+
var str message = "Click to begin"
|
|
401
|
+
|
|
402
|
+
Navbar
|
|
403
|
+
|
|
404
|
+
Hero {
|
|
405
|
+
Heading(level: 1) { "Welcome to Sinth" }
|
|
406
|
+
Paragraph { "A declarative, component-based web UI language." }
|
|
407
|
+
Button(onClick: "handleClick") { "Get Started" }
|
|
408
|
+
Paragraph(id: "score-display") { message }
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
Main {
|
|
412
|
+
Section {
|
|
413
|
+
Heading(level: 2) { "Features" }
|
|
414
|
+
CardGrid {
|
|
415
|
+
-- Add Card components here
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
style {
|
|
421
|
+
section.hero {
|
|
422
|
+
padding: "4rem 2rem"
|
|
423
|
+
textAlign: "center"
|
|
424
|
+
backgroundColor: "#f0f4ff"
|
|
425
|
+
}
|
|
426
|
+
main {
|
|
427
|
+
maxWidth: "1100px"
|
|
428
|
+
margin: "0 auto"
|
|
429
|
+
padding: "2rem"
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
script {
|
|
434
|
+
function handleClick() {
|
|
435
|
+
score += 1
|
|
436
|
+
message = "Score: " + score
|
|
437
|
+
sinthRender()
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
`);
|
|
441
|
+
fs.writeFileSync(path.join(root, "components", "Card.sinth"), `-- Card component
|
|
442
|
+
|
|
443
|
+
component Card(title, color = "blue") {
|
|
444
|
+
Div(class: "card") {
|
|
445
|
+
Heading(level: 3) { "$title" }
|
|
446
|
+
Div(class: "card-body") { "$slot" }
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
style {
|
|
450
|
+
.card {
|
|
451
|
+
backgroundColor: "#f7f7f7"
|
|
452
|
+
borderRadius: "1rem"
|
|
453
|
+
padding: "1.5rem"
|
|
454
|
+
marginBottom: "1rem"
|
|
455
|
+
}
|
|
456
|
+
.card:hover {
|
|
457
|
+
boxShadow: "0 4px 16px rgba(0,0,0,0.1)"
|
|
458
|
+
}
|
|
459
|
+
.card-body {
|
|
460
|
+
marginTop: "0.75rem"
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
`);
|
|
465
|
+
}
|
|
466
|
+
main().catch(e => {
|
|
467
|
+
process.stderr.write(`\x1b[31m${e.message}\x1b[0m\n`);
|
|
468
|
+
process.exit(1);
|
|
469
|
+
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VOID_TAGS = exports.BUILTIN_MAP = void 0;
|
|
4
|
+
exports.BUILTIN_MAP = {
|
|
5
|
+
// structural
|
|
6
|
+
Main: { tag: "main" },
|
|
7
|
+
Header: { tag: "header" },
|
|
8
|
+
Footer: { tag: "footer" },
|
|
9
|
+
Nav: { tag: "nav" },
|
|
10
|
+
Section: { tag: "section" },
|
|
11
|
+
Article: { tag: "article" },
|
|
12
|
+
Aside: { tag: "aside" },
|
|
13
|
+
Div: { tag: "div" },
|
|
14
|
+
Span: { tag: "span" },
|
|
15
|
+
Hero: { tag: "section", defaultClass: "hero" },
|
|
16
|
+
Container: { tag: "div", defaultClass: "container" },
|
|
17
|
+
Grid: { tag: "div", defaultClass: "grid" },
|
|
18
|
+
Flex: { tag: "div", defaultClass: "flex" },
|
|
19
|
+
Stack: { tag: "div", defaultClass: "stack" },
|
|
20
|
+
Row: { tag: "div", defaultClass: "row" },
|
|
21
|
+
Column: { tag: "div", defaultClass: "col" },
|
|
22
|
+
CardGrid: { tag: "div", defaultClass: "card-grid" },
|
|
23
|
+
// typography
|
|
24
|
+
Heading: { tag: "h1" },
|
|
25
|
+
SubHeading: { tag: "p", defaultClass: "subheading" },
|
|
26
|
+
Paragraph: { tag: "p" },
|
|
27
|
+
Lead: { tag: "p", defaultClass: "lead" },
|
|
28
|
+
Small: { tag: "small" },
|
|
29
|
+
Strong: { tag: "strong" },
|
|
30
|
+
Em: { tag: "em" },
|
|
31
|
+
Code: { tag: "code" },
|
|
32
|
+
Pre: { tag: "pre" },
|
|
33
|
+
Blockquote: { tag: "blockquote" },
|
|
34
|
+
Mark: { tag: "mark" },
|
|
35
|
+
Label: { tag: "label" },
|
|
36
|
+
Abbr: { tag: "abbr" },
|
|
37
|
+
Del: { tag: "del" },
|
|
38
|
+
Ins: { tag: "ins" },
|
|
39
|
+
Sub: { tag: "sub" },
|
|
40
|
+
Sup: { tag: "sup" },
|
|
41
|
+
Data: { tag: "data" },
|
|
42
|
+
Time: { tag: "time" },
|
|
43
|
+
Bdi: { tag: "bdi" },
|
|
44
|
+
Bdo: { tag: "bdo" },
|
|
45
|
+
Cite: { tag: "cite" },
|
|
46
|
+
Dfn: { tag: "dfn" },
|
|
47
|
+
Kbd: { tag: "kbd" },
|
|
48
|
+
Samp: { tag: "samp" },
|
|
49
|
+
Var: { tag: "var" },
|
|
50
|
+
Address: { tag: "address" },
|
|
51
|
+
Ruby: { tag: "ruby" },
|
|
52
|
+
Rt: { tag: "rt" },
|
|
53
|
+
Rp: { tag: "rp" },
|
|
54
|
+
// interactive
|
|
55
|
+
Button: { tag: "button" },
|
|
56
|
+
Link: { tag: "a" },
|
|
57
|
+
NavLink: { tag: "a" },
|
|
58
|
+
Select: { tag: "select" },
|
|
59
|
+
Form: { tag: "form" },
|
|
60
|
+
Fieldset: { tag: "fieldset" },
|
|
61
|
+
Legend: { tag: "legend" },
|
|
62
|
+
Details: { tag: "details" },
|
|
63
|
+
Summary: { tag: "summary" },
|
|
64
|
+
Dialog: { tag: "dialog" },
|
|
65
|
+
Textarea: { tag: "textarea" },
|
|
66
|
+
Datalist: { tag: "datalist" },
|
|
67
|
+
Optgroup: { tag: "optgroup" },
|
|
68
|
+
Option: { tag: "option" },
|
|
69
|
+
Progress: { tag: "progress" },
|
|
70
|
+
Meter: { tag: "meter" },
|
|
71
|
+
Output: { tag: "output" },
|
|
72
|
+
Map: { tag: "map" },
|
|
73
|
+
// media
|
|
74
|
+
Picture: { tag: "picture" },
|
|
75
|
+
Video: { tag: "video" },
|
|
76
|
+
Audio: { tag: "audio" },
|
|
77
|
+
Figure: { tag: "figure" },
|
|
78
|
+
Figcaption: { tag: "figcaption" },
|
|
79
|
+
Canvas: { tag: "canvas" },
|
|
80
|
+
Svg: { tag: "svg" },
|
|
81
|
+
IFrame: { tag: "iframe" },
|
|
82
|
+
Object: { tag: "object" },
|
|
83
|
+
// void elements
|
|
84
|
+
Img: { tag: "img", voidEl: true },
|
|
85
|
+
Logo: { tag: "img", voidEl: true },
|
|
86
|
+
Input: { tag: "input", voidEl: true },
|
|
87
|
+
Checkbox: { tag: "input", voidEl: true },
|
|
88
|
+
Hr: { tag: "hr", voidEl: true },
|
|
89
|
+
Br: { tag: "br", voidEl: true },
|
|
90
|
+
Wbr: { tag: "wbr", voidEl: true },
|
|
91
|
+
Source: { tag: "source", voidEl: true },
|
|
92
|
+
Embed: { tag: "embed", voidEl: true },
|
|
93
|
+
Col: { tag: "col", voidEl: true },
|
|
94
|
+
Area: { tag: "area", voidEl: true },
|
|
95
|
+
// lists
|
|
96
|
+
Ul: { tag: "ul" }, Ol: { tag: "ol" }, Li: { tag: "li" },
|
|
97
|
+
Dl: { tag: "dl" }, Dt: { tag: "dt" }, Dd: { tag: "dd" },
|
|
98
|
+
// tables
|
|
99
|
+
Table: { tag: "table" },
|
|
100
|
+
Caption: { tag: "caption" },
|
|
101
|
+
Thead: { tag: "thead" },
|
|
102
|
+
Tbody: { tag: "tbody" },
|
|
103
|
+
Tfoot: { tag: "tfoot" },
|
|
104
|
+
Tr: { tag: "tr" },
|
|
105
|
+
Th: { tag: "th" },
|
|
106
|
+
Td: { tag: "td" },
|
|
107
|
+
Colgroup: { tag: "colgroup" },
|
|
108
|
+
// utility
|
|
109
|
+
Template: { tag: "template" },
|
|
110
|
+
Slot: { tag: "slot" },
|
|
111
|
+
NoScript: { tag: "noscript" },
|
|
112
|
+
RawHTML: { tag: "__RAW__" },
|
|
113
|
+
};
|
|
114
|
+
exports.VOID_TAGS = new Set([
|
|
115
|
+
"area", "base", "br", "col", "embed", "hr", "img", "input",
|
|
116
|
+
"link", "meta", "param", "source", "track", "wbr",
|
|
117
|
+
]);
|