@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.
@@ -24,9 +24,32 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  ));
25
25
 
26
26
  // src/cli/index.ts
27
+ var import_commander6 = require("commander");
28
+
29
+ // src/cli/commands/init.ts
27
30
  var import_commander = require("commander");
31
+ var initCommand = new import_commander.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) => {
32
+ console.log("Initializing MASE project...");
33
+ console.log(`Project name: ${projectName || "mase-project"}`);
34
+ console.log(`Template: ${options.template}`);
35
+ console.log(`TypeScript: ${options.typescript}`);
36
+ console.log("\u2705 Project initialized successfully!");
37
+ });
28
38
 
29
- // src/dsl/Tokenizer.ts
39
+ // src/cli/commands/compile.ts
40
+ var import_commander2 = require("commander");
41
+
42
+ // src/dsl/lexer/TokenizerError.ts
43
+ var TokenizerError = class extends Error {
44
+ constructor(message, line, column) {
45
+ super(message);
46
+ this.name = "TokenizerError";
47
+ this.line = line;
48
+ this.column = column;
49
+ }
50
+ };
51
+
52
+ // src/dsl/lexer/Tokenizer.ts
30
53
  var TokenType = {
31
54
  // Keywords
32
55
  CONTRACT: "CONTRACT",
@@ -68,14 +91,6 @@ var TokenType = {
68
91
  EOF: "EOF",
69
92
  UNKNOWN: "UNKNOWN"
70
93
  };
71
- var TokenizerError = class extends Error {
72
- constructor(message, line, column) {
73
- super(message);
74
- this.name = "TokenizerError";
75
- this.line = line;
76
- this.column = column;
77
- }
78
- };
79
94
  var ContractDSLTokenizer = class {
80
95
  constructor() {
81
96
  this.source = "";
@@ -99,7 +114,7 @@ var ContractDSLTokenizer = class {
99
114
  ["web", TokenType.WEB],
100
115
  ["native", TokenType.NATIVE],
101
116
  ["canvas", TokenType.CANVAS],
102
- ["default", TokenType.DEFAULT_CTX],
117
+ // ['default', TokenType.DEFAULT_CTX], // Removed duplicate mapping
103
118
  ["hover", TokenType.HOVER],
104
119
  ["active", TokenType.ACTIVE],
105
120
  ["disabled", TokenType.DISABLED],
@@ -259,7 +274,7 @@ var ContractDSLTokenizer = class {
259
274
  }
260
275
  };
261
276
 
262
- // src/dsl/Parser.ts
277
+ // src/dsl/parser/ParserError.ts
263
278
  var ParserError = class extends Error {
264
279
  constructor(message, line, column) {
265
280
  super(message);
@@ -268,6 +283,8 @@ var ParserError = class extends Error {
268
283
  this.column = column;
269
284
  }
270
285
  };
286
+
287
+ // src/dsl/parser/Parser.ts
271
288
  var ContractDSLParser = class {
272
289
  constructor() {
273
290
  this.tokens = [];
@@ -312,7 +329,7 @@ var ContractDSLParser = class {
312
329
  parseDomain() {
313
330
  this.expect(TokenType.DOMAIN);
314
331
  this.expect(TokenType.COLON);
315
- const domain = this.expectIdentifier();
332
+ const domain = this.expectDomain();
316
333
  this.expect(TokenType.SEMICOLON);
317
334
  return domain;
318
335
  }
@@ -449,13 +466,29 @@ var ContractDSLParser = class {
449
466
  this.advance();
450
467
  return token.value;
451
468
  }
469
+ /**
470
+ * Expect domain token
471
+ * @returns Domain value
472
+ */
473
+ expectDomain() {
474
+ const token = this.peek();
475
+ 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) {
476
+ throw new ParserError(
477
+ `Expected domain, got ${token?.type || "EOF"}`,
478
+ token?.line || 0,
479
+ token?.column || 0
480
+ );
481
+ }
482
+ this.advance();
483
+ return token.value;
484
+ }
452
485
  /**
453
486
  * Expect context token
454
487
  * @returns Context value
455
488
  */
456
489
  expectContext() {
457
490
  const token = this.peek();
458
- 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) {
491
+ 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) {
459
492
  throw new ParserError(
460
493
  `Expected context, got ${token?.type || "EOF"}`,
461
494
  token?.line || 0,
@@ -495,7 +528,7 @@ var ContractDSLParser = class {
495
528
  }
496
529
  };
497
530
 
498
- // src/dsl/Validator.ts
531
+ // src/dsl/validator/ValidationError.ts
499
532
  var ValidationError = class extends Error {
500
533
  constructor(message, path) {
501
534
  super(message);
@@ -503,6 +536,8 @@ var ValidationError = class extends Error {
503
536
  this.path = path;
504
537
  }
505
538
  };
539
+
540
+ // src/dsl/validator/Validator.ts
506
541
  var ContractDSLValidator = class {
507
542
  constructor() {
508
543
  this.validDomains = /* @__PURE__ */ new Set([
@@ -785,7 +820,7 @@ var ContractDSLValidator = class {
785
820
  }
786
821
  };
787
822
 
788
- // src/dsl/Compiler.ts
823
+ // src/dsl/compiler/Compiler.ts
789
824
  var ContractDSLCompiler = class {
790
825
  /**
791
826
  * Compile AST to ComponentConstitution and StyleContractDefinition
@@ -940,7 +975,97 @@ var ContractDSLCompiler = class {
940
975
  }
941
976
  };
942
977
 
943
- // src/materializer/CSSMaterializer.ts
978
+ // src/cli/commands/compile.ts
979
+ var fs = __toESM(require("fs"));
980
+ var compileCommand = new import_commander2.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) => {
981
+ console.log(`Compiling ${contractFile}...`);
982
+ try {
983
+ const source = fs.readFileSync(contractFile, "utf-8");
984
+ const tokenizer = new ContractDSLTokenizer();
985
+ const tokens = tokenizer.tokenize(source);
986
+ const parser = new ContractDSLParser();
987
+ const ast = parser.parse(tokens);
988
+ const validator = new ContractDSLValidator();
989
+ const validationResult = validator.validate(ast);
990
+ if (!validationResult.isValid) {
991
+ console.error("\u274C Validation errors:");
992
+ validationResult.errors.forEach((error) => {
993
+ console.error(` - ${error.path}: ${error.message}`);
994
+ });
995
+ process.exit(1);
996
+ }
997
+ const compiler = new ContractDSLCompiler();
998
+ const result = compiler.compile(ast);
999
+ if (result.errors.length > 0) {
1000
+ console.error("\u274C Compilation errors:");
1001
+ result.errors.forEach((error) => {
1002
+ console.error(` - ${error}`);
1003
+ });
1004
+ process.exit(1);
1005
+ }
1006
+ let output;
1007
+ switch (options.format) {
1008
+ case "json":
1009
+ output = JSON.stringify(ast, null, 2);
1010
+ break;
1011
+ case "ast":
1012
+ output = JSON.stringify(ast, null, 2);
1013
+ break;
1014
+ case "ts":
1015
+ default:
1016
+ output = compiler.generateTypeScriptFile(ast);
1017
+ break;
1018
+ }
1019
+ if (options.output) {
1020
+ fs.writeFileSync(options.output, output, "utf-8");
1021
+ console.log(`\u2705 Compiled to ${options.output}`);
1022
+ } else {
1023
+ console.log(output);
1024
+ }
1025
+ if (options.watch) {
1026
+ console.log("\u{1F440} Watching for changes...");
1027
+ }
1028
+ } catch (error) {
1029
+ console.error("\u274C Error:", error);
1030
+ process.exit(1);
1031
+ }
1032
+ });
1033
+
1034
+ // src/cli/commands/validate.ts
1035
+ var import_commander3 = require("commander");
1036
+ var fs2 = __toESM(require("fs"));
1037
+ var validateCommand = new import_commander3.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) => {
1038
+ console.log(`Validating ${contractFile}...`);
1039
+ try {
1040
+ const source = fs2.readFileSync(contractFile, "utf-8");
1041
+ const tokenizer = new ContractDSLTokenizer();
1042
+ const tokens = tokenizer.tokenize(source);
1043
+ const parser = new ContractDSLParser();
1044
+ const ast = parser.parse(tokens);
1045
+ const validator = new ContractDSLValidator();
1046
+ const validationResult = validator.validate(ast);
1047
+ if (validationResult.isValid) {
1048
+ console.log("\u2705 Contract is valid!");
1049
+ } else {
1050
+ console.error("\u274C Validation errors:");
1051
+ validationResult.errors.forEach((error) => {
1052
+ console.error(` - ${error.path}: ${error.message}`);
1053
+ });
1054
+ process.exit(1);
1055
+ }
1056
+ if (options.watch) {
1057
+ console.log("\u{1F440} Watching for changes...");
1058
+ }
1059
+ } catch (error) {
1060
+ console.error("\u274C Error:", error);
1061
+ process.exit(1);
1062
+ }
1063
+ });
1064
+
1065
+ // src/cli/commands/generate-css.ts
1066
+ var import_commander4 = require("commander");
1067
+
1068
+ // src/materializer/targets/CSSMaterializer.ts
944
1069
  var CSSMaterializer = class {
945
1070
  constructor() {
946
1071
  this.semanticToCSS = this.buildSemanticToCSSMapping();
@@ -1102,101 +1227,12 @@ var CSSMaterializer = class {
1102
1227
  }
1103
1228
  };
1104
1229
 
1105
- // src/cli/index.ts
1106
- var fs = __toESM(require("fs"));
1107
- var program = new import_commander.Command();
1108
- program.name("mase").description("Meta-Architecture Style Engine CLI").version("1.0.0");
1109
- 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) => {
1110
- console.log("Initializing MASE project...");
1111
- console.log(`Project name: ${projectName || "mase-project"}`);
1112
- console.log(`Template: ${options.template}`);
1113
- console.log(`TypeScript: ${options.typescript}`);
1114
- console.log("\u2705 Project initialized successfully!");
1115
- });
1116
- 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) => {
1117
- console.log(`Compiling ${contractFile}...`);
1118
- try {
1119
- const source = fs.readFileSync(contractFile, "utf-8");
1120
- const tokenizer = new ContractDSLTokenizer();
1121
- const tokens = tokenizer.tokenize(source);
1122
- const parser = new ContractDSLParser();
1123
- const ast = parser.parse(tokens);
1124
- const validator = new ContractDSLValidator();
1125
- const validationResult = validator.validate(ast);
1126
- if (!validationResult.isValid) {
1127
- console.error("\u274C Validation errors:");
1128
- validationResult.errors.forEach((error) => {
1129
- console.error(` - ${error.path}: ${error.message}`);
1130
- });
1131
- process.exit(1);
1132
- }
1133
- const compiler = new ContractDSLCompiler();
1134
- const result = compiler.compile(ast);
1135
- if (result.errors.length > 0) {
1136
- console.error("\u274C Compilation errors:");
1137
- result.errors.forEach((error) => {
1138
- console.error(` - ${error}`);
1139
- });
1140
- process.exit(1);
1141
- }
1142
- let output;
1143
- switch (options.format) {
1144
- case "json":
1145
- output = JSON.stringify(ast, null, 2);
1146
- break;
1147
- case "ast":
1148
- output = JSON.stringify(ast, null, 2);
1149
- break;
1150
- case "ts":
1151
- default:
1152
- output = compiler.generateTypeScriptFile(ast);
1153
- break;
1154
- }
1155
- if (options.output) {
1156
- fs.writeFileSync(options.output, output, "utf-8");
1157
- console.log(`\u2705 Compiled to ${options.output}`);
1158
- } else {
1159
- console.log(output);
1160
- }
1161
- if (options.watch) {
1162
- console.log("\u{1F440} Watching for changes...");
1163
- }
1164
- } catch (error) {
1165
- console.error("\u274C Error:", error);
1166
- process.exit(1);
1167
- }
1168
- });
1169
- 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) => {
1170
- console.log(`Validating ${contractFile}...`);
1171
- try {
1172
- const source = fs.readFileSync(contractFile, "utf-8");
1173
- const tokenizer = new ContractDSLTokenizer();
1174
- const tokens = tokenizer.tokenize(source);
1175
- const parser = new ContractDSLParser();
1176
- const ast = parser.parse(tokens);
1177
- const validator = new ContractDSLValidator();
1178
- const validationResult = validator.validate(ast);
1179
- if (validationResult.isValid) {
1180
- console.log("\u2705 Contract is valid!");
1181
- } else {
1182
- console.error("\u274C Validation errors:");
1183
- validationResult.errors.forEach((error) => {
1184
- console.error(` - ${error.path}: ${error.message}`);
1185
- });
1186
- process.exit(1);
1187
- }
1188
- if (options.watch) {
1189
- console.log("\u{1F440} Watching for changes...");
1190
- }
1191
- } catch (error) {
1192
- console.error("\u274C Error:", error);
1193
- process.exit(1);
1194
- }
1195
- });
1196
- 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) => {
1230
+ // src/cli/commands/generate-css.ts
1231
+ var fs3 = __toESM(require("fs"));
1232
+ var generateCssCommand = new import_commander4.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) => {
1197
1233
  console.log(`Generating CSS from ${contractFile}...`);
1198
1234
  try {
1199
- const source = fs.readFileSync(contractFile, "utf-8");
1235
+ const source = fs3.readFileSync(contractFile, "utf-8");
1200
1236
  const tokenizer = new ContractDSLTokenizer();
1201
1237
  const tokens = tokenizer.tokenize(source);
1202
1238
  const parser = new ContractDSLParser();
@@ -1240,7 +1276,7 @@ program.command("generate-css").description("Generate CSS from a contract DSL fi
1240
1276
  break;
1241
1277
  }
1242
1278
  if (options.output) {
1243
- fs.writeFileSync(options.output, output, "utf-8");
1279
+ fs3.writeFileSync(options.output, output, "utf-8");
1244
1280
  console.log(`\u2705 CSS generated to ${options.output}`);
1245
1281
  } else {
1246
1282
  console.log(output);
@@ -1250,11 +1286,23 @@ program.command("generate-css").description("Generate CSS from a contract DSL fi
1250
1286
  process.exit(1);
1251
1287
  }
1252
1288
  });
1253
- 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) => {
1289
+
1290
+ // src/cli/commands/watch.ts
1291
+ var import_commander5 = require("commander");
1292
+ var watchCommand = new import_commander5.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) => {
1254
1293
  console.log(`Watching ${contractFile}...`);
1255
1294
  console.log(`Command: ${options.command}`);
1256
1295
  console.log(`Debounce: ${options.debounce}ms`);
1257
- console.log("\u{1F440} Watching for changes...");
1296
+ console.log("Watch mode started (Ctrl+C to stop)");
1258
1297
  });
1298
+
1299
+ // src/cli/index.ts
1300
+ var program = new import_commander6.Command();
1301
+ program.name("mase").description("Meta-Architecture Style Engine CLI").version("1.0.0");
1302
+ program.addCommand(initCommand);
1303
+ program.addCommand(compileCommand);
1304
+ program.addCommand(validateCommand);
1305
+ program.addCommand(generateCssCommand);
1306
+ program.addCommand(watchCommand);
1259
1307
  program.parse(process.argv);
1260
1308
  //# sourceMappingURL=index.js.map