Skip to content

Commit

Permalink
Merge pull request #1 from QDivision/master
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
dryink authored Aug 7, 2021
2 parents 366d1be + 8e156c2 commit b829ed5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ All subcommands supported by `chip` can be viewed by running `chip help`:
chip <command>
Commands:
chip sync [services..] Clone or pull repos for services in
project
chip checkout <branch> [services..] Checkout a git branch for services in
project
chip status [services..] Show git status for services in project
chip install [services..] Install dependencies for services in
project
chip start [services..] Start services in project
chip stop [services..] Stop services in project
chip restart [services..] Stop and restart services in project
chip logs [services..] View logs for services in project
chip list List all services in project
chip sync [services|tags..] Clone or pull repos for services in
project
chip checkout <branch> [services|tags..] Checkout a git branch for services in
project
chip status [services|tags..] Show git status for services in project
chip install [services|tags..] Install dependencies for services in
project
chip start [services|tags..] Start services in project
chip stop [services|tags..] Stop services in project
chip restart [services|tags..] Stop and restart services in project
chip logs [services|tags..] View logs for services in project
chip list List all services in project
```

## Sample Project
Expand Down Expand Up @@ -83,11 +83,15 @@ services:
repo: '[email protected]:QDivision/sandwich-ui.git'
install: 'yarn install'
run: 'yarn start'
tags:
- sandwich

sandwich-api:
repo: '[email protected]:QDivision/sandwich-api.git'
install: 'mvn clean package -D maven.test.skip=true'
run: 'mvn spring-boot:run -D spring-boot.run.profiles=local'
tags:
- sandwich

ingredient-api:
repo: '[email protected]:QDivision/ingredient-api.git'
Expand Down
16 changes: 8 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { cleanNames } from './utils/strings';

yargs
.command<{ services: string[] }>(
'sync [services..]',
'sync [services|tags..]',
'Clone or pull repos for services in project',
(yargs) => yargs.positional('services', { describe: 'service names' }),
handleErrors(async ({ services }) => {
Expand All @@ -25,7 +25,7 @@ yargs
}),
)
.command<{ branch: string; services: string[] }>(
'checkout <branch> [services..]',
'checkout <branch> [services|tags..]',
'Checkout a git branch for services in project',
(yargs) =>
yargs
Expand All @@ -38,7 +38,7 @@ yargs
}),
)
.command<{ services: string[] }>(
'status [services..]',
'status [services|tags..]',
'Show git status for services in project',
(yargs) => yargs.positional('services', { describe: 'service names' }),
handleErrors(async ({ services }) => {
Expand All @@ -48,7 +48,7 @@ yargs
}),
)
.command<{ services: string[] }>(
'install [services..]',
'install [services|tags..]',
'Install dependencies for services in project',
(yargs) => yargs.positional('services', { describe: 'service names' }),
handleErrors(async ({ services }) => {
Expand All @@ -58,7 +58,7 @@ yargs
}),
)
.command<{ services: string[] }>(
'start [services..]',
'start [services|tags..]',
'Start services in project',
(yargs) => yargs.positional('services', { describe: 'service names' }),
handleErrors(async ({ services }) => {
Expand All @@ -68,7 +68,7 @@ yargs
}),
)
.command<{ services: string[]; remove: boolean }>(
'stop [services..]',
'stop [services|tags..]',
'Stop services in project',
(yargs) =>
yargs.positional('services', { describe: 'service names' }).option('r', {
Expand All @@ -84,7 +84,7 @@ yargs
}),
)
.command<{ services: string[]; remove: boolean }>(
'restart [services..]',
'restart [services|tags..]',
'Stop and restart services in project',
(yargs) =>
yargs.positional('services', { describe: 'service names' }).option('r', {
Expand All @@ -100,7 +100,7 @@ yargs
}),
)
.command<{ services: string[] }>(
'logs [services..]',
'logs [services|tags..]',
'View logs for services in project',
(yargs) => yargs.positional('services', { describe: 'service names' }),
handleErrors(async ({ services }) => {
Expand Down
8 changes: 7 additions & 1 deletion src/subcommands/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const dockerServices = async () => {
status ?? '',
' 🐳',
'',
'',
]);
};

Expand All @@ -32,10 +33,11 @@ export const listServices = async () => {
bold('STATUS'),
bold('PID'),
bold('BRANCH'),
bold('TAGS'),
],
];

for (const { name, run = '' } of services) {
for (const { name, run = '', tags = [] } of services) {
const { pid, startTime } = activeProcesses[name] || {};
const exists = !!pid;

Expand All @@ -59,13 +61,16 @@ export const listServices = async () => {
}
}

const allTags = tags.join(', ') || '';

// prettier-ignore
tableData.push([
name,
run.substring(0, 20) + (run.length > 20 ? '...' : ''),
status,
exists ? String(pid) : '',
await git.activeBranch(name),
allTags.substring(0, 30) + (allTags.length > 30 ? '...' : ''),
]);
}

Expand All @@ -82,6 +87,7 @@ export const listServices = async () => {
2: { alignment: 'left' },
3: { alignment: 'left' },
4: { alignment: 'left' },
5: { alignment: 'left' },
},
}).trim(),
);
Expand Down
9 changes: 7 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export interface ChipConfig {
install?: string;
run?: string;
env?: { [envVar: string]: string };
}
tags?: string[];
}
| undefined;
};
}
Expand Down Expand Up @@ -60,6 +61,7 @@ export const readServices = async (
run?: string;
env: { [envVar: string]: string };
secrets: { [name: string]: string };
tags?: string[];
}[]
> => {
const config = await readConfig();
Expand All @@ -75,7 +77,10 @@ export const readServices = async (
);

return whitelist.length > 0
? allServices.filter((service) => whitelist.includes(service.name))
? [...new Set([
...allServices.filter(service => whitelist.includes(service.name)),
...allServices.filter(service => service.tags?.some(tag => whitelist.includes(tag))),
])]
: allServices;
};

Expand Down

0 comments on commit b829ed5

Please sign in to comment.