@iacmp/cli 1.1.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.
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/commands/watch.ts
31
+ var watch_exports = {};
32
+ __export(watch_exports, {
33
+ default: () => Watch
34
+ });
35
+ module.exports = __toCommonJS(watch_exports);
36
+ var import_core = require("@oclif/core");
37
+ var fs2 = __toESM(require("fs"));
38
+ var path = __toESM(require("path"));
39
+ var import_child_process = require("child_process");
40
+
41
+ // src/utils.ts
42
+ var fs = __toESM(require("fs"));
43
+ function readJsonFile(filePath) {
44
+ let content;
45
+ try {
46
+ content = fs.readFileSync(filePath, "utf-8");
47
+ } catch (e) {
48
+ throw new Error(`Falha ao ler '${filePath}': ${errMessage(e)}`);
49
+ }
50
+ try {
51
+ return JSON.parse(content);
52
+ } catch (e) {
53
+ throw new Error(`JSON inv\xE1lido em '${filePath}': ${errMessage(e)}`);
54
+ }
55
+ }
56
+ function errMessage(e) {
57
+ if (e instanceof Error) return e.message;
58
+ if (typeof e === "string") return e;
59
+ try {
60
+ return JSON.stringify(e);
61
+ } catch {
62
+ return String(e);
63
+ }
64
+ }
65
+
66
+ // src/commands/watch.ts
67
+ function isTempArtifact(name) {
68
+ if (!name) return true;
69
+ const base = path.basename(name);
70
+ return base.endsWith(".swp") || base.endsWith(".swx") || base.endsWith(".tmp") || base.endsWith("~") || base.startsWith(".#") || base.startsWith("#") || base.startsWith(".DS_Store");
71
+ }
72
+ function isStackSource(name) {
73
+ return name.endsWith(".ts") || name.endsWith(".js");
74
+ }
75
+ var Watch = class _Watch extends import_core.Command {
76
+ static description = "Monitora stacks/ e sintetiza automaticamente ao detectar mudan\xE7as";
77
+ static flags = {
78
+ provider: import_core.Flags.string({ char: "p", description: "Provider alvo (aws, azure, gcp, terraform)", default: "aws" })
79
+ };
80
+ static examples = [
81
+ "$ iacmp watch",
82
+ "$ iacmp watch --provider azure"
83
+ ];
84
+ async run() {
85
+ const { flags } = await this.parse(_Watch);
86
+ const cwd = process.cwd();
87
+ const configPath = path.join(cwd, "iacmp.json");
88
+ if (!fs2.existsSync(configPath)) {
89
+ this.error("Projeto n\xE3o inicializado. Rode: iacmp init");
90
+ }
91
+ let config;
92
+ try {
93
+ config = readJsonFile(configPath);
94
+ } catch (err) {
95
+ this.error(errMessage(err));
96
+ }
97
+ const provider = flags.provider ?? config.provider ?? "aws";
98
+ const stacksDir = path.join(cwd, "stacks");
99
+ if (!fs2.existsSync(stacksDir)) {
100
+ this.error("Diret\xF3rio stacks/ n\xE3o encontrado.");
101
+ }
102
+ this.log(`Monitorando stacks/ \u2014 pressione Ctrl+C para parar`);
103
+ let debounceTimer = null;
104
+ const runSynth = (changedFile) => {
105
+ const now = /* @__PURE__ */ new Date();
106
+ const hh = String(now.getHours()).padStart(2, "0");
107
+ const mm = String(now.getMinutes()).padStart(2, "0");
108
+ const ss = String(now.getSeconds()).padStart(2, "0");
109
+ this.log(`[${hh}:${mm}:${ss}] Mudan\xE7a detectada em ${changedFile} \u2014 sintetizando...`);
110
+ const cliBin = path.resolve(__dirname, "../../bin/run.js");
111
+ const cmd = `node "${cliBin}" synth --provider ${provider}`;
112
+ try {
113
+ (0, import_child_process.execSync)(cmd, { cwd, stdio: "pipe" });
114
+ this.log(`\u2713 Sintetizado em synth-out/`);
115
+ } catch (err) {
116
+ this.log(`\u2717 Erro ao sintetizar \u2014 veja acima`);
117
+ const output = err;
118
+ if (output.stderr) process.stderr.write(output.stderr);
119
+ if (output.stdout) process.stdout.write(output.stdout);
120
+ }
121
+ };
122
+ fs2.watch(stacksDir, { recursive: true }, (_event, filename) => {
123
+ const name = (filename ?? "").toString();
124
+ if (!name) return;
125
+ if (isTempArtifact(name)) return;
126
+ if (!isStackSource(name)) return;
127
+ if (debounceTimer) clearTimeout(debounceTimer);
128
+ debounceTimer = setTimeout(() => runSynth(name), 300);
129
+ });
130
+ await new Promise(() => {
131
+ });
132
+ }
133
+ };
package/dist/index.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ run: () => import_core.run
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+ var import_core = require("@oclif/core");
27
+ // Annotate the CommonJS export names for ESM import in node:
28
+ 0 && (module.exports = {
29
+ run
30
+ });