Skip to content

Commit f9d061c

Browse files
authored
Add application dependency utilities (#21)
* Add application utilities * Give positive feedback when utilities pass
1 parent 405c925 commit f9d061c

File tree

10 files changed

+42
-10
lines changed

10 files changed

+42
-10
lines changed

src/components/Generator/Generator.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export type GeneratorSettings = {
1818
checkoutGitRequest: 'none' | 'github' | 'gitlab';
1919
configureGitHooks: boolean;
2020
fileUtilities: boolean;
21+
appUtilities: boolean;
2122
};
2223

2324
const Generator = (): ReactElement => {

src/components/Generator/GeneredTaskfile/SaveFile/SaveFile.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import {ReactElement, useState} from 'react';
3+
import { ReactElement, useState } from 'react';
44

55
import styles from './save-file.module.scss';
66

src/components/Generator/GeneredTaskfile/addons/addons.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TaskfileAddons } from '@/components/Generator/GeneredTaskfile/taskfile'
44
import runtime from './runtime';
55
import git from './git';
66
import fileUtilities from './fileUtilities';
7+
import appUtilities from '@/components/Generator/GeneredTaskfile/addons/appUtilities';
78

89
/**
910
* Render addons for the Taskfile based on the generator settings
@@ -15,6 +16,7 @@ const renderAddons = (settings: GeneratorSettings, addons: TaskfileAddons): void
1516
runtime(settings, addons);
1617
git(settings, addons);
1718
fileUtilities(settings, addons);
19+
appUtilities(settings, addons);
1820
};
1921

2022
export default renderAddons;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
function app:ensure { # Abort if the desired program is not installed
2+
if [ ! $(which "$1") ]; then
3+
echo "Missing required application ${RED}$1${RESET}. Install it before tying again."
4+
exit 1
5+
else
6+
echo "Application ${GREEN}$1${RESET} is installed.";
7+
fi
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { GeneratorSettings } from '@/components/Generator';
2+
import { TaskfileAddons } from '@/components/Generator/GeneredTaskfile/taskfile';
3+
import loadTemplate from '@/helpers/loadTemplate';
4+
import appUtilitiesSh from './app-utilities.sh';
5+
6+
const appUtilities = (settings: GeneratorSettings, addon: TaskfileAddons): void => {
7+
if (settings.appUtilities) {
8+
addon.utilityFunctions.push(loadTemplate(appUtilitiesSh));
9+
}
10+
};
11+
12+
export default appUtilities;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './appUtilities';
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
function file:ensure { # Abort if the desired file is not found
22
if [ ! -f $1 ]; then
3-
echo -e "${RED}Missing required file: ${YELLOW}$1${RESET}"
3+
echo -e "Missing required file ${RED}$1${RESET}, make sure it is created."
44
exit 1
5+
else
6+
echo "File ${GREEN}$1${RESET} is present.";
57
fi
68
}
79

8-
function file:ensure-copy { # file:ensure-copy $COPY_TARGET $COPY_SOURCE
9-
if [ ! -f $1 ]; then
10+
function file:ensure-copy { # file:ensure-copy $COPY_DESTINATION $SOURCE
11+
if [ ! -f $1 ]; then
1012
cp $2 $1;
11-
echo -e "Created copy of ${YELLOW}$2${RESET} to create ${GREEN}$1${RESET}.";
13+
echo -e "Created copy of ${YELLOW}$2${RESET} to create required file ${GREEN}$1${RESET}.";
1214
else
13-
echo "${GREEN}$1${RESET} is present.";
14-
fi
15+
echo "File ${GREEN}$1${RESET} is present.";
16+
fi
1517
}

src/components/Generator/GeneredTaskfile/taskfile-base.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile
7272
banner
7373
if [[ ! "$(declare -F task:${@-help})" ]]; then
7474
title "Task not found"
75-
echo -e "Task ${YELLOW}$1${RESET} doesn't exist."
75+
echo -e "Task ${RED}$1${RESET} doesn't exist."
7676
task:help
7777
exit 1
7878
fi

src/components/Generator/Settings/Settings.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { ReactElement } from 'react';
44

5-
import styles from './settings.module.css';
5+
import styles from './settings.module.scss';
66
import TextInput from '@/components/Form/Text';
77
import RadioInput from '@/components/Form/Radio';
88
import { useFormContext } from 'react-hook-form';
@@ -80,7 +80,9 @@ const Settings = (): ReactElement => {
8080
]}
8181
/>
8282
<Checkbox name="configureGitHooks">Configure git hooks</Checkbox>
83-
<Checkbox name="fileUtilities">File utilities</Checkbox>
83+
<h2>Utilities</h2>
84+
<Checkbox name="fileUtilities">File checks</Checkbox>
85+
<Checkbox name="appUtilities">Application dependencies</Checkbox>
8486
</div>
8587
);
8688
};

src/components/Generator/Settings/settings.module.css renamed to src/components/Generator/Settings/settings.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
display: flex;
33
flex-direction: column;
44
gap: 1rem;
5+
6+
h2 {
7+
font-size: 1rem;
8+
}
59
}

0 commit comments

Comments
 (0)