Skip to content

Commit

Permalink
feat: update CEM analyzer to run from root of project, and rename "st…
Browse files Browse the repository at this point in the history
…yles" directory in package format to "sass"
  • Loading branch information
DRiFTy17 committed Jun 3, 2024
1 parent 9b2507e commit 82ce460
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
5 changes: 5 additions & 0 deletions config/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@
"type": "boolean",
"description": "Disables automatic generation of the custom elements manifest as part of the build.",
"default": "false"
},
"outputPath": {
"type": "string",
"description": "The path to output the custom elements manifest to. This is relative to the project root.",
"default": "dist/cem"
}
}
},
Expand Down
13 changes: 7 additions & 6 deletions src/commands/build/build-command-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export async function build({

// Compile TypeScript to JavaScript ESM (includes bare module specifiers)
await runTask('Compiling sources...', async () => {
await compileTypeScriptTask(config, stagingSrcDir, stagingSrcDir, esmBuildDir, ts.ScriptTarget.ES2017, ts.ModuleKind.ES2015, true, typingsDir);
await compileTypeScriptTask(config, stagingSrcDir, stagingSrcDir, esmBuildDir, ts.ScriptTarget.ES2020, ts.ModuleKind.ES2015, true, typingsDir);
}, quiet);

// Get the full library entry point
Expand Down Expand Up @@ -150,7 +150,7 @@ export async function build({
// Generates Custom Elements Manifest file.
if (!config.context.customElementsManifestConfig?.disableAutoGeneration) {
await runTask('Generating custom elements manifest...', async () => {
await generateCustomElementsManifest(config.context, stagingSrcDir, { quiet });
await generateCustomElementsManifest(config.context, config.context.paths.rootDir, { outDir: 'dist/cem', quiet });
});
}
}
Expand All @@ -170,7 +170,7 @@ export async function createDistributionPackage({
const releaseRootDir = join(config.paths.distReleaseDir, packageJson.name);
const releaseDistDir = join(releaseRootDir, 'dist');
const releaseEsmDir = join(releaseRootDir, 'esm');
const releaseStylesDir = join(releaseRootDir, 'styles');
const releaseSassDir = join(releaseRootDir, 'sass');
const releaseDistEsmDir = join(releaseDistDir, 'esm');
const releaseTypingsDir = releaseEsmDir;
const buildEsmDir = join(buildOutputDir, 'esm');
Expand All @@ -179,6 +179,7 @@ export async function createDistributionPackage({
const buildSrcDir = join(buildOutputDir, 'src');
const esbuildOutputDir = join(buildOutputDir, 'esbuild');
const bundleOutputDir = join(buildOutputDir, 'bundle');
const customElementsOutputDir = join(config.paths.rootDir, config.context.customElementsManifestConfig.outputPath ?? 'dist/cem');

// Clean previous release build
await deleteDir(config.paths.distReleaseDir);
Expand All @@ -188,7 +189,7 @@ export async function createDistributionPackage({
await mkdirp(releaseDistDir);
await mkdirp(releaseEsmDir);
await mkdirp(releaseDistEsmDir);
await mkdirp(releaseStylesDir);
await mkdirp(releaseSassDir);
await mkdirp(releaseTypingsDir);

// Append license headers to all files in the package
Expand All @@ -197,14 +198,14 @@ export async function createDistributionPackage({
// Copy files from build output to the package structure
const customElementsFiles = config.context.customElementsManifestConfig?.disableAutoGeneration
? []
: [{ path: join(buildSrcDir, 'custom-elements.json'), rootPath: buildSrcDir, outputPath: releaseRootDir }];
: [{ path: join(customElementsOutputDir, 'custom-elements.json'), rootPath: customElementsOutputDir, outputPath: releaseRootDir }];
const fileConfigs: IFileCopyConfig[] = [
{ path: join(buildEsmDir, '**/*.js*'), rootPath: buildEsmDir, outputPath: releaseEsmDir },
{ path: join(esbuildOutputDir, '**/*.js*'), rootPath: esbuildOutputDir, outputPath: releaseDistEsmDir },
{ path: join(bundleOutputDir, '**/*.js*'), rootPath: bundleOutputDir, outputPath: releaseDistDir },
{ path: join(buildTypingsDir, '**/*.d.ts'), rootPath: buildTypingsDir, outputPath: releaseTypingsDir },
{ path: join(buildCssDir, '**/*.css'), rootPath: buildCssDir, outputPath: releaseDistDir },
{ path: join(buildSrcDir, '**/*.scss'), rootPath: buildSrcDir, outputPath: releaseStylesDir },
{ path: join(buildSrcDir, '**/*.scss'), rootPath: buildSrcDir, outputPath: releaseSassDir },
{ path: join(projectRootDir, 'README.md'), rootPath: projectRootDir, outputPath: releaseRootDir },
{ path: join(projectRootDir, 'LICENSE'), rootPath: projectRootDir, outputPath: releaseRootDir },
...customElementsFiles
Expand Down
1 change: 1 addition & 0 deletions src/core/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface IProjectConfig {
export interface ICustomElementsManifestConfig {
configFileName?: string;
disableAutoGeneration?: boolean;
outputPath?: string;
}

export interface IProjectLicenseConfig {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/manifest-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IGenerateCustomElementsManifestOptions {

export async function generateCustomElementsManifest(
projectConfig: IProjectConfig,
srcDir: string,
cwd: string,
{ configFileName, outDir, quiet = true }: IGenerateCustomElementsManifestOptions = {}
): Promise<string> {
let cmd = 'npx custom-elements-manifest analyze';
Expand All @@ -23,8 +23,8 @@ export async function generateCustomElementsManifest(
}

if (outDir) {
cmd += ` --outdir ${cpath.relative(srcDir, outDir)}`;
cmd += ` --outdir ${cpath.relative(cwd, outDir)}`;
}

return await runCommand(cmd, srcDir, !quiet);
return await runCommand(cmd, cwd, !quiet);
}

0 comments on commit 82ce460

Please sign in to comment.