Skip to content

Commit

Permalink
fix: import Document directly & add ignorePrompts CLI flag (#18668)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis authored Nov 3, 2023
1 parent 805908b commit e741a4a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
2 changes: 2 additions & 0 deletions packages/core/admin/_internal/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const build: StrapiCommand = ({ command, ctx }) => {
command
.command('build')
.option('-d, --debug', 'Enable debugging mode with verbose logs', false)
.option('--ignore-prompts', 'Ignore all prompts', false)
.option('--minify', 'Minify the output', true)
.option('--no-optimization', '[deprecated]: use minify instead')
.option('--silent', "Don't log anything", false)
Expand All @@ -31,6 +32,7 @@ const develop: StrapiCommand = ({ command, ctx }) => {
.alias('dev')
.option('-d, --debug', 'Enable debugging mode with verbose logs', false)
.option('--silent', "Don't log anything", false)
.option('--ignore-prompts', 'Ignore all prompts', false)
.option('--polling', 'Watch for file changes in network directories', false)
.option(
'--no-build',
Expand Down
16 changes: 11 additions & 5 deletions packages/core/admin/_internal/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { getTimer } from './core/timer';
import type { CLIContext } from '@strapi/strapi';

interface BuildOptions extends CLIContext {
/**
* @default false
*/
ignorePrompts?: boolean;
/**
* Minify the output
*
Expand All @@ -31,13 +35,15 @@ interface BuildOptions extends CLIContext {
*
* @description Builds the admin panel of the strapi application.
*/
const build = async ({ logger, cwd, tsconfig, ...options }: BuildOptions) => {
const build = async ({ logger, cwd, tsconfig, ignorePrompts, ...options }: BuildOptions) => {
const timer = getTimer();

const { didInstall } = await checkRequiredDependencies({ cwd, logger }).catch((err) => {
logger.error(err.message);
process.exit(1);
});
const { didInstall } = await checkRequiredDependencies({ cwd, logger, ignorePrompts }).catch(
(err) => {
logger.error(err.message);
process.exit(1);
}
);

if (didInstall) {
return;
Expand Down
8 changes: 6 additions & 2 deletions packages/core/admin/_internal/node/core/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ interface DepToInstall {
const checkRequiredDependencies = async ({
cwd,
logger,
}: Pick<BuildOptions, 'cwd' | 'logger'>): Promise<CheckRequiredDependenciesResult> => {
ignorePrompts,
}: Pick<
BuildOptions,
'cwd' | 'logger' | 'ignorePrompts'
>): Promise<CheckRequiredDependenciesResult> => {
const pkg = await readPkgUp({ cwd });

if (!pkg) {
Expand Down Expand Up @@ -102,7 +106,7 @@ const checkRequiredDependencies = async ({
/**
* temporary until V5 when we _will_ be enforcing these dependencies as required.
*/
if (process.env.NODE_ENV !== 'development') {
if (process.env.NODE_ENV !== 'development' || ignorePrompts) {
return { didInstall: false };
}

Expand Down
23 changes: 18 additions & 5 deletions packages/core/admin/_internal/node/develop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,31 @@ import EE from '@strapi/strapi/dist/utils/ee';
import { writeStaticClientFiles } from './staticFiles';

interface DevelopOptions extends CLIContext {
/**
* @default false
*/
ignorePrompts?: boolean;
polling?: boolean;
open?: boolean;
}

const develop = async ({ cwd, polling, logger, tsconfig, ...options }: DevelopOptions) => {
const develop = async ({
cwd,
polling,
logger,
tsconfig,
ignorePrompts,
...options
}: DevelopOptions) => {
const timer = getTimer();

if (cluster.isPrimary) {
const { didInstall } = await checkRequiredDependencies({ cwd, logger }).catch((err) => {
logger.error(err.message);
process.exit(1);
});
const { didInstall } = await checkRequiredDependencies({ cwd, logger, ignorePrompts }).catch(
(err) => {
logger.error(err.message);
process.exit(1);
}
);

if (didInstall) {
return;
Expand Down
17 changes: 5 additions & 12 deletions packages/core/admin/_internal/node/staticFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import outdent from 'outdent';
import { format } from 'prettier';
import { createElement } from 'react';
import { renderToStaticMarkup } from 'react-dom/server';
import { DefaultDocument as Document } from '../../admin/src/components/DefaultDocument';

import type { BuildContext } from './createBuildContext';

Expand Down Expand Up @@ -38,21 +39,11 @@ const getEntryModule = ({ plugins }: EntryModuleArgs): string => {
`;
};

const getDefaultDocumentComponent = () => {
// eslint-disable-next-line @typescript-eslint/no-var-requires, node/no-missing-require
const { DefaultDocument } = require('@strapi/admin/strapi-admin');

return DefaultDocument;
};

/**
* TODO: Here in the future we could add the ability
* to load a user's Document component?
*/
const getDocumentHTML = ({ logger }: Pick<BuildContext, 'logger'>) => {
const Document = getDefaultDocumentComponent();
logger.debug('Got the default document');

const getDocumentHTML = async ({ logger }: Pick<BuildContext, 'logger'>) => {
const result = renderToStaticMarkup(createElement(Document));
logger.debug('Rendered the HTML');

Expand Down Expand Up @@ -84,7 +75,9 @@ const writeStaticClientFiles = async (ctx: BuildContext) => {
await fs.mkdir(ctx.runtimeDir, { recursive: true });
ctx.logger.debug('Created the runtime directory');

const indexHtml = decorateHTMLWithAutoGeneratedWarning(getDocumentHTML({ logger: ctx.logger }));
const indexHtml = decorateHTMLWithAutoGeneratedWarning(
await getDocumentHTML({ logger: ctx.logger })
);

await fs.writeFile(
path.join(ctx.runtimeDir, 'index.html'),
Expand Down
7 changes: 1 addition & 6 deletions packages/core/admin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"extends": "tsconfig/base.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "Bundler",
"noEmit": true
},
"extends": "tsconfig/client.json",
"include": ["_internal", "packup.config.ts"],
"exclude": ["node_modules"]
}

0 comments on commit e741a4a

Please sign in to comment.