({
extensionPath,
outputPath,
silent,
}: PackOptions)
| 47 | } |
| 48 | |
| 49 | export async function packExtension({ |
| 50 | extensionPath, |
| 51 | outputPath, |
| 52 | silent, |
| 53 | }: PackOptions): Promise<boolean> { |
| 54 | const resolvedPath = resolve(extensionPath); |
| 55 | const logger = getLogger({ silent }); |
| 56 | |
| 57 | // Check if directory exists |
| 58 | if (!existsSync(resolvedPath) || !statSync(resolvedPath).isDirectory()) { |
| 59 | logger.error(`ERROR: Directory not found: ${extensionPath}`); |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | // Check if manifest exists |
| 64 | const manifestPath = join(resolvedPath, "manifest.json"); |
| 65 | if (!existsSync(manifestPath)) { |
| 66 | logger.log(`No manifest.json found in ${extensionPath}`); |
| 67 | const shouldInit = await confirm({ |
| 68 | message: "Would you like to create a manifest.json file?", |
| 69 | default: true, |
| 70 | }); |
| 71 | |
| 72 | if (shouldInit) { |
| 73 | const success = await initExtension(extensionPath); |
| 74 | if (!success) { |
| 75 | logger.error("ERROR: Failed to create manifest"); |
| 76 | return false; |
| 77 | } |
| 78 | } else { |
| 79 | logger.error("ERROR: Cannot pack extension without manifest.json"); |
| 80 | return false; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Validate manifest first |
| 85 | logger.log("Validating manifest..."); |
| 86 | if (!validateManifest(manifestPath)) { |
| 87 | logger.error("ERROR: Cannot pack extension with invalid manifest"); |
| 88 | return false; |
| 89 | } |
| 90 | |
| 91 | // Read and parse manifest |
| 92 | let manifest; |
| 93 | try { |
| 94 | const manifestContent = readFileSync(manifestPath, "utf-8"); |
| 95 | const manifestData = JSON.parse(manifestContent); |
| 96 | const manifestVersion = getManifestVersionFromRawData(manifestData); |
| 97 | if (!manifestVersion) { |
| 98 | logger.error( |
| 99 | `ERROR: Manifest version mismatch. Expected "${Object.keys(MANIFEST_SCHEMAS).join(" or ")}", found "${manifestVersion}"`, |
| 100 | ); |
| 101 | logger.error( |
| 102 | ` Please update the manifest_version in your manifest.json to a supported version`, |
| 103 | ); |
| 104 | return false; |
| 105 | } |
| 106 |
no test coverage detected
searching dependent graphs…