Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
BioPhoton committed Sep 23, 2024
1 parent 9d11bfe commit fe47ead
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
22 changes: 13 additions & 9 deletions projects/build-env/src/executors/bootstrap/bootstrap-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import { writeFile } from 'node:fs/promises';
import { setupNpmWorkspace } from './npm';
import { formatInfo } from '../../internal/logging';
import { VERDACCIO_REGISTRY_JSON } from './constants';
import { ExecutorContext, logger } from '@nx/devkit';
import { logger } from '@nx/devkit';
import {
configureRegistry,
type Environment,
VERDACCIO_ENV_TOKEN,
} from './npm';
import runKillProcessExecutor from '../kill-process/executor';

export type BootstrapEnvironmentOptions = Partial<
StarVerdaccioOptions & Environment
Expand All @@ -30,16 +29,14 @@ export type BootstrapEnvironmentResult = Environment & {
};

export async function bootstrapEnvironment(
options: BootstrapEnvironmentOptions & {
projectName: string;
}
options
): Promise<BootstrapEnvironmentResult> {
const { verbose, environmentRoot } = options;

const { verbose, environmentRoot, storage } = options;
const registryResult = await startVerdaccioServer({
storage: join(environmentRoot, 'storage'),
storage: storage ?? join(environmentRoot, 'storage'),
verbose,
readyWhen: 'Environment ready under',
keepServerRunning: true,
keepServerRunning: false,
...options,
});

Expand All @@ -63,5 +60,12 @@ export async function bootstrapEnvironment(
JSON.stringify(activeRegistry.registry, null, 2)
);

logger.info(
formatInfo(
`Environment ready under: ${activeRegistry.root}`,
VERDACCIO_ENV_TOKEN
)
);

return activeRegistry;
}
15 changes: 6 additions & 9 deletions projects/build-env/src/executors/bootstrap/executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { type ExecutorContext, logger } from '@nx/devkit';
import type { BootstrapExecutorOptions } from './schema';
import {
bootstrapEnvironment,
BootstrapEnvironmentOptions,
BootstrapEnvironmentResult,
} from './bootstrap-env';
import { normalizeExecutorOptions } from '../internal/normalize-options';
Expand Down Expand Up @@ -41,7 +42,8 @@ export default async function runBootstrapExecutor(
try {
bootstrapResult = await bootstrapEnvironment({
projectName,
...normalizedOptions,
environmentRoot,
keepServerRunning,
});
} catch (error) {
logger.error(error);
Expand All @@ -52,15 +54,10 @@ export default async function runBootstrapExecutor(
}

if (keepServerRunning) {
const { registry, root } = bootstrapResult;
const { registry } = bootstrapResult;
const { url } = registry;
logger.info(
formatInfo(`Environment ready under: ${root}`, VERDACCIO_ENV_TOKEN)
);
logger.info(
formatInfo(
`Verdaccio server is running on ${registry.url}`,
VERDACCIO_ENV_TOKEN
)
formatInfo(`Verdaccio server running under ${url}`, VERDACCIO_ENV_TOKEN)
);
} else {
await runKillProcessExecutor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export function parseRegistryData(stdout: string): VerdaccioProcessResult {
}

export type StarVerdaccioOnlyOptions = {
targetName?: string;
projectName?: string;
verbose?: boolean;
};
Expand All @@ -67,9 +66,7 @@ export type VerdaccioExecuterOptions = {
readyWhen?: string;
storage?: string;
port?: string;
p?: string;
config?: string;
c?: string;
location?: string;
clear?: boolean;
};
Expand All @@ -78,7 +75,6 @@ export type StarVerdaccioOptions = VerdaccioExecuterOptions &
StarVerdaccioOnlyOptions;

export async function startVerdaccioServer({
targetName = DEFAULT_START_VERDACCIO_TARGET,
projectName,
port = String(uniquePort()),
storage = join(getEnvironmentsRoot(projectName), 'storage'),
Expand All @@ -93,7 +89,7 @@ export async function startVerdaccioServer({
executeProcess({
command: 'nx',
args: objectToCliArgs({
_: [targetName, projectName ?? '', '--'],
_: [DEFAULT_START_VERDACCIO_TARGET, projectName ?? '', '--'],
storage,
port,
verbose,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@ import type { ExecutorContext } from '@nx/devkit';

export function normalizeExecutorOptions<
T extends ExecutorContext,
I extends Record<string, unknown> & {
environmentProject?: string;
environmentRoot?: string;
}
I extends Record<string, unknown>
>(
context: T,
options: I
): T & {
options: I & { environmentRoot: string };
options: I;
} {
return {
...context,
Expand Down

0 comments on commit fe47ead

Please sign in to comment.