@payfit/iac 1.0.0-ephemeral-migration-scripts.7 → 1.0.0-ephemeral-migration-scripts.8
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/README.md +97 -4
- package/dist/executors/stack-migration/README.md +111 -11
- package/dist/executors/stack-migration/lib/constants.d.ts +0 -11
- package/dist/executors/stack-migration/lib/constants.js +1 -12
- package/dist/executors/stack-migration/lib/constants.js.map +1 -1
- package/dist/executors/stack-migration/lib/file-operations.d.ts +0 -43
- package/dist/executors/stack-migration/lib/file-operations.js +0 -88
- package/dist/executors/stack-migration/lib/file-operations.js.map +1 -1
- package/dist/executors/stack-migration/lib/git-operations.d.ts +0 -27
- package/dist/executors/stack-migration/lib/git-operations.js +2 -35
- package/dist/executors/stack-migration/lib/git-operations.js.map +1 -1
- package/dist/executors/stack-migration/lib/logger.d.ts +0 -3
- package/dist/executors/stack-migration/lib/logger.js +3 -6
- package/dist/executors/stack-migration/lib/logger.js.map +1 -1
- package/dist/executors/stack-migration/lib/migration-helper.d.ts +8 -44
- package/dist/executors/stack-migration/lib/migration-helper.js +23 -67
- package/dist/executors/stack-migration/lib/migration-helper.js.map +1 -1
- package/dist/executors/stack-migration/lib/migration-tool.d.ts +4 -15
- package/dist/executors/stack-migration/lib/migration-tool.js +77 -212
- package/dist/executors/stack-migration/lib/migration-tool.js.map +1 -1
- package/dist/executors/stack-migration/lib/path-builder.d.ts +0 -8
- package/dist/executors/stack-migration/lib/path-builder.js +2 -28
- package/dist/executors/stack-migration/lib/path-builder.js.map +1 -1
- package/dist/executors/stack-migration/lib/templates/index.d.ts +1 -0
- package/dist/executors/stack-migration/lib/templates/index.js +1 -0
- package/dist/executors/stack-migration/lib/templates/index.js.map +1 -1
- package/dist/executors/stack-migration/lib/templates/message-templates.d.ts +25 -0
- package/dist/executors/stack-migration/lib/templates/message-templates.js +107 -0
- package/dist/executors/stack-migration/lib/templates/message-templates.js.map +1 -0
- package/dist/executors/stack-migration/lib/templates/pr-templates.d.ts +0 -4
- package/dist/executors/stack-migration/lib/templates/pr-templates.js +3 -24
- package/dist/executors/stack-migration/lib/templates/pr-templates.js.map +1 -1
- package/dist/executors/stack-migration/lib/templates/procedure-template.js +5 -40
- package/dist/executors/stack-migration/lib/templates/procedure-template.js.map +1 -1
- package/dist/executors/stack-migration/lib/types.d.ts +0 -9
- package/dist/executors/stack-migration/lib/types.js +0 -3
- package/dist/executors/stack-migration/lib/types.js.map +1 -1
- package/dist/executors/stack-migration/schema.d.ts +2 -1
- package/dist/executors/stack-migration/schema.json +4 -3
- package/dist/executors/stack-migration/stack-migration.js +30 -60
- package/dist/executors/stack-migration/stack-migration.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,11 +1,104 @@
|
|
|
1
|
-
# iac
|
|
1
|
+
# @payfit/iac
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Nx plugin that provides executors for infrastructure as code operations
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
npx nx add @payfit/iac
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Stack Migration Executor
|
|
14
|
+
|
|
15
|
+
The stack migration executor automates the process of migrating Spacelift stacks from a centralized iac-deploy repository to repository-level metastacks with autodiscovery.
|
|
16
|
+
|
|
17
|
+
#### Quick Start
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Run the complete migration workflow
|
|
21
|
+
npx nx run <project>:stack-migration --command=run
|
|
22
|
+
|
|
23
|
+
# Run in dry-run mode to preview changes
|
|
24
|
+
npx nx run <project>:stack-migration --command=run --dryRun
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
#### Migration Workflow
|
|
28
|
+
|
|
29
|
+
The migration process consists of several phases:
|
|
30
|
+
|
|
31
|
+
1. **Initialization**: Clone repositories and collect configuration
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx nx run <project>:stack-migration --command=init
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. **Domain Enrollment**: Create PR to enroll repository in domain
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npx nx run <project>:stack-migration --command=enroll
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
3. **Generate Migration Files**: Create service repository PR with import configuration
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx nx run <project>:stack-migration --command=generate-tf-migration
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
4. **Cleanup**: Create PR to remove old stack configuration
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx nx run <project>:stack-migration --command=cleanup-pr
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
5. **Generate Documentation**: Create migration procedure document
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx nx run <project>:stack-migration --command=generate-procedure
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
6. **Migrate Spaces** (Manual step): Move stacks to domain space
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
npx nx run <project>:stack-migration --command=migrate-spaces
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
7. **Cleanup Migration Files**: Remove temporary migration files
|
|
68
|
+
```bash
|
|
69
|
+
npx nx run <project>:stack-migration --command=migration-cleanup
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### Configuration
|
|
73
|
+
|
|
74
|
+
Once installed, the executor should be automatically infered from your root project.
|
|
75
|
+
|
|
76
|
+
#### Available Commands
|
|
77
|
+
|
|
78
|
+
- `init` - Initialize migration by cloning repositories and collecting configuration
|
|
79
|
+
- `state` - Check current migration state
|
|
80
|
+
- `enroll` - Create domain enrollment PR
|
|
81
|
+
- `generate-tf-migration` - Generate service repository PR and state removal commands
|
|
82
|
+
- `cleanup-pr` - Create cleanup PR for iac-deploy
|
|
83
|
+
- `generate-procedure` - Generate migration procedure documentation
|
|
84
|
+
- `migrate-spaces` - Update stack spaces (manual step, run after state removal)
|
|
85
|
+
- `migration-cleanup` - Clean up migration files after completion
|
|
86
|
+
- `run` - Execute complete migration workflow (excludes migrate-spaces for safety)
|
|
87
|
+
- `help` - Display help information
|
|
88
|
+
|
|
89
|
+
#### Important Notes
|
|
90
|
+
|
|
91
|
+
- The migration state is saved in `.migration-state.json` and can be resumed from any step
|
|
92
|
+
- The `migrate-spaces` command must be run manually after executing state removal commands
|
|
93
|
+
- Follow the recommended order: enrollment → migration files → state removal → space migration → cleanup
|
|
94
|
+
- Always review PRs before merging them
|
|
95
|
+
|
|
96
|
+
---
|
|
4
97
|
|
|
5
98
|
## Building
|
|
6
99
|
|
|
7
|
-
Run `nx build iac` to build the library.
|
|
100
|
+
Run `npx nx build iac` to build the library.
|
|
8
101
|
|
|
9
102
|
## Running unit tests
|
|
10
103
|
|
|
11
|
-
Run `nx test iac` to execute the unit tests via [Vitest](https://vitest.dev/).
|
|
104
|
+
Run `npx nx test iac` to execute the unit tests via [Vitest](https://vitest.dev/).
|
|
@@ -1,25 +1,125 @@
|
|
|
1
1
|
# Stack Migration Executor
|
|
2
2
|
|
|
3
|
-
NX executor for migrating Spacelift stacks from centralized iac-deploy
|
|
3
|
+
NX executor for migrating Spacelift stacks from centralized iac-deploy to repository-level metastacks.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This tool automates the migration of Spacelift stacks to the new metastack architecture. It creates necessary PRs, generates import files, and manages state removal.
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
### Complete Workflow
|
|
4
12
|
|
|
5
13
|
```bash
|
|
6
|
-
#
|
|
14
|
+
# Run the full migration (recommended for first-time users)
|
|
15
|
+
nx run <project>:stack-migration --command=run
|
|
16
|
+
|
|
17
|
+
# Run in dry-run mode to preview changes
|
|
18
|
+
nx run <project>:stack-migration --command=run --dryRun
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Individual Steps
|
|
22
|
+
|
|
23
|
+
You can also run each step independently. This is useful if you need to pause the migration or re-run specific steps.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
# 1. Initialize migration (clone repos, collect info)
|
|
7
27
|
nx run <project>:stack-migration --command=init
|
|
8
28
|
|
|
9
|
-
# Check state
|
|
29
|
+
# 2. Check migration state
|
|
10
30
|
nx run <project>:stack-migration --command=state
|
|
11
31
|
|
|
12
|
-
#
|
|
32
|
+
# 3. Create domain enrollment PR
|
|
13
33
|
nx run <project>:stack-migration --command=enroll
|
|
14
|
-
nx run <project>:stack-migration --command=generate-import
|
|
15
|
-
nx run <project>:stack-migration --command=migrate-spaces
|
|
16
34
|
|
|
17
|
-
#
|
|
18
|
-
nx run <project>:stack-migration --command=
|
|
35
|
+
# 4. Create service repository PR and generate state removal commands
|
|
36
|
+
nx run <project>:stack-migration --command=generate-tf-migration
|
|
19
37
|
|
|
20
|
-
#
|
|
21
|
-
nx run <project>:stack-migration --command=
|
|
38
|
+
# 5. Create cleanup PR (iac-deploy)
|
|
39
|
+
nx run <project>:stack-migration --command=cleanup-pr
|
|
22
40
|
|
|
23
|
-
#
|
|
41
|
+
# 6. Generate migration procedure documentation
|
|
42
|
+
nx run <project>:stack-migration --command=generate-procedure
|
|
43
|
+
|
|
44
|
+
# 7. Update stack spaces (move to domain space) - RUN MANUALLY ONLY
|
|
45
|
+
nx run <project>:stack-migration --command=migrate-spaces
|
|
46
|
+
|
|
47
|
+
# 8. Clean up migration files
|
|
24
48
|
nx run <project>:stack-migration --command=migration-cleanup
|
|
25
49
|
```
|
|
50
|
+
|
|
51
|
+
## Migration Flow and Dependencies
|
|
52
|
+
|
|
53
|
+
The migration follows a specific sequence. Here's the required flow:
|
|
54
|
+
|
|
55
|
+
### Phase 1: Setup and Configuration
|
|
56
|
+
|
|
57
|
+
1. **init** - Clones required repos, validates auth, collects service info
|
|
58
|
+
- Creates `.migration-state.json` to track progress
|
|
59
|
+
- Clones: `domain-enrollment`, `iac-deploy`
|
|
60
|
+
- Loads stack configuration
|
|
61
|
+
|
|
62
|
+
### Phase 2: Safety and Enrollment
|
|
63
|
+
|
|
64
|
+
2. **enroll** - Creates domain enrollment PR
|
|
65
|
+
- Adds repository to domain's `spacelift.yaml`
|
|
66
|
+
- PR must be merged before continuing
|
|
67
|
+
- Deploys the metastack for your repository
|
|
68
|
+
|
|
69
|
+
3. **generate-tf-migration** - Creates service repository PR and state removal script
|
|
70
|
+
- Copies `spacelift.yaml` from iac-deploy
|
|
71
|
+
- Generates `.metastack/import.tf` with import blocks
|
|
72
|
+
- Generates `METASTACK_STATE_REMOVAL_COMMANDS.sh`
|
|
73
|
+
- DO NOT MERGE THIS PR YET
|
|
74
|
+
|
|
75
|
+
### Phase 3: Cleanup and State Management
|
|
76
|
+
|
|
77
|
+
4. **cleanup-pr** - Creates cleanup PR
|
|
78
|
+
- iac-deploy: Removes stack configuration file
|
|
79
|
+
- DO NOT MERGE THIS PR YET
|
|
80
|
+
|
|
81
|
+
5. **generate-procedure** - Generates migration documentation
|
|
82
|
+
- Creates `METASTACK_MIGRATION_PROCEDURE.md`
|
|
83
|
+
- Provides complete overview of migration steps
|
|
84
|
+
|
|
85
|
+
6. **migrate-spaces** - Updates stack spaces (MANUAL STEP)
|
|
86
|
+
- Moves stacks from old space to `domain-{domain}` space
|
|
87
|
+
- **IMPORTANT**: Run MANUALLY after state removal commands
|
|
88
|
+
- Run AFTER state removal, BEFORE merging cleanup PRs
|
|
89
|
+
- NOT included in full `run` workflow for safety
|
|
90
|
+
|
|
91
|
+
### Phase 4: Completion
|
|
92
|
+
|
|
93
|
+
7. After all steps complete:
|
|
94
|
+
- Merge cleanup PR (iac-deploy)
|
|
95
|
+
- Merge service repository PR
|
|
96
|
+
- Run **migration-cleanup** to remove temporary files
|
|
97
|
+
|
|
98
|
+
## Important Notes
|
|
99
|
+
|
|
100
|
+
### State Management
|
|
101
|
+
|
|
102
|
+
- Migration state is saved in `.migration-state.json`
|
|
103
|
+
- You can resume migration from any step
|
|
104
|
+
- Configuration (stacks) is preserved in state
|
|
105
|
+
- You can run steps in any order after `init`, but follow the recommended flow
|
|
106
|
+
|
|
107
|
+
### Order Requirements
|
|
108
|
+
|
|
109
|
+
While steps can be run independently, they should generally follow this sequence:
|
|
110
|
+
|
|
111
|
+
1. `init` must be run first (loads configuration)
|
|
112
|
+
2. `enroll` should be merged before running `generate-tf-migration`
|
|
113
|
+
3. `generate-tf-migration` creates the service repo PR and state removal script
|
|
114
|
+
4. Run state removal commands from `METASTACK_STATE_REMOVAL_COMMANDS.sh` before merging cleanup PR
|
|
115
|
+
5. Run `migrate-spaces` MANUALLY after state removal but before merging cleanup PR
|
|
116
|
+
6. Merge cleanup PR before merging service repository PR
|
|
117
|
+
7. The full `run` command skips `migrate-spaces` for safety - you must run it manually
|
|
118
|
+
|
|
119
|
+
### Files Generated
|
|
120
|
+
|
|
121
|
+
- `.migration-state.json` - Migration state and progress
|
|
122
|
+
- `METASTACK_MIGRATION_PROCEDURE.md` - Complete migration procedure
|
|
123
|
+
- `METASTACK_STATE_REMOVAL_COMMANDS.sh` - Commands to remove Terraform state
|
|
124
|
+
- `.metastack/import.tf` - Terraform import blocks
|
|
125
|
+
- `spacelift.yaml` - Stack configuration
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Constants for stack migration
|
|
3
|
-
*/
|
|
4
1
|
export declare const REPO_URLS: {
|
|
5
2
|
readonly domainEnrollment: "git@github.com:PayFit/domain-enrollment.git";
|
|
6
3
|
readonly iacDeploy: "git@github.com:PayFit/iac-deploy.git";
|
|
7
|
-
readonly ecrDeploy: "git@github.com:PayFit/ecr-deploy.git";
|
|
8
4
|
};
|
|
9
5
|
export declare const FILE_NAMES: {
|
|
10
6
|
readonly migrationState: ".migration-state.json";
|
|
@@ -12,7 +8,6 @@ export declare const FILE_NAMES: {
|
|
|
12
8
|
readonly stateRemovalCommands: "METASTACK_STATE_REMOVAL_COMMANDS.sh";
|
|
13
9
|
readonly migrationProcedure: "METASTACK_MIGRATION_PROCEDURE.md";
|
|
14
10
|
readonly spaceliftYaml: "spacelift.yaml";
|
|
15
|
-
readonly ecrYaml: "ecr.yaml";
|
|
16
11
|
readonly gitignore: ".gitignore";
|
|
17
12
|
};
|
|
18
13
|
export declare const GITIGNORE_ENTRIES: string;
|
|
@@ -24,9 +19,6 @@ export declare const DOMAIN_ENROLLMENT_PATHS: {
|
|
|
24
19
|
readonly spaceliftDir: "spacelift";
|
|
25
20
|
readonly spaceliftYaml: "spacelift/spacelift.yaml";
|
|
26
21
|
};
|
|
27
|
-
export declare const ECR_DEPLOY_PATHS: {
|
|
28
|
-
readonly ecrRepos: "ecr-private-repositories.yaml";
|
|
29
|
-
};
|
|
30
22
|
export declare const SPACELIFT_API: {
|
|
31
23
|
readonly endpoint: "https://payfit.app.spacelift.io/graphql";
|
|
32
24
|
};
|
|
@@ -36,9 +28,6 @@ export declare const SPACELIFT_INTEGRATIONS_ENV_IDS: {
|
|
|
36
28
|
readonly SHARED: "01GMN9T0G289G811A802GV7FN9";
|
|
37
29
|
readonly STAGING: "01GMN9SZQ1750KR5TH5W6XKQB0";
|
|
38
30
|
};
|
|
39
|
-
export declare const METASTACK_DIR = ".metastack";
|
|
40
|
-
export declare const IMPORT_TF_FILE = "import.tf";
|
|
41
31
|
export declare const STACK_MANAGERS: {
|
|
42
32
|
readonly projectsManager: "projects-manager";
|
|
43
|
-
readonly ecrDeployShared: "ecr-deploy-shared-eu-west-3";
|
|
44
33
|
};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* Constants for stack migration
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.STACK_MANAGERS = exports.
|
|
3
|
+
exports.STACK_MANAGERS = exports.SPACELIFT_INTEGRATIONS_ENV_IDS = exports.SPACELIFT_API = exports.DOMAIN_ENROLLMENT_PATHS = exports.IAC_DEPLOY_PATHS = exports.GITIGNORE_ENTRIES = exports.FILE_NAMES = exports.REPO_URLS = void 0;
|
|
7
4
|
exports.REPO_URLS = {
|
|
8
5
|
domainEnrollment: 'git@github.com:PayFit/domain-enrollment.git',
|
|
9
6
|
iacDeploy: 'git@github.com:PayFit/iac-deploy.git',
|
|
10
|
-
ecrDeploy: 'git@github.com:PayFit/ecr-deploy.git',
|
|
11
7
|
};
|
|
12
8
|
exports.FILE_NAMES = {
|
|
13
9
|
migrationState: '.migration-state.json',
|
|
@@ -15,7 +11,6 @@ exports.FILE_NAMES = {
|
|
|
15
11
|
stateRemovalCommands: 'METASTACK_STATE_REMOVAL_COMMANDS.sh',
|
|
16
12
|
migrationProcedure: 'METASTACK_MIGRATION_PROCEDURE.md',
|
|
17
13
|
spaceliftYaml: 'spacelift.yaml',
|
|
18
|
-
ecrYaml: 'ecr.yaml',
|
|
19
14
|
gitignore: '.gitignore',
|
|
20
15
|
};
|
|
21
16
|
exports.GITIGNORE_ENTRIES = [
|
|
@@ -34,9 +29,6 @@ exports.DOMAIN_ENROLLMENT_PATHS = {
|
|
|
34
29
|
spaceliftDir: 'spacelift',
|
|
35
30
|
spaceliftYaml: 'spacelift/spacelift.yaml',
|
|
36
31
|
};
|
|
37
|
-
exports.ECR_DEPLOY_PATHS = {
|
|
38
|
-
ecrRepos: 'ecr-private-repositories.yaml',
|
|
39
|
-
};
|
|
40
32
|
exports.SPACELIFT_API = {
|
|
41
33
|
endpoint: 'https://payfit.app.spacelift.io/graphql',
|
|
42
34
|
};
|
|
@@ -46,10 +38,7 @@ exports.SPACELIFT_INTEGRATIONS_ENV_IDS = {
|
|
|
46
38
|
SHARED: '01GMN9T0G289G811A802GV7FN9',
|
|
47
39
|
STAGING: '01GMN9SZQ1750KR5TH5W6XKQB0',
|
|
48
40
|
};
|
|
49
|
-
exports.METASTACK_DIR = '.metastack';
|
|
50
|
-
exports.IMPORT_TF_FILE = 'import.tf';
|
|
51
41
|
exports.STACK_MANAGERS = {
|
|
52
42
|
projectsManager: 'projects-manager',
|
|
53
|
-
ecrDeployShared: 'ecr-deploy-shared-eu-west-3',
|
|
54
43
|
};
|
|
55
44
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/executors/stack-migration/lib/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/executors/stack-migration/lib/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG;IACvB,gBAAgB,EAAE,6CAA6C;IAC/D,SAAS,EAAE,sCAAsC;CACzC,CAAA;AAEG,QAAA,UAAU,GAAG;IACxB,cAAc,EAAE,uBAAuB;IACvC,OAAO,EAAE,gBAAgB;IACzB,oBAAoB,EAAE,qCAAqC;IAC3D,kBAAkB,EAAE,kCAAkC;IACtD,aAAa,EAAE,gBAAgB;IAC/B,SAAS,EAAE,YAAY;CACf,CAAA;AAEG,QAAA,iBAAiB,GAAG;IAC/B,EAAE;IACF,6BAA6B;IAC7B,GAAG,kBAAU,CAAC,OAAO,GAAG;IACxB,kBAAU,CAAC,cAAc;IACzB,kBAAU,CAAC,oBAAoB;IAC/B,kBAAU,CAAC,kBAAkB;CAC9B,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AAEC,QAAA,gBAAgB,GAAG;IAC9B,eAAe,EAAE,kBAAkB;CAC3B,CAAA;AAEG,QAAA,uBAAuB,GAAG;IACrC,OAAO,EAAE,SAAS;IAClB,YAAY,EAAE,WAAW;IACzB,aAAa,EAAE,0BAA0B;CACjC,CAAA;AAEG,QAAA,aAAa,GAAG;IAC3B,QAAQ,EAAE,yCAAyC;CAC3C,CAAA;AAEG,QAAA,8BAA8B,GAAG;IAC5C,GAAG,EAAE,4BAA4B;IACjC,IAAI,EAAE,4BAA4B;IAClC,MAAM,EAAE,4BAA4B;IACpC,OAAO,EAAE,4BAA4B;CAC7B,CAAA;AAEG,QAAA,cAAc,GAAG;IAC5B,eAAe,EAAE,kBAAkB;CAC3B,CAAA"}
|
|
@@ -1,66 +1,23 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File operations helper with dry-run support
|
|
3
|
-
*/
|
|
4
1
|
import type { Logger } from './git-operations';
|
|
5
2
|
export declare class FileOperations {
|
|
6
3
|
private dryRun;
|
|
7
4
|
private logger;
|
|
8
5
|
constructor(dryRun: boolean, logger: Logger);
|
|
9
|
-
/**
|
|
10
|
-
* Read a YAML file
|
|
11
|
-
*/
|
|
12
6
|
readYaml(filePath: string): Record<string, unknown>;
|
|
13
|
-
/**
|
|
14
|
-
* Write a YAML file
|
|
15
|
-
*/
|
|
16
7
|
writeYaml(filePath: string, data: Record<string, unknown>): void;
|
|
17
|
-
/**
|
|
18
|
-
* Write a file
|
|
19
|
-
*/
|
|
20
8
|
writeFile(filePath: string, content: string): void;
|
|
21
|
-
/**
|
|
22
|
-
* Read a file
|
|
23
|
-
*/
|
|
24
9
|
readFile(filePath: string): string;
|
|
25
|
-
/**
|
|
26
|
-
* Create a directory
|
|
27
|
-
*/
|
|
28
10
|
mkdir(dirPath: string, options?: {
|
|
29
11
|
recursive?: boolean;
|
|
30
12
|
}): void;
|
|
31
|
-
/**
|
|
32
|
-
* Delete a file
|
|
33
|
-
*/
|
|
34
13
|
deleteFile(filePath: string): void;
|
|
35
|
-
/**
|
|
36
|
-
* Delete a directory recursively
|
|
37
|
-
*/
|
|
38
14
|
deleteDirectory(dirPath: string): void;
|
|
39
|
-
/**
|
|
40
|
-
* Copy a file
|
|
41
|
-
*/
|
|
42
15
|
copyFile(source: string, destination: string): void;
|
|
43
|
-
/**
|
|
44
|
-
* Check if file or directory exists
|
|
45
|
-
*/
|
|
46
16
|
exists(filePath: string): boolean;
|
|
47
|
-
/**
|
|
48
|
-
* Check if path is a directory
|
|
49
|
-
*/
|
|
50
17
|
isDirectory(filePath: string): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Read directory entries
|
|
53
|
-
*/
|
|
54
18
|
readDir(dirPath: string): Array<{
|
|
55
19
|
name: string;
|
|
56
20
|
isDirectory: boolean;
|
|
57
21
|
}>;
|
|
58
|
-
/**
|
|
59
|
-
* Remove top-level YAML keys from a file while preserving formatting
|
|
60
|
-
*/
|
|
61
|
-
removeYamlKeys(filePath: string, keysToRemove: string[]): void;
|
|
62
|
-
/**
|
|
63
|
-
* Update autodeploy field in YAML file while preserving formatting
|
|
64
|
-
*/
|
|
65
22
|
updateAutodeployInYaml(filePath: string, value: boolean): void;
|
|
66
23
|
}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* File operations helper with dry-run support
|
|
4
|
-
*/
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.FileOperations = void 0;
|
|
7
4
|
const tslib_1 = require("tslib");
|
|
@@ -12,16 +9,10 @@ class FileOperations {
|
|
|
12
9
|
this.dryRun = dryRun;
|
|
13
10
|
this.logger = logger;
|
|
14
11
|
}
|
|
15
|
-
/**
|
|
16
|
-
* Read a YAML file
|
|
17
|
-
*/
|
|
18
12
|
readYaml(filePath) {
|
|
19
13
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
20
14
|
return yaml.load(content);
|
|
21
15
|
}
|
|
22
|
-
/**
|
|
23
|
-
* Write a YAML file
|
|
24
|
-
*/
|
|
25
16
|
writeYaml(filePath, data) {
|
|
26
17
|
const content = yaml.dump(data, {
|
|
27
18
|
lineWidth: -1,
|
|
@@ -34,9 +25,6 @@ class FileOperations {
|
|
|
34
25
|
}
|
|
35
26
|
fs.writeFileSync(filePath, content);
|
|
36
27
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Write a file
|
|
39
|
-
*/
|
|
40
28
|
writeFile(filePath, content) {
|
|
41
29
|
if (this.dryRun) {
|
|
42
30
|
this.logger.info(`[DRY RUN] Would write file to: ${filePath}`);
|
|
@@ -44,15 +32,9 @@ class FileOperations {
|
|
|
44
32
|
}
|
|
45
33
|
fs.writeFileSync(filePath, content);
|
|
46
34
|
}
|
|
47
|
-
/**
|
|
48
|
-
* Read a file
|
|
49
|
-
*/
|
|
50
35
|
readFile(filePath) {
|
|
51
36
|
return fs.readFileSync(filePath, 'utf-8');
|
|
52
37
|
}
|
|
53
|
-
/**
|
|
54
|
-
* Create a directory
|
|
55
|
-
*/
|
|
56
38
|
mkdir(dirPath, options) {
|
|
57
39
|
if (this.dryRun) {
|
|
58
40
|
this.logger.info(`[DRY RUN] Would create directory: ${dirPath}`);
|
|
@@ -60,9 +42,6 @@ class FileOperations {
|
|
|
60
42
|
}
|
|
61
43
|
fs.mkdirSync(dirPath, options);
|
|
62
44
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Delete a file
|
|
65
|
-
*/
|
|
66
45
|
deleteFile(filePath) {
|
|
67
46
|
if (this.dryRun) {
|
|
68
47
|
this.logger.info(`[DRY RUN] Would delete file: ${filePath}`);
|
|
@@ -72,9 +51,6 @@ class FileOperations {
|
|
|
72
51
|
fs.unlinkSync(filePath);
|
|
73
52
|
}
|
|
74
53
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Delete a directory recursively
|
|
77
|
-
*/
|
|
78
54
|
deleteDirectory(dirPath) {
|
|
79
55
|
if (this.dryRun) {
|
|
80
56
|
this.logger.info(`[DRY RUN] Would delete directory: ${dirPath}`);
|
|
@@ -84,9 +60,6 @@ class FileOperations {
|
|
|
84
60
|
fs.rmSync(dirPath, { recursive: true, force: true });
|
|
85
61
|
}
|
|
86
62
|
}
|
|
87
|
-
/**
|
|
88
|
-
* Copy a file
|
|
89
|
-
*/
|
|
90
63
|
copyFile(source, destination) {
|
|
91
64
|
if (this.dryRun) {
|
|
92
65
|
this.logger.info(`[DRY RUN] Would copy ${source} -> ${destination}`);
|
|
@@ -94,21 +67,12 @@ class FileOperations {
|
|
|
94
67
|
}
|
|
95
68
|
fs.copyFileSync(source, destination);
|
|
96
69
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if file or directory exists
|
|
99
|
-
*/
|
|
100
70
|
exists(filePath) {
|
|
101
71
|
return fs.existsSync(filePath);
|
|
102
72
|
}
|
|
103
|
-
/**
|
|
104
|
-
* Check if path is a directory
|
|
105
|
-
*/
|
|
106
73
|
isDirectory(filePath) {
|
|
107
74
|
return fs.existsSync(filePath) && fs.statSync(filePath).isDirectory();
|
|
108
75
|
}
|
|
109
|
-
/**
|
|
110
|
-
* Read directory entries
|
|
111
|
-
*/
|
|
112
76
|
readDir(dirPath) {
|
|
113
77
|
if (!fs.existsSync(dirPath)) {
|
|
114
78
|
return [];
|
|
@@ -119,56 +83,6 @@ class FileOperations {
|
|
|
119
83
|
isDirectory: entry.isDirectory(),
|
|
120
84
|
}));
|
|
121
85
|
}
|
|
122
|
-
/**
|
|
123
|
-
* Remove top-level YAML keys from a file while preserving formatting
|
|
124
|
-
*/
|
|
125
|
-
removeYamlKeys(filePath, keysToRemove) {
|
|
126
|
-
if (this.dryRun) {
|
|
127
|
-
this.logger.info(`[DRY RUN] Would remove keys from ${filePath}:`);
|
|
128
|
-
keysToRemove.forEach(key => this.logger.info(` - ${key}`));
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const content = this.readFile(filePath);
|
|
132
|
-
const lines = content.split('\n');
|
|
133
|
-
const result = [];
|
|
134
|
-
let i = 0;
|
|
135
|
-
let skipUntilNextTopLevel = false;
|
|
136
|
-
while (i < lines.length) {
|
|
137
|
-
const line = lines[i];
|
|
138
|
-
// Check if this is a top-level key (no leading whitespace, ends with colon)
|
|
139
|
-
const topLevelMatch = line.match(/^([^:\s]+):/);
|
|
140
|
-
if (topLevelMatch) {
|
|
141
|
-
const key = topLevelMatch[1];
|
|
142
|
-
// Check if this key should be removed
|
|
143
|
-
if (keysToRemove.includes(key)) {
|
|
144
|
-
skipUntilNextTopLevel = true;
|
|
145
|
-
i++;
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
skipUntilNextTopLevel = false;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
// If we're not skipping, add the line
|
|
153
|
-
if (!skipUntilNextTopLevel) {
|
|
154
|
-
result.push(line);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
// Check if this is an indented line (part of the value we're skipping)
|
|
158
|
-
const isIndented = line.length > 0 && line[0] === ' ';
|
|
159
|
-
if (!isIndented && line.trim().length > 0) {
|
|
160
|
-
// We hit a non-indented line, stop skipping
|
|
161
|
-
skipUntilNextTopLevel = false;
|
|
162
|
-
result.push(line);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
i++;
|
|
166
|
-
}
|
|
167
|
-
this.writeFile(filePath, result.join('\n'));
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Update autodeploy field in YAML file while preserving formatting
|
|
171
|
-
*/
|
|
172
86
|
updateAutodeployInYaml(filePath, value) {
|
|
173
87
|
if (this.dryRun) {
|
|
174
88
|
this.logger.info(`[DRY RUN] Would set autodeploy=${value} in ${filePath}`);
|
|
@@ -179,11 +93,9 @@ class FileOperations {
|
|
|
179
93
|
const result = [];
|
|
180
94
|
for (let i = 0; i < lines.length; i++) {
|
|
181
95
|
const line = lines[i];
|
|
182
|
-
// Match lines with 'autodeploy:' (with proper indentation)
|
|
183
96
|
const autodeployMatch = line.match(/^(\s*)autodeploy:\s*(true|false)(.*)$/);
|
|
184
97
|
if (autodeployMatch) {
|
|
185
98
|
const [, indent, , rest] = autodeployMatch;
|
|
186
|
-
// Replace with the new value, preserving indentation and any trailing comments
|
|
187
99
|
result.push(`${indent}autodeploy: ${value}${rest}`);
|
|
188
100
|
}
|
|
189
101
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file-operations.js","sourceRoot":"","sources":["../../../../src/executors/stack-migration/lib/file-operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"file-operations.js","sourceRoot":"","sources":["../../../../src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,GAAG,IAAI,EAAE,CAAC,CAAA;YACrD,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;QAED,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;IAC7C,CAAC;CACF;AA3HD,wCA2HC"}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Git operations helper
|
|
3
|
-
*/
|
|
4
1
|
export interface Logger {
|
|
5
2
|
info(message: string): void;
|
|
6
3
|
success(message: string): void;
|
|
@@ -11,36 +8,12 @@ export declare class GitOperations {
|
|
|
11
8
|
private dryRun;
|
|
12
9
|
private logger;
|
|
13
10
|
constructor(dryRun: boolean, logger: Logger);
|
|
14
|
-
/**
|
|
15
|
-
* Execute a git command
|
|
16
|
-
*/
|
|
17
11
|
private exec;
|
|
18
|
-
/**
|
|
19
|
-
* Clone a repository
|
|
20
|
-
*/
|
|
21
12
|
clone(repoUrl: string, targetPath: string, cwd: string): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Pull latest changes from origin/main
|
|
24
|
-
*/
|
|
25
13
|
pull(cwd: string): Promise<void>;
|
|
26
|
-
/**
|
|
27
|
-
* Create a new branch
|
|
28
|
-
*/
|
|
29
14
|
createBranch(branchName: string, cwd: string): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Add files to staging area
|
|
32
|
-
*/
|
|
33
15
|
add(files: string[], cwd: string): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Commit changes
|
|
36
|
-
*/
|
|
37
16
|
commit(message: string, cwd: string): Promise<void>;
|
|
38
|
-
/**
|
|
39
|
-
* Push branch to remote
|
|
40
|
-
*/
|
|
41
17
|
push(branchName: string, cwd: string): Promise<void>;
|
|
42
|
-
/**
|
|
43
|
-
* Create a draft PR using GitHub CLI
|
|
44
|
-
*/
|
|
45
18
|
createPR(branchName: string, title: string, body: string, cwd: string): Promise<string>;
|
|
46
19
|
}
|