Skip to content

App utilities #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/Generator/Generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type GeneratorSettings = {
checkoutGitRequest: 'none' | 'github' | 'gitlab';
configureGitHooks: boolean;
fileUtilities: boolean;
appUtilities: boolean;
};

const Generator = (): ReactElement => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import {ReactElement, useState} from 'react';
import { ReactElement, useState } from 'react';

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

Expand Down
2 changes: 2 additions & 0 deletions src/components/Generator/GeneredTaskfile/addons/addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TaskfileAddons } from '@/components/Generator/GeneredTaskfile/taskfile'
import runtime from './runtime';
import git from './git';
import fileUtilities from './fileUtilities';
import appUtilities from '@/components/Generator/GeneredTaskfile/addons/appUtilities';

/**
* Render addons for the Taskfile based on the generator settings
Expand All @@ -15,6 +16,7 @@ const renderAddons = (settings: GeneratorSettings, addons: TaskfileAddons): void
runtime(settings, addons);
git(settings, addons);
fileUtilities(settings, addons);
appUtilities(settings, addons);
};

export default renderAddons;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function app:ensure {
if [ ! $(which "$1") ]; then
echo "Missing required application ${RED}$1${RESET}. Install it before tying again."
exit 1
fi
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { GeneratorSettings } from '@/components/Generator';
import { TaskfileAddons } from '@/components/Generator/GeneredTaskfile/taskfile';
import loadTemplate from '@/helpers/loadTemplate';
import appUtilitiesSh from './app-utilities.sh';

const appUtilities = (settings: GeneratorSettings, addon: TaskfileAddons): void => {
if (settings.appUtilities) {
addon.utilityFunctions.push(loadTemplate(appUtilitiesSh));
}
};

export default appUtilities;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './appUtilities';
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
function file:ensure { # Abort if the desired file is not found
if [ ! -f $1 ]; then
echo -e "${RED}Missing required file: ${YELLOW}$1${RESET}"
echo -e "Missing required file ${RED}$1${RESET}, make sure it is created."
exit 1
fi
}

function file:ensure-copy { # file:ensure-copy $COPY_TARGET $COPY_SOURCE
if [ ! -f $1 ]; then
cp $2 $1;
echo -e "Created copy of ${YELLOW}$2${RESET} to create ${GREEN}$1${RESET}.";
echo -e "Created copy of ${YELLOW}$2${RESET} to create required file ${GREEN}$1${RESET}.";
else
echo "${GREEN}$1${RESET} is present.";
echo "File ${GREEN}$1${RESET} is present.";
fi
}
2 changes: 1 addition & 1 deletion src/components/Generator/GeneredTaskfile/taskfile-base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function task:shorthand { ## Create CLI shorthand task instead of ./Taskfile
banner
if [[ ! "$(declare -F task:${@-help})" ]]; then
title "Task not found"
echo -e "Task ${YELLOW}$1${RESET} doesn't exist."
echo -e "Task ${RED}$1${RESET} doesn't exist."
task:help
exit 1
fi
Expand Down
6 changes: 4 additions & 2 deletions src/components/Generator/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { ReactElement } from 'react';

import styles from './settings.module.css';
import styles from './settings.module.scss';
import TextInput from '@/components/Form/Text';
import RadioInput from '@/components/Form/Radio';
import { useFormContext } from 'react-hook-form';
Expand Down Expand Up @@ -80,7 +80,9 @@ const Settings = (): ReactElement => {
]}
/>
<Checkbox name="configureGitHooks">Configure git hooks</Checkbox>
<Checkbox name="fileUtilities">File utilities</Checkbox>
<h2>Utilities</h2>
<Checkbox name="fileUtilities">File checks</Checkbox>
<Checkbox name="appUtilities">Application dependencies</Checkbox>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@
display: flex;
flex-direction: column;
gap: 1rem;

h2 {
font-size: 1rem;
}
}