@geek-fun/serverlessinsight 0.5.1 → 0.5.3

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.
Files changed (47) hide show
  1. package/dist/package.json +1 -1
  2. package/dist/src/commands/deploy.js +12 -6
  3. package/dist/src/commands/destroy.js +13 -8
  4. package/dist/src/commands/forceUnlock.js +60 -4
  5. package/dist/src/commands/index.js +40 -21
  6. package/dist/src/commands/local.js +5 -27
  7. package/dist/src/commands/plan.js +12 -4
  8. package/dist/src/commands/template.js +3 -3
  9. package/dist/src/commands/validate.js +4 -2
  10. package/dist/src/common/context.js +2 -1
  11. package/dist/src/common/lockManager.js +5 -3
  12. package/dist/src/common/stateBackend/cosStateBackend.js +215 -0
  13. package/dist/src/common/stateBackend/index.js +55 -0
  14. package/dist/src/common/stateBackend/localStateBackend.js +33 -0
  15. package/dist/src/common/stateBackend/ossStateBackend.js +196 -0
  16. package/dist/src/common/stateBackend/types.js +2 -0
  17. package/dist/src/common/stateManager.js +45 -18
  18. package/dist/src/lang/en.js +2 -2
  19. package/dist/src/lang/zh-CN.js +2 -2
  20. package/dist/src/parser/index.js +34 -5
  21. package/dist/src/parser/tagParser.js +4 -1
  22. package/dist/src/stack/aliyunStack/deployer.js +6 -7
  23. package/dist/src/stack/aliyunStack/destroyer.js +12 -8
  24. package/dist/src/stack/aliyunStack/fc3Resource.js +2 -2
  25. package/dist/src/stack/aliyunStack/planner.js +2 -2
  26. package/dist/src/stack/deploy.js +9 -9
  27. package/dist/src/stack/localStack/aliyunFc.js +2 -2
  28. package/dist/src/stack/rfsStack/index.js +1 -1
  29. package/dist/src/stack/scfStack/deployer.js +6 -7
  30. package/dist/src/stack/scfStack/destroyer.js +6 -7
  31. package/dist/src/stack/scfStack/planner.js +2 -2
  32. package/dist/src/types/domains/backend.js +8 -0
  33. package/dist/src/types/domains/state.js +1 -1
  34. package/dist/src/types/index.js +1 -0
  35. package/dist/src/validator/rootSchema.js +20 -3
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +1 -1
  38. package/samples/aliyun-poc-api.yml +2 -1
  39. package/samples/aliyun-poc-bucket.yml +2 -1
  40. package/samples/aliyun-poc-domain.yml +2 -1
  41. package/samples/aliyun-poc-es.yml +2 -1
  42. package/samples/aliyun-poc-fc-gpu.yml +2 -1
  43. package/samples/aliyun-poc-rds.yml +2 -1
  44. package/samples/aliyun-poc-table.yml +2 -1
  45. package/samples/huawei-poc-fc.yml +3 -1
  46. package/samples/tencent-poc-cos.yml +2 -1
  47. package/samples/tencent-poc-scf.yml +2 -1
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geek-fun/serverlessinsight",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "description": "Full life cycle cross providers serverless application management for your fast-growing business.",
5
5
  "homepage": "https://serverlessinsight.geekfun.club",
6
6
  "main": "dist/src/index.js",
@@ -3,23 +3,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.deploy = void 0;
4
4
  const stack_1 = require("../stack");
5
5
  const common_1 = require("../common");
6
+ const stateBackend_1 = require("../common/stateBackend");
6
7
  const parser_1 = require("../parser");
7
8
  const lang_1 = require("../lang");
8
- const deploy = async (stackName, options) => {
9
+ const deploy = async (options) => {
9
10
  common_1.logger.info(lang_1.lang.__('VALIDATING_YAML'));
10
11
  const iacLocation = (0, common_1.getIacLocation)(options.location);
11
12
  const rawIac = (0, parser_1.parseYaml)(iacLocation);
12
13
  common_1.logger.info(lang_1.lang.__('YAML_VALID'));
13
- await (0, common_1.setContext)({ ...options, stackName, iacProvider: rawIac.provider, stages: rawIac.stages }, true);
14
+ await (0, common_1.setContext)({
15
+ ...options,
16
+ app: rawIac.app,
17
+ service: rawIac.service,
18
+ iacProvider: rawIac.provider,
19
+ stages: rawIac.stages,
20
+ }, true);
14
21
  const context = (0, common_1.getContext)();
15
22
  const iac = (0, parser_1.revalYaml)(iacLocation, context);
16
23
  // Store IAC in context for access by all functions
17
24
  (0, common_1.setIac)(iac);
18
25
  common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK'));
19
- // Acquire lock for the deployment operation
20
- const statePath = (0, common_1.getStatePath)();
21
- await (0, common_1.withLock)(statePath, 'deploy', async () => {
22
- await (0, stack_1.deployStack)(stackName, iac);
26
+ const backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
27
+ await backend.withLock('deploy', async () => {
28
+ await (0, stack_1.deployStack)(iac, backend);
23
29
  });
24
30
  common_1.logger.info(lang_1.lang.__('STACK_DEPLOYED'));
25
31
  };
@@ -2,31 +2,36 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.destroyStack = void 0;
4
4
  const common_1 = require("../common");
5
+ const stateBackend_1 = require("../common/stateBackend");
5
6
  const parser_1 = require("../parser");
6
7
  const lang_1 = require("../lang");
7
8
  const scfStack_1 = require("../stack/scfStack");
8
9
  const aliyunStack_1 = require("../stack/aliyunStack");
9
- const destroyStack = async (stackName, options) => {
10
+ const destroyStack = async (options) => {
10
11
  const iacLocation = (0, common_1.getIacLocation)(options.location);
11
12
  const rawIac = (0, parser_1.parseYaml)(iacLocation);
12
- await (0, common_1.setContext)({ stackName, ...options, iacProvider: rawIac.provider, stages: rawIac.stages }, true);
13
+ await (0, common_1.setContext)({
14
+ ...options,
15
+ app: rawIac.app,
16
+ service: rawIac.service,
17
+ iacProvider: rawIac.provider,
18
+ stages: rawIac.stages,
19
+ }, true);
13
20
  const context = (0, common_1.getContext)();
14
21
  const iac = (0, parser_1.revalYaml)(iacLocation, context);
15
22
  // Store IAC in context for access by all functions
16
23
  (0, common_1.setIac)(iac);
17
24
  common_1.logger.info(lang_1.lang.__('DESTROYING_STACK', {
18
- stackName,
19
25
  provider: context.provider,
20
26
  region: context.region,
21
27
  }));
22
- // Acquire lock for the destroy operation
23
- const statePath = (0, common_1.getStatePath)();
24
- await (0, common_1.withLock)(statePath, 'destroy', async () => {
28
+ const backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
29
+ await backend.withLock('destroy', async () => {
25
30
  if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
26
- await (0, scfStack_1.destroyTencentStack)();
31
+ await (0, scfStack_1.destroyTencentStack)(backend);
27
32
  }
28
33
  else if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
29
- await (0, aliyunStack_1.destroyAliyunStack)();
34
+ await (0, aliyunStack_1.destroyAliyunStack)(backend);
30
35
  }
31
36
  else {
32
37
  throw new Error(`Unsupported provider: ${iac.provider.name}`);
@@ -5,8 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.forceUnlockCommand = void 0;
7
7
  const node_readline_1 = __importDefault(require("node:readline"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
8
10
  const common_1 = require("../common");
11
+ const stateBackend_1 = require("../common/stateBackend");
12
+ const constants_1 = require("../common/constants");
13
+ const lockManager_1 = require("../common/lockManager");
9
14
  const lang_1 = require("../lang");
15
+ const parser_1 = require("../parser");
10
16
  const askConfirmation = (question) => {
11
17
  const rl = node_readline_1.default.createInterface({
12
18
  input: process.stdin,
@@ -19,10 +25,60 @@ const askConfirmation = (question) => {
19
25
  });
20
26
  });
21
27
  };
22
- const forceUnlockCommand = async (lockId) => {
23
- const statePath = (0, common_1.getStatePath)();
28
+ const forceUnlockCommand = async (lockId, options = {}) => {
29
+ let backend;
30
+ if (options.location) {
31
+ const iacLocation = (0, common_1.getIacLocation)(options.location);
32
+ const rawIac = (0, parser_1.parseYaml)(iacLocation);
33
+ await (0, common_1.setContext)({
34
+ ...options,
35
+ app: rawIac.app,
36
+ service: rawIac.service,
37
+ iacProvider: rawIac.provider,
38
+ stages: rawIac.stages,
39
+ }, false);
40
+ const context = (0, common_1.getContext)();
41
+ const iac = (0, parser_1.revalYaml)(iacLocation, context);
42
+ backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
43
+ }
44
+ else {
45
+ const stateDir = node_path_1.default.join(process.cwd(), '.serverlessinsight');
46
+ let foundStatePath;
47
+ if (node_fs_1.default.existsSync(stateDir)) {
48
+ const lockFiles = node_fs_1.default.readdirSync(stateDir).filter((f) => f.endsWith(constants_1.LOCK_FILE_SUFFIX));
49
+ if (lockFiles.length > 0) {
50
+ const lockContent = node_fs_1.default.readFileSync(node_path_1.default.join(stateDir, lockFiles[0]), 'utf-8');
51
+ const lockMeta = JSON.parse(lockContent);
52
+ foundStatePath = lockMeta.path;
53
+ }
54
+ }
55
+ if (!foundStatePath) {
56
+ common_1.logger.error(lang_1.lang.__('NO_LOCK_FOUND'));
57
+ throw new Error(lang_1.lang.__('NO_LOCK_FOUND'));
58
+ }
59
+ const statePath = foundStatePath;
60
+ backend = {
61
+ readLock: async () => (0, lockManager_1.readLockFileForCommand)(statePath),
62
+ forceUnlock: async (id) => (0, lockManager_1.forceUnlock)(statePath, id),
63
+ loadState: async () => {
64
+ throw new Error('Not supported in no-location mode');
65
+ },
66
+ saveState: async () => {
67
+ throw new Error('Not supported in no-location mode');
68
+ },
69
+ acquireLock: async () => {
70
+ throw new Error('Not supported in no-location mode');
71
+ },
72
+ releaseLock: async () => {
73
+ throw new Error('Not supported in no-location mode');
74
+ },
75
+ withLock: async () => {
76
+ throw new Error('Not supported in no-location mode');
77
+ },
78
+ };
79
+ }
24
80
  // Check if lock exists
25
- const existingLock = (0, common_1.readLockFileForCommand)(statePath);
81
+ const existingLock = await backend.readLock();
26
82
  if (!existingLock) {
27
83
  common_1.logger.error(lang_1.lang.__('NO_LOCK_FOUND'));
28
84
  throw new Error(lang_1.lang.__('NO_LOCK_FOUND'));
@@ -49,7 +105,7 @@ const forceUnlockCommand = async (lockId) => {
49
105
  return;
50
106
  }
51
107
  // Force unlock
52
- const success = (0, common_1.forceUnlock)(statePath, lockId);
108
+ const success = await backend.forceUnlock(lockId);
53
109
  if (success) {
54
110
  common_1.logger.info(lang_1.lang.__('LOCK_RELEASED'));
55
111
  }
@@ -11,6 +11,7 @@ const local_1 = require("./local");
11
11
  const plan_1 = require("./plan");
12
12
  const forceUnlock_1 = require("./forceUnlock");
13
13
  const lang_1 = require("../lang");
14
+ const parser_1 = require("../parser");
14
15
  // Global error handler
15
16
  const handleCommandError = (error, commandName) => {
16
17
  // Skip logging if already logged by handlePartialFailure
@@ -58,23 +59,26 @@ program.name('si').description('CLI for ServerlessInsight').version((0, common_1
58
59
  program
59
60
  .command('show')
60
61
  .description('show string')
62
+ .option('-f, --file <path>', 'specify the yaml file')
61
63
  .action(actionWrapper('show', async (options) => {
62
- await (0, common_1.setContext)({ ...options });
64
+ const iacLocation = (0, common_1.getIacLocation)(options.file);
65
+ const rawIac = (0, parser_1.parseYaml)(iacLocation);
66
+ await (0, common_1.setContext)({ ...options, app: rawIac.app, service: rawIac.service });
63
67
  const context = (0, common_1.getContext)();
64
68
  const result = await (0, common_1.getIamInfo)(context);
65
69
  console.log(lang_1.lang.__('RESULT', { result: JSON.stringify(result) }));
66
70
  }));
67
71
  program
68
- .command('validate [stackName]')
72
+ .command('validate')
69
73
  .description('validate serverless Iac yaml')
70
74
  .option('-f, --file <path>', 'specify the yaml file')
71
75
  .option('-s, --stage <stage>', 'specify the stage')
72
- .action(actionWrapper('validate', async (stackName, { file, stage }) => {
76
+ .action(actionWrapper('validate', async ({ file, stage }) => {
73
77
  common_1.logger.debug(lang_1.lang.__('LOG_COMMAND_INFO'));
74
- await (0, validate_1.validate)(stackName, { stage, location: file });
78
+ await (0, validate_1.validate)({ stage, location: file });
75
79
  }));
76
80
  program
77
- .command('plan <stackName>')
81
+ .command('plan')
78
82
  .description('generate and show deployment plan (Tencent provider only)')
79
83
  .option('-f, --file <path>', 'specify the yaml file')
80
84
  .option('-s, --stage <stage>', 'specify the stage')
@@ -83,8 +87,8 @@ program
83
87
  .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
84
88
  .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
85
89
  .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
86
- .action(actionWrapper('plan', async (stackName, { stage, file, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
87
- await (0, plan_1.plan)(stackName, {
90
+ .action(actionWrapper('plan', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
91
+ await (0, plan_1.plan)({
88
92
  stage,
89
93
  location: file,
90
94
  region,
@@ -95,7 +99,7 @@ program
95
99
  });
96
100
  }));
97
101
  program
98
- .command('deploy <stackName>')
102
+ .command('deploy')
99
103
  .description('deploy serverless Iac yaml')
100
104
  .option('-f, --file <path>', 'specify the yaml file')
101
105
  .option('-s, --stage <stage>', 'specify the stage')
@@ -109,8 +113,8 @@ program
109
113
  previous[key] = val;
110
114
  return previous;
111
115
  }, {})
112
- .action(actionWrapper('deploy', async (stackName, { stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
113
- await (0, deploy_1.deploy)(stackName, {
116
+ .action(actionWrapper('deploy', async ({ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken, }) => {
117
+ await (0, deploy_1.deploy)({
114
118
  stage,
115
119
  parameters: parameter,
116
120
  location: file,
@@ -122,16 +126,16 @@ program
122
126
  });
123
127
  }));
124
128
  program
125
- .command('template <stackName>')
129
+ .command('template')
126
130
  .description('print platform specific infrastructure as code template')
127
131
  .option('-f, --file <path>', 'specify the yaml file')
128
132
  .option('-s, --stage <stage>', 'specify the stage')
129
133
  .option('-t, --format <type>', 'output content type (JSON or YAML)', 'JSON')
130
- .action(actionWrapper('template', async (stackName, { format, file, stage }) => {
131
- await (0, template_1.template)(stackName, { format, location: file, stage });
134
+ .action(actionWrapper('template', async ({ format, file, stage }) => {
135
+ await (0, template_1.template)({ format, location: file, stage });
132
136
  }));
133
137
  program
134
- .command('destroy <stackName>')
138
+ .command('destroy')
135
139
  .option('-f, --file <path>', 'specify the yaml file')
136
140
  .option('-s, --stage <stage>', 'specify the stage')
137
141
  .option('-r, --region <region>', 'specify the region')
@@ -140,8 +144,8 @@ program
140
144
  .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
141
145
  .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
142
146
  .description('destroy serverless stack')
143
- .action(actionWrapper('destroy', async (stackName, { file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
144
- await (0, destroy_1.destroyStack)(stackName, {
147
+ .action(actionWrapper('destroy', async ({ file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
148
+ await (0, destroy_1.destroyStack)({
145
149
  location: file,
146
150
  stage,
147
151
  region,
@@ -152,15 +156,15 @@ program
152
156
  });
153
157
  }));
154
158
  program
155
- .command('local <stackName>')
159
+ .command('local')
156
160
  .description('run Serverless application locally for debugging')
157
161
  .option('-f, --file <path>', 'specify the yaml file')
158
162
  .option('-s, --stage <stage>', 'specify the stage', 'default')
159
163
  .option('-p, --port <port>', 'specify the port', '3000')
160
164
  .option('-d, --debug', 'enable debug mode')
161
165
  .option('-w, --watch', 'enable file watch', true)
162
- .action(actionWrapper('local', async (stackName, { stage, port, debug, watch, file }) => {
163
- await (0, local_1.runLocal)(stackName, {
166
+ .action(actionWrapper('local', async ({ stage, port, debug, watch, file }) => {
167
+ await (0, local_1.runLocal)({
164
168
  stage,
165
169
  port: Number(port) || 3000,
166
170
  debug: !!debug,
@@ -171,7 +175,22 @@ program
171
175
  program
172
176
  .command('force-unlock <lockId>')
173
177
  .description('manually remove a stuck lock (use with caution)')
174
- .action(actionWrapper('force-unlock', async (lockId) => {
175
- await (0, forceUnlock_1.forceUnlockCommand)(lockId);
178
+ .option('-f, --file <path>', 'specify the yaml file (required for remote backends)')
179
+ .option('-s, --stage <stage>', 'specify the stage')
180
+ .option('-r, --region <region>', 'specify the region')
181
+ .option('-v, --provider <provider>', 'specify the provider')
182
+ .option('-k, --accessKeyId <accessKeyId>', 'specify the AccessKeyId')
183
+ .option('-x, --accessKeySecret <accessKeySecret>', 'specify the AccessKeySecret')
184
+ .option('-n, --securityToken <securityToken>', 'specify the SecurityToken')
185
+ .action(actionWrapper('force-unlock', async (lockId, { file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
186
+ await (0, forceUnlock_1.forceUnlockCommand)(lockId, {
187
+ location: file,
188
+ stage,
189
+ region,
190
+ provider,
191
+ accessKeyId,
192
+ accessKeySecret,
193
+ securityToken,
194
+ });
176
195
  }));
177
196
  program.parse();
@@ -5,43 +5,21 @@ const common_1 = require("../common");
5
5
  const localStack_1 = require("../stack/localStack");
6
6
  const parser_1 = require("../parser");
7
7
  const lang_1 = require("../lang");
8
- const runLocal = async (stackName, opts) => {
8
+ const runLocal = async (opts) => {
9
9
  const { stage, port, debug, watch, location } = opts;
10
- await (0, common_1.setContext)({ stage, location });
10
+ const iacLocation = (0, common_1.getIacLocation)(location);
11
+ const rawIac = (0, parser_1.parseYaml)(iacLocation);
12
+ await (0, common_1.setContext)({ stage, app: rawIac.app, service: rawIac.service, location });
11
13
  const ctx = (0, common_1.getContext)();
12
- const iac = (0, parser_1.revalYaml)((0, common_1.getIacLocation)(location), ctx);
14
+ const iac = (0, parser_1.revalYaml)(iacLocation, ctx);
13
15
  // Store IAC in context for access by all functions
14
16
  (0, common_1.setIac)(iac);
15
17
  common_1.logger.info(lang_1.lang.__('RUN_LOCAL_STARTING', {
16
- stackName,
17
18
  stage,
18
19
  port: String(port),
19
20
  debug: String(debug),
20
21
  watch: String(watch),
21
22
  }));
22
23
  await (0, localStack_1.startLocalStack)(iac);
23
- // if (watch) {
24
- // const cwd = process.cwd();
25
- // try {
26
- // fs.watch(cwd, { recursive: true }, (eventType, filename) => {
27
- // if (!filename) return;
28
- // const filePath = path.join(cwd, filename);
29
- // logger.info(`file change detected: ${eventType} ${filePath}`);
30
- // });
31
- // logger.info(`watching files under ${process.cwd()}`);
32
- // } catch (err) {
33
- // logger.warn(`file watch not available: ${String(err)}`);
34
- // }
35
- // }
36
- //
37
- // const shutdown = () => {
38
- // logger.info('shutting down run-local server');
39
- // server.close(() => process.exit(0));
40
- // };
41
- // process.on('SIGINT', shutdown);
42
- // process.on('SIGTERM', shutdown);
43
- //
44
- // // return server for tests if needed
45
- // return { server, port, stage, debug, watch };
46
24
  };
47
25
  exports.runLocal = runLocal;
@@ -2,27 +2,35 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.plan = void 0;
4
4
  const common_1 = require("../common");
5
+ const stateBackend_1 = require("../common/stateBackend");
5
6
  const parser_1 = require("../parser");
6
7
  const scfStack_1 = require("../stack/scfStack");
7
8
  const aliyunStack_1 = require("../stack/aliyunStack");
8
9
  const lang_1 = require("../lang");
9
- const plan = async (stackName, options) => {
10
+ const plan = async (options) => {
10
11
  common_1.logger.info(lang_1.lang.__('VALIDATING_YAML'));
11
12
  const iacLocation = (0, common_1.getIacLocation)(options.location);
12
13
  const rawIac = (0, parser_1.parseYaml)(iacLocation);
13
14
  common_1.logger.info(lang_1.lang.__('YAML_VALID'));
14
- await (0, common_1.setContext)({ ...options, stackName, iacProvider: rawIac.provider, stages: rawIac.stages }, true);
15
+ await (0, common_1.setContext)({
16
+ ...options,
17
+ app: rawIac.app,
18
+ service: rawIac.service,
19
+ iacProvider: rawIac.provider,
20
+ stages: rawIac.stages,
21
+ }, true);
15
22
  const context = (0, common_1.getContext)();
16
23
  const iac = (0, parser_1.revalYaml)(iacLocation, context);
17
24
  // Store IAC in context for access by all functions
18
25
  (0, common_1.setIac)(iac);
19
26
  common_1.logger.info(lang_1.lang.__('GENERATING_PLAN_FOR_SCF'));
27
+ const backend = (0, stateBackend_1.createStateBackend)(iac.backend, context);
20
28
  let planResult;
21
29
  if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
22
- planResult = await (0, scfStack_1.generateTencentPlan)(iac);
30
+ planResult = await (0, scfStack_1.generateTencentPlan)(iac, backend);
23
31
  }
24
32
  else if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
25
- planResult = await (0, aliyunStack_1.generateAliyunPlan)(iac);
33
+ planResult = await (0, aliyunStack_1.generateAliyunPlan)(iac, backend);
26
34
  }
27
35
  else {
28
36
  common_1.logger.error(lang_1.lang.__('PLAN_COMMAND_NOT_SUPPORTED'));
@@ -9,12 +9,12 @@ const yaml_1 = __importDefault(require("yaml"));
9
9
  const deploy_1 = require("../stack/deploy");
10
10
  const common_1 = require("../common");
11
11
  const parser_1 = require("../parser");
12
- const template = async (stackName, options) => {
12
+ const template = async (options) => {
13
13
  const iac = (0, parser_1.parseYaml)((0, common_1.getIacLocation)(options.location));
14
14
  const credentials = (0, common_1.getCredentials)(undefined, iac.provider.name);
15
15
  const shouldFetchIamInfo = (0, common_1.hasCredentials)(credentials);
16
- await (0, common_1.setContext)({ ...options, stackName, provider: iac.provider.name }, shouldFetchIamInfo);
17
- const { template } = (0, deploy_1.generateStackTemplate)(stackName, iac);
16
+ await (0, common_1.setContext)({ stage: options.stage, app: iac.app, service: iac.service, provider: iac.provider.name }, shouldFetchIamInfo);
17
+ const { template } = (0, deploy_1.generateStackTemplate)(iac);
18
18
  if (typeof template === 'string') {
19
19
  common_1.logger.info(`\n${template}`);
20
20
  }
@@ -4,8 +4,10 @@ exports.validate = void 0;
4
4
  const common_1 = require("../common");
5
5
  const parser_1 = require("../parser");
6
6
  const lang_1 = require("../lang");
7
- const validate = async (stackName, options) => {
8
- await (0, common_1.setContext)({ stackName, ...options });
7
+ const validate = async (options) => {
8
+ const iacLocation = (0, common_1.getIacLocation)(options.location);
9
+ const rawIac = (0, parser_1.parseYaml)(iacLocation);
10
+ await (0, common_1.setContext)({ app: rawIac.app, service: rawIac.service, ...options });
9
11
  const context = (0, common_1.getContext)();
10
12
  (0, parser_1.parseYaml)(context.iacLocation);
11
13
  common_1.logger.info(lang_1.lang.__('YAML_VALID'));
@@ -68,7 +68,8 @@ const setContext = async (config, reaValToken = false) => {
68
68
  }, provider);
69
69
  const newContext = {
70
70
  stage: config.stage ?? 'default',
71
- stackName: config.stackName ?? '',
71
+ app: config.app,
72
+ service: config.service,
72
73
  provider,
73
74
  region,
74
75
  accessKeyId: credentials.accessKeyId,
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.readLockFileForCommand = exports.withLock = exports.forceUnlock = exports.formatLockInfo = exports.generateLockId = exports.getLockPath = exports.LockError = void 0;
6
+ exports.readLockFileForCommand = exports.withLock = exports.forceUnlock = exports.releaseLockInternal = exports.acquireLockInternal = exports.formatLockInfo = exports.generateLockId = exports.getLockPath = exports.LockError = void 0;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
9
  const node_os_1 = __importDefault(require("node:os"));
@@ -170,6 +170,7 @@ const acquireLockInternal = async (statePath, operation, options = {}) => {
170
170
  const existingLock = readLockFile(lockPath);
171
171
  throw new LockError(`Failed to acquire lock.\n${existingLock ? (0, exports.formatLockInfo)(existingLock) : ''}\nIf you are certain no other operation is running, use:\n si force-unlock ${existingLock?.id || 'unknown'}`, existingLock || undefined);
172
172
  };
173
+ exports.acquireLockInternal = acquireLockInternal;
173
174
  const releaseLockInternal = (statePath, lockId) => {
174
175
  const lockPath = (0, exports.getLockPath)(statePath);
175
176
  const existingLock = readLockFile(lockPath);
@@ -178,6 +179,7 @@ const releaseLockInternal = (statePath, lockId) => {
178
179
  removeLockFile(lockPath);
179
180
  }
180
181
  };
182
+ exports.releaseLockInternal = releaseLockInternal;
181
183
  const forceUnlock = (statePath, lockId) => {
182
184
  const lockPath = (0, exports.getLockPath)(statePath);
183
185
  const existingLock = readLockFile(lockPath);
@@ -194,12 +196,12 @@ exports.forceUnlock = forceUnlock;
194
196
  const withLock = async (statePath, operation, fn, options) => {
195
197
  let lock = null;
196
198
  try {
197
- lock = await acquireLockInternal(statePath, operation, options);
199
+ lock = await (0, exports.acquireLockInternal)(statePath, operation, options);
198
200
  return await fn();
199
201
  }
200
202
  finally {
201
203
  if (lock) {
202
- releaseLockInternal(statePath, lock.id);
204
+ (0, exports.releaseLockInternal)(statePath, lock.id);
203
205
  }
204
206
  }
205
207
  };