Skip to content

Commit 514afe5

Browse files
initial commit for git strategy
1 parent 04ff1f7 commit 514afe5

File tree

10 files changed

+191
-6
lines changed

10 files changed

+191
-6
lines changed

src/commander/commander.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { uploadFigma, uploadWebFigmaCommand,uploadAppFigmaCommand } from './upl
88
import startServer from './server.js';
99
import stopServer from './stopServer.js'
1010
import ping from './ping.js'
11+
import mergeBranch from './mergeBranch.js'
12+
import mergeBuild from './mergeBuild.js'
1113

1214
const program = new Command();
1315

@@ -23,6 +25,8 @@ program
2325
.addCommand(upload)
2426
.addCommand(startServer)
2527
.addCommand(stopServer)
28+
.addCommand(mergeBranch)
29+
.addCommand(mergeBuild)
2630
.addCommand(ping)
2731
.addCommand(configFigma)
2832
.addCommand(uploadFigma)

src/commander/mergeBranch.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { Command } from 'commander';
2+
import { Context } from '../types.js';
3+
import { color, Listr, ListrDefaultRendererLogLevels } from 'listr2';
4+
import startServer from '../tasks/startServer.js';
5+
import auth from '../tasks/auth.js';
6+
import ctxInit from '../lib/ctx.js';
7+
import getGitInfo from '../tasks/getGitInfo.js';
8+
import createBuild from '../tasks/createBuild.js';
9+
import snapshotQueue from '../lib/snapshotQueue.js';
10+
import { startPolling, startPingPolling } from '../lib/utils.js';
11+
import fetchBuildInfo from '../tasks/fetchBuildInfo.js'
12+
import mergeBuilds from '../tasks/mergeBuilds.js'
13+
14+
const command = new Command();
15+
16+
command
17+
.name('merge')
18+
.description('Merge a source branch into the target branch')
19+
.command('branch')
20+
.description('Merge the source branch into the target branch')
21+
.requiredOption('--source <string>', 'Source branch to merge')
22+
.requiredOption('--target <string>', 'Target branch to merge into')
23+
.action(async function(this: Command, options: { source: string, target: string }) {
24+
const { source, target } = options;
25+
let ctx: Context = ctxInit(command.optsWithGlobals());
26+
27+
if (!source || source.trim() === '') {
28+
ctx.log.error('Error: The --source option cannot be empty.');
29+
process.exit(1);
30+
}
31+
if (!target || target.trim() === '') {
32+
ctx.log.error('Error: The --target option cannot be empty.');
33+
process.exit(1);
34+
}
35+
36+
ctx.log.debug(`Merging source branch '${source}' into target branch '${target}'`);
37+
ctx.snapshotQueue = new snapshotQueue(ctx);
38+
ctx.totalSnapshots = 0;
39+
ctx.isStartExec = true;
40+
41+
let tasks = new Listr<Context>(
42+
[
43+
auth(ctx),
44+
fetchBuildInfo(ctx),
45+
mergeBuilds(ctx),
46+
],
47+
{
48+
rendererOptions: {
49+
icon: {
50+
[ListrDefaultRendererLogLevels.OUTPUT]: '→'
51+
},
52+
color: {
53+
[ListrDefaultRendererLogLevels.OUTPUT]: color.gray
54+
}
55+
}
56+
}
57+
);
58+
59+
try {
60+
await tasks.run(ctx);
61+
} catch (error) {
62+
console.error('Error during merge operation:', error);
63+
}
64+
});
65+
66+
export default command;

src/commander/mergeBuild.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { Command } from 'commander';
2+
import { Context } from '../types.js';
3+
import { color, Listr, ListrDefaultRendererLogLevels } from 'listr2';
4+
import startServer from '../tasks/startServer.js';
5+
import auth from '../tasks/auth.js';
6+
import ctxInit from '../lib/ctx.js';
7+
import getGitInfo from '../tasks/getGitInfo.js';
8+
import createBuild from '../tasks/createBuild.js';
9+
import snapshotQueue from '../lib/snapshotQueue.js';
10+
import { startPolling, startPingPolling } from '../lib/utils.js';
11+
import fetchBuildInfo from '../tasks/fetchBuildInfo.js'
12+
import mergeBuilds from '../tasks/mergeBuilds.js'
13+
14+
const command = new Command();
15+
16+
command
17+
.name('merge')
18+
.description('Merge a source branch into the target branch')
19+
.command('build')
20+
.description('Merge the source branch into the target branch')
21+
.requiredOption('--source <string>', 'Source build to merge')
22+
.requiredOption('--target <string>', 'Target build to merge into')
23+
.action(async function(this: Command, options: { source: string, target: string }) {
24+
const { source, target } = options;
25+
let ctx: Context = ctxInit(command.optsWithGlobals());
26+
27+
if (!source || source.trim() === '') {
28+
ctx.log.error('Error: The --source option cannot be empty.');
29+
process.exit(1);
30+
}
31+
if (!target || target.trim() === '') {
32+
ctx.log.error('Error: The --target option cannot be empty.');
33+
process.exit(1);
34+
}
35+
36+
ctx.log.debug(`Merging source build '${source}' into target build '${target}'`);
37+
38+
ctx.snapshotQueue = new snapshotQueue(ctx);
39+
ctx.totalSnapshots = 0;
40+
ctx.isStartExec = true;
41+
42+
let tasks = new Listr<Context>(
43+
[
44+
auth(ctx),
45+
fetchBuildInfo(ctx),
46+
mergeBuilds(ctx),
47+
],
48+
{
49+
rendererOptions: {
50+
icon: {
51+
[ListrDefaultRendererLogLevels.OUTPUT]: '→'
52+
},
53+
color: {
54+
[ListrDefaultRendererLogLevels.OUTPUT]: color.gray
55+
}
56+
}
57+
}
58+
);
59+
60+
try {
61+
await tasks.run(ctx);
62+
} catch (error) {
63+
console.error('Error during merge operation:', error);
64+
}
65+
});
66+
67+
export default command;

src/lib/env.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ export default (): Env => {
2020
PROJECT_NAME,
2121
SMARTUI_API_PROXY,
2222
SMARTUI_API_SKIP_CERTIFICATES,
23-
USE_REMOTE_DISCOVERY
23+
USE_REMOTE_DISCOVERY,
24+
SMART_GIT
2425
} = process.env
2526

2627
return {
@@ -42,6 +43,7 @@ export default (): Env => {
4243
PROJECT_NAME,
4344
SMARTUI_API_PROXY,
4445
SMARTUI_API_SKIP_CERTIFICATES: SMARTUI_API_SKIP_CERTIFICATES === 'true',
45-
USE_REMOTE_DISCOVERY: USE_REMOTE_DISCOVERY === 'true'
46+
USE_REMOTE_DISCOVERY: USE_REMOTE_DISCOVERY === 'true',
47+
SMART_GIT: SMART_GIT === 'true'
4648
}
4749
}

src/lib/httpClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default class httpClient {
202202
}
203203
}
204204

205-
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean) {
205+
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean, smartGit: boolean) {
206206
return this.request({
207207
url: '/build',
208208
method: 'POST',
@@ -211,7 +211,8 @@ export default class httpClient {
211211
config,
212212
buildName,
213213
isStartExec,
214-
packageVersion: pkgJSON.version
214+
packageVersion: pkgJSON.version,
215+
smartGit
215216
}
216217
}, log)
217218
}

src/tasks/createBuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1010
updateLogContext({task: 'createBuild'});
1111

1212
try {
13-
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec);
13+
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT);
1414
ctx.build = {
1515
id: resp.data.buildId,
1616
name: resp.data.buildName,

src/tasks/createBuildExec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1212

1313
try {
1414
if (ctx.authenticatedInitially && !ctx.config.skipBuildCreation) {
15-
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec);
15+
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT);
1616
ctx.build = {
1717
id: resp.data.buildId,
1818
name: resp.data.buildName,

src/tasks/fetchBuildInfo.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ListrTask, ListrRendererFactory } from 'listr2'
2+
import { Context } from '../types.js'
3+
import chalk from 'chalk'
4+
import { updateLogContext } from '../lib/logger.js'
5+
6+
export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRendererFactory> => {
7+
return {
8+
title: `Fetching build info`,
9+
task: async (ctx, task): Promise<void> => {
10+
updateLogContext({task: 'fetchBuildInfo'});
11+
12+
try {
13+
task.title = 'Build info fetched';
14+
} catch (error: any) {
15+
ctx.log.debug(error);
16+
task.output = chalk.gray(error.message);
17+
throw new Error('Build info fetching failed');
18+
}
19+
},
20+
rendererOptions: { persistentOutput: true }
21+
}
22+
}

src/tasks/mergeBuilds.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ListrTask, ListrRendererFactory } from 'listr2'
2+
import { Context } from '../types.js'
3+
import chalk from 'chalk'
4+
import { updateLogContext } from '../lib/logger.js'
5+
6+
export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRendererFactory> => {
7+
return {
8+
title: `Merging smartui branches`,
9+
task: async (ctx, task): Promise<void> => {
10+
updateLogContext({task: 'auth'});
11+
12+
try {
13+
task.title = 'Merging smartui branch initiated';
14+
} catch (error: any) {
15+
ctx.log.debug(error);
16+
task.output = chalk.gray(error.message);
17+
throw new Error('Merging smartui branch failed');
18+
}
19+
},
20+
rendererOptions: { persistentOutput: true }
21+
}
22+
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export interface Env {
9494
SMARTUI_API_PROXY: string | undefined;
9595
SMARTUI_API_SKIP_CERTIFICATES: boolean;
9696
USE_REMOTE_DISCOVERY: boolean;
97+
SMART_GIT: boolean;
9798
}
9899

99100
export interface Snapshot {

0 commit comments

Comments
 (0)