Skip to content

Commit

Permalink
Updated piral publish command
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Feb 8, 2024
1 parent 2619f43 commit 30bfbfd
Show file tree
Hide file tree
Showing 19 changed files with 746 additions and 476 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Removed pilet-related options in debug settings when running `piral debug` (#670)
- Improved internal navigation Blazor pilets using `piral-blazor`
- Updated dependencies
- Updated `piral publish` command to work exclusively for emulator websites
- Added special entry point to emulator website when accessed online (#654)
- Added feed selection view for remote emulator website (#654)

Expand Down
17 changes: 0 additions & 17 deletions src/tooling/piral-cli/src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { log, installPatch } from './common';
import { commands } from './commands';
import { setBundler } from './bundler';
import { setReleaseProvider } from './release';
import { addPiletRule, addPiralRule } from './rules';
import {
ToolCommand,
Expand All @@ -13,7 +12,6 @@ import {
PiletRuleContext,
PackagePatcher,
BundlerDefinition,
ReleaseProvider,
} from './types';

function findAll(commandName: string, cb: (command: ToolCommand<any, any>, index: number) => void) {
Expand Down Expand Up @@ -157,18 +155,3 @@ export function withBundler(name: string, actions: BundlerDefinition) {

return this;
}

export function withReleaseProvider(name: string, action: ReleaseProvider) {
if (typeof name !== 'string') {
log('apiReleaseProviderInvalid_0207', 'providerName');
} else if (typeof action !== 'object') {
log('apiReleaseProviderInvalid_0207', 'provider');
} else {
setReleaseProvider({
name,
action,
});
}

return this;
}
76 changes: 17 additions & 59 deletions src/tooling/piral-cli/src/apps/build-pilet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
validateSharedDependencies,
defaultSchemaVersion,
flattenExternals,
triggerBuildPilet,
} from '../common';

interface PiletData {
Expand Down Expand Up @@ -217,66 +218,23 @@ export async function buildPilet(baseDir = process.cwd(), options: BuildPiletOpt
}

const pilets = await concurrentWorkers(allEntries, concurrency, async (entryModule) => {
const targetDir = dirname(entryModule);
const { peerDependencies, peerModules, root, apps, piletPackage, ignored, importmap, schema } =
await retrievePiletData(targetDir, app);
const schemaVersion = originalSchemaVersion || schema || config.schemaVersion || defaultSchemaVersion;
const piralInstances = apps.map((m) => m.appPackage.name);
const externals = combinePiletExternals(piralInstances, peerDependencies, peerModules, importmap);
const dest = resolve(root, target);
const outDir = dirname(dest);
const outFile = basename(dest);

validateSharedDependencies(importmap);

if (fresh) {
progress('Removing output directory ...');
await removeDirectory(outDir);
}

logInfo('Bundle pilet ...');

await hooks.beforeBuild?.({ root, outDir, importmap, entryModule, schemaVersion, piletPackage });

await callPiletBuild(
{
root,
piralInstances,
optimizeModules,
sourceMaps,
watch,
contentHash,
minify,
externals,
targetDir,
importmap,
outFile,
outDir,
entryModule: `./${relative(root, entryModule)}`,
logLevel,
version: schemaVersion,
ignored,
_,
},
const { piletPackage, root, outDir, apps, outFile, dest } = await triggerBuildPilet({
_,
app,
bundlerName,
);

await hooks.afterBuild?.({ root, outDir, importmap, entryModule, schemaVersion, piletPackage });

if (declaration) {
await hooks.beforeDeclaration?.({ root, outDir, entryModule, piletPackage });
await createPiletDeclaration(
piletPackage.name,
piralInstances,
root,
entryModule,
externals,
outDir,
ForceOverwrite.yes,
logLevel,
);
await hooks.afterDeclaration?.({ root, outDir, entryModule, piletPackage });
}
contentHash,
entryModule,
fresh,
logLevel,
minify,
optimizeModules,
originalSchemaVersion,
sourceMaps,
target,
watch,
hooks,
declaration,
});

logDone(`Pilet "${piletPackage.name}" built successfully!`);

Expand Down
177 changes: 37 additions & 140 deletions src/tooling/piral-cli/src/apps/build-piral.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
import { join, resolve } from 'path';
import { callPiralBuild } from '../bundler';
import { LogLevels, PiralBuildType } from '../types';
import {
retrievePiletsInfo,
retrievePiralRoot,
removeDirectory,
logDone,
checkCliCompatibility,
progress,
setLogLevel,
logReset,
createEmulatorSources,
log,
logInfo,
runScript,
packageEmulator,
normalizePublicUrl,
getDestination,
validateSharedDependencies,
flattenExternals,
createEmulatorWebsite,
allName,
emulatorPackageName,
emulatorName,
emulatorWebsiteName,
emulatorSourcesName,
releaseName,
triggerBuildEmulator,
triggerBuildShell,
} from '../common';

const allName = 'all';
const releaseName = 'release';
const emulatorName = 'emulator';
const emulatorPackageName = 'package';
const emulatorSourcesName = 'sources';
const emulatorWebsiteName = 'website';

export interface BuildPiralOptions {
/**
* The location of the piral
Expand Down Expand Up @@ -130,18 +122,6 @@ export const buildPiralDefaults: BuildPiralOptions = {
optimizeModules: false,
};

async function runLifecycle(root: string, scripts: Record<string, string>, type: string) {
const script = scripts?.[type];

if (script) {
log('generalDebug_0003', `Running "${type}" ("${script}") ...`);
await runScript(script, root);
log('generalDebug_0003', `Finished running "${type}".`);
} else {
log('generalDebug_0003', `No script for "${type}" found ...`);
}
}

export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOptions = {}) {
const {
entry = buildPiralDefaults.entry,
Expand Down Expand Up @@ -193,139 +173,56 @@ export async function buildPiral(baseDir = process.cwd(), options: BuildPiralOpt

// only applies to an explicit emulator target (e.g., "emulator-website") or to "all" / "emulator" with the setting from the piral.json
if ([emulatorSourcesName, emulatorPackageName, emulatorWebsiteName].includes(emulatorType)) {
const emulatorPublicUrl = '/';
const targetDir = useSubdir ? join(dest.outDir, emulatorName) : dest.outDir;
const appDir = emulatorType !== emulatorWebsiteName ? join(targetDir, 'app') : targetDir;
progress('Starting emulator build ...');

// since we create this anyway let's just pretend we want to have it clean!
await removeDirectory(targetDir);

await hooks.beforeBuild?.({ root, publicUrl: emulatorPublicUrl, externals, entryFiles, targetDir, piralInstances });

logInfo(`Bundle ${emulatorName} ...`);
const {
dir: outDir,
name: outFile,
hash,
} = await callPiralBuild(
{
root,
piralInstances,
emulator: true,
standalone: false,
optimizeModules,
sourceMaps,
watch,
contentHash,
minify: false,
externals: flattenExternals(externals),
publicUrl: emulatorPublicUrl,
entryFiles,
logLevel,
ignored,
outDir: appDir,
outFile: dest.outFile,
_,
},
bundlerName,
);

await hooks.afterBuild?.({
await triggerBuildEmulator({
root,
publicUrl: emulatorPublicUrl,
logLevel,
bundlerName,
emulatorType,
hooks,
targetDir,
ignored,
externals,
entryFiles,
targetDir,
piralInstances,
hash,
outDir,
outFile,
optimizeModules,
sourceMaps,
watch,
scripts,
contentHash,
outFile: dest.outFile,
_,
});

await runLifecycle(root, scripts, 'piral:postbuild');
await runLifecycle(root, scripts, `piral:postbuild-${emulatorName}`);

await hooks.beforeEmulator?.({ root, externals, targetDir, outDir });

let rootDir = root;

switch (emulatorType) {
case emulatorPackageName:
rootDir = await createEmulatorSources(root, externals, outDir, outFile, logLevel);
await hooks.beforePackage?.({ root, externals, targetDir, outDir, rootDir });
await packageEmulator(rootDir);
await hooks.afterPackage?.({ root, externals, targetDir, outDir, rootDir });
break;
case emulatorSourcesName:
rootDir = await createEmulatorSources(root, externals, outDir, outFile, logLevel);
logDone(`Emulator package sources available in "${rootDir}".`);
break;
case emulatorWebsiteName:
rootDir = await createEmulatorWebsite(root, externals, outDir, outFile, logLevel);
logDone(`Emulator website available in "${rootDir}".`);
break;
}

await hooks.afterEmulator?.({ root, externals, targetDir, outDir, rootDir });
logReset();
}

// either 'release' or 'all'
if (type === releaseName || type === allName) {
const targetDir = useSubdir ? join(dest.outDir, releaseName) : dest.outDir;
progress('Starting release build ...');

// since we create this anyway let's just pretend we want to have it clean!
await removeDirectory(targetDir);

logInfo(`Bundle ${releaseName} ...`);

await hooks.beforeBuild?.({ root, publicUrl, externals, entryFiles, targetDir, piralInstances });

const {
dir: outDir,
name: outFile,
hash,
} = await callPiralBuild(
{
root,
piralInstances,
emulator: false,
standalone: false,
optimizeModules,
sourceMaps,
watch,
contentHash,
minify,
externals: flattenExternals(externals),
publicUrl,
outFile: dest.outFile,
outDir: targetDir,
entryFiles,
logLevel,
ignored,
_,
},
await triggerBuildShell({
targetDir,
logLevel,
bundlerName,
);

await hooks.afterBuild?.({
root,
publicUrl,
contentHash,
externals,
ignored,
minify,
optimizeModules,
publicUrl,
outFile: dest.outFile,
root,
sourceMaps,
watch,
hooks,
entryFiles,
targetDir,
piralInstances,
outDir,
outFile,
hash,
scripts,
_,
});

await runLifecycle(root, scripts, 'piral:postbuild');
await runLifecycle(root, scripts, `piral:postbuild-${releaseName}`);

logDone(`Files for publication available in "${outDir}".`);
logReset();
}

Expand Down
Loading

0 comments on commit 30bfbfd

Please sign in to comment.