Skip to content
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

Add automatic install and build for plugins #46

Merged
merged 5 commits into from
Sep 5, 2024
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"chalk": "4.1.2",
"commander": "12.1.0",
"concurrently": "^8.2.2",
"execa": "^9.3.1",
"get-latest-version": "5.1.0",
"git-url-parse": "13.1.1",
"nodemon": "^3.1.0",
Expand Down
94 changes: 94 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 24 additions & 6 deletions src/cli/commands/plugin/init/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ import gitUrlParse from 'git-url-parse';
import path from 'node:path';
import { outdent } from 'outdent';

import { dirContainsStrapiProject, logInstructions } from '../../utils/helpers';
import {
dirContainsStrapiProject,
logInstructions,
getPkgManager,
runBuild,
runInstall,
} from '../../utils/helpers';

import { gitIgnoreFile } from './files/gitIgnore';

import type { CLIContext } from '../../../../types';
import type { InitOptions, TemplateFile } from '@strapi/pack-up';

type ActionOptions = Pick<InitOptions, 'silent' | 'debug'>;
import type { CLIContext, CommonCLIOptions } from '../../../../types';
import type { TemplateFile } from '@strapi/pack-up';

// TODO: remove these when release versions are available
const USE_RC_VERSIONS: string[] = [
Expand All @@ -29,7 +33,7 @@ let promptAnswers: { name: string; answer: string | boolean }[] = [];

export default async (
packagePath: string,
{ silent, debug }: ActionOptions,
{ silent, debug, useNpm, usePnpm, useYarn, install }: CommonCLIOptions,
{ logger, cwd }: CLIContext
) => {
try {
Expand Down Expand Up @@ -59,6 +63,20 @@ export default async (
template,
});

const packageManager = getPkgManager(
{
useNpm,
usePnpm,
useYarn,
},
isStrapiProject
);

if (install) {
await runInstall(packageManager, pluginPath);
await runBuild(packageManager, pluginPath);
}

if (isStrapiProject) {
const pkgName = promptAnswers.find((option) => option.name === 'pkgName')?.answer;
const language = promptAnswers.find((option) => option.name === 'typescript')?.answer
Expand Down
7 changes: 7 additions & 0 deletions src/cli/commands/plugin/init/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ const command: StrapiCommand = ({ command: commanderCommand, ctx }) => {
.argument('path', 'path to the plugin')
.option('-d, --debug', 'Enable debugging mode with verbose logs', false)
.option('--silent', "Don't log anything", false)
// Package manager options
.option('--use-npm', 'Use npm as the plugin package manager')
.option('--use-yarn', 'Use yarn as the plugin package manager')
.option('--use-pnpm', 'Use pnpm as the plugin package manager')

// dependencies options
.option('--no-install', 'Do not install dependencies')
.action((path, options) => {
return action(path, options, ctx);
});
Expand Down
Loading