refactor: Move archive management commands to Endo CLI
MODIFY
packages/cli/package.json
packages/cli/package.json
"dependencies": {
"@endo/daemon": "^0.1.2",
"@endo/where": "^0.1.2",
+ "@endo/compartment-mapper": "^0.6.2",
"commander": "^5.0.0"
},
"devDependencies": {

MODIFY
packages/cli/src/endo.js
packages/cli/src/endo.js
/* global process */
+import fs from 'fs';
import url from 'url';
-import rawFs from 'fs';
+import crypto from 'crypto';
import { Command } from 'commander';
import { start, stop, restart, clean } from '@endo/daemon';
import { whereEndo, whereEndoSock, whereEndoLog } from '@endo/where';
-
-const fs = rawFs.promises;
+import {
+ mapLocation,
+ hashLocation,
+ loadArchive,
+ writeArchive,
+} from '@endo/compartment-mapper';
+import {
+ makeReadPowers,
+ makeWritePowers,
+} from '@endo/compartment-mapper/node-powers.js';
+
+const readPowers = makeReadPowers({ fs, url, crypto });
+const writePowers = makeWritePowers({ fs, url });
+const { write } = writePowers;
const packageDescriptorPath = url.fileURLToPath(
new URL('../package.json', import.meta.url),
@@ -21,7 +34,9 @@ export const main = async rawArgs => {
program.storeOptionsAsProperties(false);
- const packageDescriptorBytes = await fs.readFile(packageDescriptorPath);
+ const packageDescriptorBytes = await fs.promises.readFile(
+ packageDescriptorPath,
+ );
const packageDescriptor = JSON.parse(packageDescriptorBytes);
program.name(packageDescriptor.name).version(packageDescriptor.version);
@@ -53,6 +68,46 @@ export const main = async rawArgs => {
await clean();
});
+ program
+ .command('map <application-path>')
+ .action(async (_cmd, [applicationPath]) => {
+ const applicationLocation = url.pathToFileURL(applicationPath);
+ const compartmentMapBytes = await mapLocation(
+ readPowers,
+ applicationLocation,
+ );
+ process.stdout.write(compartmentMapBytes);
+ });
+
+ program
+ .command('hash <application-path>')
+ .action(async (_cmd, [applicationPath]) => {
+ const applicationLocation = url.pathToFileURL(applicationPath);
+ const sha512 = await hashLocation(readPowers, applicationLocation);
+ process.stdout.write(`${sha512}\n`);
+ });
+
+ program
+ .command('hash-archive <archive-path>')
+ .action(async (_cmd, [archivePath]) => {
+ const archiveLocation = url.pathToFileURL(archivePath);
+ const { sha512 } = await loadArchive(readPowers, archiveLocation);
+ process.stdout.write(`${sha512}\n`);
+ });
+
+ program
+ .command('archive <archive-path> <application-path>')
+ .action(async (_cmd, [archivePath, applicationPath]) => {
+ const archiveLocation = url.pathToFileURL(archivePath);
+ const applicationLocation = url.pathToFileURL(applicationPath);
+ await writeArchive(
+ write,
+ readPowers,
+ archiveLocation,
+ applicationLocation,
+ );
+ });
+
// Throw an error instead of exiting directly.
program.exitOverride();

refactor: Move archive management commands to Endo CLI