@damarkuncoro/meta-architecture-style-engine 0.1.0 → 0.1.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.
@@ -1,9 +1,32 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/cli/index.ts
4
+ import { Command as Command6 } from "commander";
5
+
6
+ // src/cli/commands/init.ts
4
7
  import { Command } from "commander";
8
+ var initCommand = new Command("init").description("Initialize a new project with MASE").argument("[project-name]", "Project name").option("-t, --template <template>", "Template to use (default, minimal, full)", "default").option("--typescript", "Use TypeScript (default)", true).option("--javascript", "Use JavaScript").action((projectName, options) => {
9
+ console.log("Initializing MASE project...");
10
+ console.log(`Project name: ${projectName || "mase-project"}`);
11
+ console.log(`Template: ${options.template}`);
12
+ console.log(`TypeScript: ${options.typescript}`);
13
+ console.log("\u2705 Project initialized successfully!");
14
+ });
5
15
 
6
- // src/dsl/Tokenizer.ts
16
+ // src/cli/commands/compile.ts
17
+ import { Command as Command2 } from "commander";
18
+
19
+ // src/dsl/lexer/TokenizerError.ts
20
+ var TokenizerError = class extends Error {
21
+ constructor(message, line, column) {
22
+ super(message);
23
+ this.name = "TokenizerError";
24
+ this.line = line;
25
+ this.column = column;
26
+ }
27
+ };
28
+
29
+ // src/dsl/lexer/Tokenizer.ts
7
30
  var TokenType = {
8
31
  // Keywords
9
32
  CONTRACT: "CONTRACT",
@@ -45,14 +68,6 @@ var TokenType = {
45
68
  EOF: "EOF",
46
69
  UNKNOWN: "UNKNOWN"
47
70
  };
48
- var TokenizerError = class extends Error {
49
- constructor(message, line, column) {
50
- super(message);
51
- this.name = "TokenizerError";
52
- this.line = line;
53
- this.column = column;
54
- }
55
- };
56
71
  var ContractDSLTokenizer = class {
57
72
  constructor() {
58
73
  this.source = "";
@@ -76,7 +91,7 @@ var ContractDSLTokenizer = class {
76
91
  ["web", TokenType.WEB],
77
92
  ["native", TokenType.NATIVE],
78
93
  ["canvas", TokenType.CANVAS],
79
- ["default", TokenType.DEFAULT_CTX],
94
+ // ['default', TokenType.DEFAULT_CTX], // Removed duplicate mapping
80
95
  ["hover", TokenType.HOVER],
81
96
  ["active", TokenType.ACTIVE],
82
97
  ["disabled", TokenType.DISABLED],
@@ -236,7 +251,7 @@ var ContractDSLTokenizer = class {
236
251
  }
237
252
  };
238
253
 
239
- // src/dsl/Parser.ts
254
+ // src/dsl/parser/ParserError.ts
240
255
  var ParserError = class extends Error {
241
256
  constructor(message, line, column) {
242
257
  super(message);
@@ -245,6 +260,8 @@ var ParserError = class extends Error {
245
260
  this.column = column;
246
261
  }
247
262
  };
263
+
264
+ // src/dsl/parser/Parser.ts
248
265
  var ContractDSLParser = class {
249
266
  constructor() {
250
267
  this.tokens = [];
@@ -289,7 +306,7 @@ var ContractDSLParser = class {
289
306
  parseDomain() {
290
307
  this.expect(TokenType.DOMAIN);
291
308
  this.expect(TokenType.COLON);
292
- const domain = this.expectIdentifier();
309
+ const domain = this.expectDomain();
293
310
  this.expect(TokenType.SEMICOLON);
294
311
  return domain;
295
312
  }
@@ -426,13 +443,29 @@ var ContractDSLParser = class {
426
443
  this.advance();
427
444
  return token.value;
428
445
  }
446
+ /**
447
+ * Expect domain token
448
+ * @returns Domain value
449
+ */
450
+ expectDomain() {
451
+ const token = this.peek();
452
+ if (!token || token.type !== TokenType.LAYOUT && token.type !== TokenType.TYPOGRAPHY && token.type !== TokenType.COLOR && token.type !== TokenType.EFFECT && token.type !== TokenType.INTERACTION && token.type !== TokenType.IDENTIFIER) {
453
+ throw new ParserError(
454
+ `Expected domain, got ${token?.type || "EOF"}`,
455
+ token?.line || 0,
456
+ token?.column || 0
457
+ );
458
+ }
459
+ this.advance();
460
+ return token.value;
461
+ }
429
462
  /**
430
463
  * Expect context token
431
464
  * @returns Context value
432
465
  */
433
466
  expectContext() {
434
467
  const token = this.peek();
435
- if (!token || token.type !== TokenType.MOBILE && token.type !== TokenType.TABLET && token.type !== TokenType.DESKTOP && token.type !== TokenType.LIGHT && token.type !== TokenType.DARK && token.type !== TokenType.WEB && token.type !== TokenType.NATIVE && token.type !== TokenType.CANVAS && token.type !== TokenType.DEFAULT_CTX && token.type !== TokenType.HOVER && token.type !== TokenType.ACTIVE && token.type !== TokenType.DISABLED) {
468
+ if (!token || token.type !== TokenType.MOBILE && token.type !== TokenType.TABLET && token.type !== TokenType.DESKTOP && token.type !== TokenType.LIGHT && token.type !== TokenType.DARK && token.type !== TokenType.WEB && token.type !== TokenType.NATIVE && token.type !== TokenType.CANVAS && token.type !== TokenType.DEFAULT_CTX && token.type !== TokenType.DEFAULT && token.type !== TokenType.HOVER && token.type !== TokenType.ACTIVE && token.type !== TokenType.DISABLED) {
436
469
  throw new ParserError(
437
470
  `Expected context, got ${token?.type || "EOF"}`,
438
471
  token?.line || 0,
@@ -472,7 +505,7 @@ var ContractDSLParser = class {
472
505
  }
473
506
  };
474
507
 
475
- // src/dsl/Validator.ts
508
+ // src/dsl/validator/ValidationError.ts
476
509
  var ValidationError = class extends Error {
477
510
  constructor(message, path) {
478
511
  super(message);
@@ -480,6 +513,8 @@ var ValidationError = class extends Error {
480
513
  this.path = path;
481
514
  }
482
515
  };
516
+
517
+ // src/dsl/validator/Validator.ts
483
518
  var ContractDSLValidator = class {
484
519
  constructor() {
485
520
  this.validDomains = /* @__PURE__ */ new Set([
@@ -762,7 +797,7 @@ var ContractDSLValidator = class {
762
797
  }
763
798
  };
764
799
 
765
- // src/dsl/Compiler.ts
800
+ // src/dsl/compiler/Compiler.ts
766
801
  var ContractDSLCompiler = class {
767
802
  /**
768
803
  * Compile AST to ComponentConstitution and StyleContractDefinition
@@ -917,7 +952,97 @@ var ContractDSLCompiler = class {
917
952
  }
918
953
  };
919
954
 
920
- // src/materializer/CSSMaterializer.ts
955
+ // src/cli/commands/compile.ts
956
+ import * as fs from "fs";
957
+ var compileCommand = new Command2("compile").description("Compile a contract DSL file to TypeScript").argument("<contract-file>", "Contract DSL file to compile").option("-o, --output <file>", "Output file (default: stdout)").option("--format <format>", "Output format (ts, json, ast)", "ts").option("--watch", "Watch for changes", false).action((contractFile, options) => {
958
+ console.log(`Compiling ${contractFile}...`);
959
+ try {
960
+ const source = fs.readFileSync(contractFile, "utf-8");
961
+ const tokenizer = new ContractDSLTokenizer();
962
+ const tokens = tokenizer.tokenize(source);
963
+ const parser = new ContractDSLParser();
964
+ const ast = parser.parse(tokens);
965
+ const validator = new ContractDSLValidator();
966
+ const validationResult = validator.validate(ast);
967
+ if (!validationResult.isValid) {
968
+ console.error("\u274C Validation errors:");
969
+ validationResult.errors.forEach((error) => {
970
+ console.error(` - ${error.path}: ${error.message}`);
971
+ });
972
+ process.exit(1);
973
+ }
974
+ const compiler = new ContractDSLCompiler();
975
+ const result = compiler.compile(ast);
976
+ if (result.errors.length > 0) {
977
+ console.error("\u274C Compilation errors:");
978
+ result.errors.forEach((error) => {
979
+ console.error(` - ${error}`);
980
+ });
981
+ process.exit(1);
982
+ }
983
+ let output;
984
+ switch (options.format) {
985
+ case "json":
986
+ output = JSON.stringify(ast, null, 2);
987
+ break;
988
+ case "ast":
989
+ output = JSON.stringify(ast, null, 2);
990
+ break;
991
+ case "ts":
992
+ default:
993
+ output = compiler.generateTypeScriptFile(ast);
994
+ break;
995
+ }
996
+ if (options.output) {
997
+ fs.writeFileSync(options.output, output, "utf-8");
998
+ console.log(`\u2705 Compiled to ${options.output}`);
999
+ } else {
1000
+ console.log(output);
1001
+ }
1002
+ if (options.watch) {
1003
+ console.log("\u{1F440} Watching for changes...");
1004
+ }
1005
+ } catch (error) {
1006
+ console.error("\u274C Error:", error);
1007
+ process.exit(1);
1008
+ }
1009
+ });
1010
+
1011
+ // src/cli/commands/validate.ts
1012
+ import { Command as Command3 } from "commander";
1013
+ import * as fs2 from "fs";
1014
+ var validateCommand = new Command3("validate").description("Validate a contract DSL file").argument("<contract-file>", "Contract DSL file to validate").option("--strict", "Enable strict validation", false).option("--fix", "Auto-fix issues", false).option("--watch", "Watch for changes", false).action((contractFile, options) => {
1015
+ console.log(`Validating ${contractFile}...`);
1016
+ try {
1017
+ const source = fs2.readFileSync(contractFile, "utf-8");
1018
+ const tokenizer = new ContractDSLTokenizer();
1019
+ const tokens = tokenizer.tokenize(source);
1020
+ const parser = new ContractDSLParser();
1021
+ const ast = parser.parse(tokens);
1022
+ const validator = new ContractDSLValidator();
1023
+ const validationResult = validator.validate(ast);
1024
+ if (validationResult.isValid) {
1025
+ console.log("\u2705 Contract is valid!");
1026
+ } else {
1027
+ console.error("\u274C Validation errors:");
1028
+ validationResult.errors.forEach((error) => {
1029
+ console.error(` - ${error.path}: ${error.message}`);
1030
+ });
1031
+ process.exit(1);
1032
+ }
1033
+ if (options.watch) {
1034
+ console.log("\u{1F440} Watching for changes...");
1035
+ }
1036
+ } catch (error) {
1037
+ console.error("\u274C Error:", error);
1038
+ process.exit(1);
1039
+ }
1040
+ });
1041
+
1042
+ // src/cli/commands/generate-css.ts
1043
+ import { Command as Command4 } from "commander";
1044
+
1045
+ // src/materializer/targets/CSSMaterializer.ts
921
1046
  var CSSMaterializer = class {
922
1047
  constructor() {
923
1048
  this.semanticToCSS = this.buildSemanticToCSSMapping();
@@ -1079,101 +1204,12 @@ var CSSMaterializer = class {
1079
1204
  }
1080
1205
  };
1081
1206
 
1082
- // src/cli/index.ts
1083
- import * as fs from "fs";
1084
- var program = new Command();
1085
- program.name("mase").description("Meta-Architecture Style Engine CLI").version("1.0.0");
1086
- program.command("init").description("Initialize a new project with MASE").argument("[project-name]", "Project name").option("-t, --template <template>", "Template to use (default, minimal, full)", "default").option("--typescript", "Use TypeScript (default)", true).option("--javascript", "Use JavaScript").action((projectName, options) => {
1087
- console.log("Initializing MASE project...");
1088
- console.log(`Project name: ${projectName || "mase-project"}`);
1089
- console.log(`Template: ${options.template}`);
1090
- console.log(`TypeScript: ${options.typescript}`);
1091
- console.log("\u2705 Project initialized successfully!");
1092
- });
1093
- program.command("compile").description("Compile a contract DSL file to TypeScript").argument("<contract-file>", "Contract DSL file to compile").option("-o, --output <file>", "Output file (default: stdout)").option("--format <format>", "Output format (ts, json, ast)", "ts").option("--watch", "Watch for changes", false).action((contractFile, options) => {
1094
- console.log(`Compiling ${contractFile}...`);
1095
- try {
1096
- const source = fs.readFileSync(contractFile, "utf-8");
1097
- const tokenizer = new ContractDSLTokenizer();
1098
- const tokens = tokenizer.tokenize(source);
1099
- const parser = new ContractDSLParser();
1100
- const ast = parser.parse(tokens);
1101
- const validator = new ContractDSLValidator();
1102
- const validationResult = validator.validate(ast);
1103
- if (!validationResult.isValid) {
1104
- console.error("\u274C Validation errors:");
1105
- validationResult.errors.forEach((error) => {
1106
- console.error(` - ${error.path}: ${error.message}`);
1107
- });
1108
- process.exit(1);
1109
- }
1110
- const compiler = new ContractDSLCompiler();
1111
- const result = compiler.compile(ast);
1112
- if (result.errors.length > 0) {
1113
- console.error("\u274C Compilation errors:");
1114
- result.errors.forEach((error) => {
1115
- console.error(` - ${error}`);
1116
- });
1117
- process.exit(1);
1118
- }
1119
- let output;
1120
- switch (options.format) {
1121
- case "json":
1122
- output = JSON.stringify(ast, null, 2);
1123
- break;
1124
- case "ast":
1125
- output = JSON.stringify(ast, null, 2);
1126
- break;
1127
- case "ts":
1128
- default:
1129
- output = compiler.generateTypeScriptFile(ast);
1130
- break;
1131
- }
1132
- if (options.output) {
1133
- fs.writeFileSync(options.output, output, "utf-8");
1134
- console.log(`\u2705 Compiled to ${options.output}`);
1135
- } else {
1136
- console.log(output);
1137
- }
1138
- if (options.watch) {
1139
- console.log("\u{1F440} Watching for changes...");
1140
- }
1141
- } catch (error) {
1142
- console.error("\u274C Error:", error);
1143
- process.exit(1);
1144
- }
1145
- });
1146
- program.command("validate").description("Validate a contract DSL file").argument("<contract-file>", "Contract DSL file to validate").option("--strict", "Enable strict validation", false).option("--fix", "Auto-fix issues", false).option("--watch", "Watch for changes", false).action((contractFile, options) => {
1147
- console.log(`Validating ${contractFile}...`);
1148
- try {
1149
- const source = fs.readFileSync(contractFile, "utf-8");
1150
- const tokenizer = new ContractDSLTokenizer();
1151
- const tokens = tokenizer.tokenize(source);
1152
- const parser = new ContractDSLParser();
1153
- const ast = parser.parse(tokens);
1154
- const validator = new ContractDSLValidator();
1155
- const validationResult = validator.validate(ast);
1156
- if (validationResult.isValid) {
1157
- console.log("\u2705 Contract is valid!");
1158
- } else {
1159
- console.error("\u274C Validation errors:");
1160
- validationResult.errors.forEach((error) => {
1161
- console.error(` - ${error.path}: ${error.message}`);
1162
- });
1163
- process.exit(1);
1164
- }
1165
- if (options.watch) {
1166
- console.log("\u{1F440} Watching for changes...");
1167
- }
1168
- } catch (error) {
1169
- console.error("\u274C Error:", error);
1170
- process.exit(1);
1171
- }
1172
- });
1173
- program.command("generate-css").description("Generate CSS from a contract DSL file").argument("<contract-file>", "Contract DSL file to generate CSS from").option("-o, --output <file>", "Output file (default: stdout)").option("--format <format>", "Output format (class, variable, inline)", "class").option("--theme <theme>", "Theme (light, dark)", "light").option("--device <device>", "Device (mobile, tablet, desktop)", "desktop").action((contractFile, options) => {
1207
+ // src/cli/commands/generate-css.ts
1208
+ import * as fs3 from "fs";
1209
+ var generateCssCommand = new Command4("generate-css").description("Generate CSS from a contract DSL file").argument("<contract-file>", "Contract DSL file to generate CSS from").option("-o, --output <file>", "Output file (default: stdout)").option("--format <format>", "Output format (class, variable, inline)", "class").option("--theme <theme>", "Theme (light, dark)", "light").option("--device <device>", "Device (mobile, tablet, desktop)", "desktop").action((contractFile, options) => {
1174
1210
  console.log(`Generating CSS from ${contractFile}...`);
1175
1211
  try {
1176
- const source = fs.readFileSync(contractFile, "utf-8");
1212
+ const source = fs3.readFileSync(contractFile, "utf-8");
1177
1213
  const tokenizer = new ContractDSLTokenizer();
1178
1214
  const tokens = tokenizer.tokenize(source);
1179
1215
  const parser = new ContractDSLParser();
@@ -1217,7 +1253,7 @@ program.command("generate-css").description("Generate CSS from a contract DSL fi
1217
1253
  break;
1218
1254
  }
1219
1255
  if (options.output) {
1220
- fs.writeFileSync(options.output, output, "utf-8");
1256
+ fs3.writeFileSync(options.output, output, "utf-8");
1221
1257
  console.log(`\u2705 CSS generated to ${options.output}`);
1222
1258
  } else {
1223
1259
  console.log(output);
@@ -1227,11 +1263,23 @@ program.command("generate-css").description("Generate CSS from a contract DSL fi
1227
1263
  process.exit(1);
1228
1264
  }
1229
1265
  });
1230
- program.command("watch").description("Watch for changes and recompile").argument("<contract-file>", "Contract DSL file to watch").option("--command <command>", "Command to run on change", "mase compile").option("--debounce <ms>", "Debounce time in ms", "300").action((contractFile, options) => {
1266
+
1267
+ // src/cli/commands/watch.ts
1268
+ import { Command as Command5 } from "commander";
1269
+ var watchCommand = new Command5("watch").description("Watch for changes and recompile").argument("<contract-file>", "Contract DSL file to watch").option("--command <command>", "Command to run on change", "mase compile").option("--debounce <ms>", "Debounce time in ms", "300").action((contractFile, options) => {
1231
1270
  console.log(`Watching ${contractFile}...`);
1232
1271
  console.log(`Command: ${options.command}`);
1233
1272
  console.log(`Debounce: ${options.debounce}ms`);
1234
- console.log("\u{1F440} Watching for changes...");
1273
+ console.log("Watch mode started (Ctrl+C to stop)");
1235
1274
  });
1275
+
1276
+ // src/cli/index.ts
1277
+ var program = new Command6();
1278
+ program.name("mase").description("Meta-Architecture Style Engine CLI").version("1.0.0");
1279
+ program.addCommand(initCommand);
1280
+ program.addCommand(compileCommand);
1281
+ program.addCommand(validateCommand);
1282
+ program.addCommand(generateCssCommand);
1283
+ program.addCommand(watchCommand);
1236
1284
  program.parse(process.argv);
1237
1285
  //# sourceMappingURL=index.js.map