mirror of
https://github.com/strapi/strapi.git
synced 2025-12-07 20:44:55 +00:00
* feat(cli): add cloud commands Co-authored-by: Gonzalo Garcia <nouvellegon@gmail.com> Co-authored-by: nathan-pichon <nathan.pichon@strapi.io> Co-authored-by: Abdallah M <55534657+abdallahmz@users.noreply.github.com>
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import chalk from 'chalk';
|
|
import { has } from 'lodash/fp';
|
|
|
|
// TODO: Remove duplicated code by extracting to a shared package
|
|
|
|
const assertCwdContainsStrapiProject = (name: string) => {
|
|
const logErrorAndExit = () => {
|
|
console.log(
|
|
`You need to run ${chalk.yellow(
|
|
`strapi ${name}`
|
|
)} in a Strapi project. Make sure you are in the right directory.`
|
|
);
|
|
process.exit(1);
|
|
};
|
|
|
|
try {
|
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
const pkgJSON = require(`${process.cwd()}/package.json`);
|
|
if (
|
|
!has('dependencies.@strapi/strapi', pkgJSON) &&
|
|
!has('devDependencies.@strapi/strapi', pkgJSON)
|
|
) {
|
|
logErrorAndExit();
|
|
}
|
|
} catch (err) {
|
|
logErrorAndExit();
|
|
}
|
|
};
|
|
|
|
const runAction =
|
|
(name: string, action: (...args: any[]) => Promise<unknown>) =>
|
|
(...args: unknown[]) => {
|
|
assertCwdContainsStrapiProject(name);
|
|
|
|
Promise.resolve()
|
|
.then(() => {
|
|
return action(...args);
|
|
})
|
|
.catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|
|
};
|
|
|
|
export { runAction };
|