Skip to content

Commit

Permalink
fix: make calls in husky pass through scripts
Browse files Browse the repository at this point in the history
Now the created projects husky files invoke gobtones-script instead of nps directly.

fix #12, fix #13
  • Loading branch information
alanrodas committed Dec 28, 2023
1 parent fc10438 commit 4bd640c
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 94 deletions.
9 changes: 1 addition & 8 deletions .husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ LOCAL_OBJ_NAME=${INPUT_ARR[1]}
REMOTE_REF=${INPUT_ARR[2]}
REMOTE_OBJ_NAME=${INPUT_ARR[3]}

echo $REMOTE_NAME;
echo $REMOTE_URL;
echo $LOCAL_REF;
echo $LOCAL_OBJ_NAME;
echo $REMOTE_REF;
echo $REMOTE_OBJ_NAME;

# We currently use this hook to verify that any commit (to any branch)
# passes the tests configured.
# If a tag is being pushed, then, we generate the documentation
Expand All @@ -58,7 +51,7 @@ echo $REMOTE_OBJ_NAME;

# Show welcome message
echo "**************************";
echo "Running pre puh hooks";
echo "Running pre push hooks";
echo "**************************";
echo "";

Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
## <small>0.5.5 (2023-12-28)</small>
## <small>0.5.6 (2023-12-28)</small>


* build: improve build system to build doc on a separate branch ([a6b1f73](https://github.com/gobstones/gobstones-scripts/commit/a6b1f73)), closes [#11](https://github.com/gobstones/gobstones-scripts/issues/11)


## <small>0.5.5 (2023-12-28)</small>

- build: improve build system to build doc on a separate branch ([a6b1f73](https://github.com/gobstones/gobstones-scripts/commit/a6b1f73)), closes [#11](https://github.com/gobstones/gobstones-scripts/issues/11)

## <small>0.5.4 (2023-11-23)</small>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gobstones/gobstones-scripts",
"version": "0.5.5",
"version": "0.5.6",
"description": "Scripts to abstract away build configuration of Gobstones Project's libraries and modules.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion project-types/cli-library/package-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"commander": "^11.1.0"
},
"devDependencies": {
"@gobstones/gobstones-scripts": "^0.5.5",
"@gobstones/gobstones-scripts": "^0.5.6",
"husky": "^8.0.2"
}
}
4 changes: 2 additions & 2 deletions project-types/common/husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ echo "";

# Run prettify
echo "Run prettify\n";
npx --no -- nps prettify;
npx --no -- gobstones-scripts run prettify --silent ;

# Run changelog
echo "\nRun changelog\n";
npx --no -- nps changelog;
npx --no gobstones-scripts run changelog --silent ;

# Add all generated files
echo "\nAdd generated files to commit\n";
Expand Down
11 changes: 2 additions & 9 deletions project-types/common/husky/pre-push
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ LOCAL_OBJ_NAME=${INPUT_ARR[1]}
REMOTE_REF=${INPUT_ARR[2]}
REMOTE_OBJ_NAME=${INPUT_ARR[3]}

echo $REMOTE_NAME;
echo $REMOTE_URL;
echo $LOCAL_REF;
echo $LOCAL_OBJ_NAME;
echo $REMOTE_REF;
echo $REMOTE_OBJ_NAME;

# We currently use this hook to verify that any commit (to any branch)
# passes the tests configured.
# If a tag is being pushed, then, we generate the documentation
Expand All @@ -58,13 +51,13 @@ echo $REMOTE_OBJ_NAME;

# Show welcome message
echo "**************************";
echo "Running pre puh hooks";
echo "Running pre push hooks";
echo "**************************";
echo "";

# Run all the tests
echo "Running tests";
npx --no nps test;
npx --no -- gobstones-scripts run test --silent;

# If pushing a tag, generate doc and push them as
# a "docs" branch in the remote.
Expand Down
2 changes: 1 addition & 1 deletion project-types/library/package-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"@gobstones/gobstones-core": "^0.4.7"
},
"devDependencies": {
"@gobstones/gobstones-scripts": "^0.5.5",
"@gobstones/gobstones-scripts": "^0.5.6",
"husky": "^8.0.2"
}
}
2 changes: 1 addition & 1 deletion project-types/react-library/package-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@gobstones/gobstones-scripts": "^0.5.5",
"@gobstones/gobstones-scripts": "^0.5.6",
"husky": "^8.0.2"
}
}
2 changes: 1 addition & 1 deletion project-types/web-library/package-definition.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"devDependencies": {
"@jest/globals": "^29.3.1",
"@gobstones/gobstones-scripts": "^0.5.5",
"@gobstones/gobstones-scripts": "^0.5.6",
"husky": "^8.0.2"
}
}
175 changes: 108 additions & 67 deletions src/cli/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const program = commanderProgram;

program
.description(`${cli.banner()}\n\n${cli.welcome()}`)
.addHelpText('beforeAll', `${cli.banner()}\n\n${cli.welcome()}`)
.addHelpText('before', `${cli.banner()}\n\n${cli.welcome()}`)
.version(config.version)
.option('-c, --config')
.action((options: { config?: boolean }) => {
Expand All @@ -45,15 +45,24 @@ program
'"',
'npm'
)
.option('-s, --silent', 'Run silently, not displaying the banner', false)
.option('-T, --test', 'Run using verdaccio as a registry', false)
.action(
(
projectName: string,
options: { type?: string; packageManager?: string; test?: boolean }
options: { type?: string; packageManager?: string; silent?: boolean; test?: boolean }
) => {
failIfOptionInvalid(options, 'type', Object.keys(config.projectTypes));
failIfOptionInvalid(options, 'package-manager', Object.keys(config.packageManagers));

if (!options.silent) {
cli.displayWelcomeForAction(
`Creating a project by the name "${projectName}" of type ` +
`"${options.type ?? config.loadedOptions.type}" using package manager ` +
`"${options.packageManager ?? config.loadedOptions.manager}".`
);
}

cli.runOrEnd(() => {
api.create(projectName, options.type, options.packageManager, options.test);
}, [
Expand Down Expand Up @@ -81,33 +90,38 @@ program
'"',
'npm'
)
.option('-s, --silent', 'Run silently, not displaying the banner', false)
.option('-T, --test', 'Run using verdaccio as a registry', false)
.action((options: { type?: string; packageManager?: string; test?: boolean }) => {
failIfOptionInvalid(options, 'type', Object.keys(config.projectTypes));
failIfOptionInvalid(options, 'package-manager', Object.keys(config.packageManagers));

cli.displayWelcomeForAction(
`Initializing a project in the current directory of type ` +
`"${options.type ?? config.loadedOptions.type}" using package manager ` +
`"${options.packageManager ?? config.loadedOptions.manager}".`
);
.action(
(options: { type?: string; packageManager?: string; silent?: boolean; test?: boolean }) => {
failIfOptionInvalid(options, 'type', Object.keys(config.projectTypes));
failIfOptionInvalid(options, 'package-manager', Object.keys(config.packageManagers));

cli.runOrEnd(() => {
api.init(
options.type ?? config.loadedOptions.type,
options.packageManager ?? config.loadedOptions.manager,
options.test
);
}, [
{
error: 'non empty folder',
msg:
'Init expects the current folder to be empty, but the ' +
'folder contains elements.\nEnsure that you are calling ' +
'init from an empty folder an try again.'
if (!options.silent) {
cli.displayWelcomeForAction(
`Initializing a project in the current directory of type ` +
`"${options.type ?? config.loadedOptions.type}" using package manager ` +
`"${options.packageManager ?? config.loadedOptions.manager}".`
);
}
]);
});

cli.runOrEnd(() => {
api.init(
options.type ?? config.loadedOptions.type,
options.packageManager ?? config.loadedOptions.manager,
options.test
);
}, [
{
error: 'non empty folder',
msg:
'Init expects the current folder to be empty, but the ' +
'folder contains elements.\nEnsure that you are calling ' +
'init from an empty folder an try again.'
}
]);
}
);

program
.command('update')
Expand All @@ -126,31 +140,46 @@ program
Object.keys(config.projectTypes).join('", "') +
'"'
)
.option('-s, --silent', 'Run silently, not displaying the banner', false)
.option('-T, --test', 'Run using verdaccio as a registry', false)
.action((options: { items?: string; type?: string; force?: boolean; test?: boolean }) => {
failIfOptionInvalid(options, 'type', Object.keys(config.loadedOptions.type));
.action(
(options: {
items?: string;
type?: string;
force?: boolean;
silent?: boolean;
test?: boolean;
}) => {
failIfOptionInvalid(options, 'type', Object.keys(config.loadedOptions.type));

if (options.items !== 'all') {
failIfOptionInvalid(options, 'items', config[config.loadedOptions.type].onUpdate);
}
if (options.items !== 'all') {
failIfOptionInvalid(options, 'items', config[config.loadedOptions.type].onUpdate);
}

cli.displayWelcomeForAction(
`Updating files in current project of type ` +
`"${options.type ?? config.loadedOptions.type}" using package manager ` +
`"${config.loadedOptions.manager}".\n\n` +
`Files to update: ${options.items}`
);
if (!options.silent) {
cli.displayWelcomeForAction(
`Updating files in current project of type ` +
`"${options.type ?? config.loadedOptions.type}" using package manager ` +
`"${config.loadedOptions.manager}".\n\n` +
`Files to update: ${options.items}`
);
}

cli.runOrEnd(() => {
const files = api.update(options.force, options.items, options.type, options.test);
const useAbsolute = config.useAbsolutePaths;
cli.display('Files updated:');
files.forEach((file) => {
const fileName = useAbsolute ? file : path.relative(config.projectRootPath, file);
cli.display('\t' + fileName, 'blue');
});
}, [{ error: 'non root folder', msg: 'Update should be run on the root of a project.' }]);
});
cli.runOrEnd(() => {
const files = api.update(options.force, options.items, options.type, options.test);
const useAbsolute = config.useAbsolutePaths;
cli.display('Files updated:');
files.forEach((file) => {
const fileName = useAbsolute
? file
: path.relative(config.projectRootPath, file);
cli.display('\t' + fileName, 'blue');
});
}, [
{ error: 'non root folder', msg: 'Update should be run on the root of a project.' }
]);
}
);

program
.command('eject')
Expand All @@ -169,19 +198,22 @@ program
Object.keys(config.projectTypes).join('", "') +
'"'
)
.action((options: { items?: string; type?: string; force?: boolean }) => {
.option('-s, --silent', 'Run silently, not displaying the banner', false)
.action((options: { items?: string; type?: string; force?: boolean; silent?: boolean }) => {
failIfOptionInvalid(options, 'type', Object.keys(config.loadedOptions.type));

if (options.items !== 'all') {
failIfOptionInvalid(options, 'items', config[config.loadedOptions.type].onEject);
}

cli.displayWelcomeForAction(
`Ejecting files in current project of type ` +
`"${options.type ?? config.loadedOptions.type}" using package manager ` +
`"${config.loadedOptions.manager}".\n\n` +
`Files to eject: ${options.items}`
);
if (!options.silent) {
cli.displayWelcomeForAction(
`Ejecting files in current project of type ` +
`"${options.type ?? config.loadedOptions.type}" using package manager ` +
`"${config.loadedOptions.manager}".\n\n` +
`Files to eject: ${options.items}`
);
}

cli.runOrEnd(() => {
const files = api.eject(options.force, options.items, options.type);
Expand All @@ -203,16 +235,25 @@ program
'"',
'npm'
)
.action((command: string, args: string[], options: { packageManager: string }) => {
failIfOptionInvalid(options, 'package-manager', Object.keys(config.packageManagers));

cli.displayWelcomeForAction(
(!command
? `Displaying all available commands on project of type `
: `Running command "${command}" on project of type `) +
`"${config.loadedOptions.type}" using package manager ` +
`"${options.packageManager ?? config.loadedOptions.manager}".`
);

api.run(command, args, options.packageManager, undefined);
});
.option('-s, --silent', 'Run silently, not displaying the banner', false)
.action(
(
command: string,
args: string[],
options: { packageManager: string; silent?: boolean }
) => {
failIfOptionInvalid(options, 'package-manager', Object.keys(config.packageManagers));

if (!options.silent) {
cli.displayWelcomeForAction(
(!command
? `Displaying all available commands on project of type `
: `Running command "${command}" on project of type `) +
`"${config.loadedOptions.type}" using package manager ` +
`"${options.packageManager ?? config.loadedOptions.manager}".`
);
}

api.run(command, args, options.packageManager, undefined);
}
);
2 changes: 1 addition & 1 deletion src/config/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
* @group Internal API Objects
*/
export const version = '0.5.5';
export const version = '0.5.6';

/**
* The current directory, as detected by node.
Expand Down

0 comments on commit 4bd640c

Please sign in to comment.