Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
]
},
"build:manifest": {
"command": "node scripts/generate-manifest.js",
"command": "node scripts/analyzer/generate-manifest.js",
"files": [
"**/*.ts"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {Analyzer, type AbsolutePath} from '@lit-labs/analyzer';
import {
createPackageAnalyzer,
type AbsolutePath,
} from '@lit-labs/analyzer/package-analyzer.js';
import {generateManifest} from '@lit-labs/gen-manifest';
import {writeFileTree} from '@lit-labs/gen-utils/lib/file-utils.js';
import type {Package as Manifest} from 'custom-elements-manifest';
import * as path from 'path';
import ts from 'typescript';

const ROOT = process.cwd() as AbsolutePath;

Expand Down Expand Up @@ -39,39 +41,7 @@ await writeFileTree(ROOT, {
console.log('Generated custom-elements.json');

async function generateManifestFromTsconfig(basePath: AbsolutePath) {
// Create TS program
const formatHost: ts.FormatDiagnosticsHost = {
getCanonicalFileName: (fileName) => fileName,
getCurrentDirectory: () => ts.sys.getCurrentDirectory(),
getNewLine: () => ts.sys.newLine,
};
const tsconfigPath = ts.findConfigFile(basePath, ts.sys.fileExists);
const configFile = ts.readConfigFile(tsconfigPath, ts.sys.readFile);
if (configFile.error) {
throw new Error(ts.formatDiagnostic(configFile.error, formatHost));
}
const parsedConfig = ts.parseJsonConfigFileContent(
configFile.config,
ts.sys,
basePath,
);
if (parsedConfig.errors.length) {
throw new Error(ts.formatDiagnostics(parsedConfig.errors, formatHost));
}
const program = ts.createProgram({
rootNames: parsedConfig.fileNames,
options: parsedConfig.options,
host: ts.createCompilerHost(parsedConfig.options, true),
});

// Run Lit analyzer
const analyzer = new Analyzer({
typescript: ts,
getProgram: () => program,
fs: ts.sys,
path,
basePath,
});
const analyzer = createPackageAnalyzer(basePath);
const pkg = analyzer.getPackage();
const files = await generateManifest(pkg);
const manifestContent = files['custom-elements.json'];
Expand Down
Loading