Skip to content

Commit

Permalink
refactor: Consolidate Endo CLI (merge #1016)
Browse files Browse the repository at this point in the history
  • Loading branch information
kriskowal authored Jan 26, 2022
2 parents c5cd72c + 2e7d692 commit cc8c541
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 832 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"packages/cli",
"packages/compartment-mapper",
"packages/daemon",
"packages/endo",
"packages/eslint-config",
"packages/eslint-plugin",
"packages/eventual-send",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"dependencies": {
"@endo/daemon": "^0.1.2",
"@endo/where": "^0.1.2",
"@endo/compartment-mapper": "^0.6.2",
"commander": "^5.0.0"
},
"devDependencies": {
Expand Down
63 changes: 59 additions & 4 deletions packages/cli/src/endo.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
/* 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),
Expand All @@ -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);

Expand Down Expand Up @@ -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();

Expand Down
167 changes: 0 additions & 167 deletions packages/endo/CHANGELOG.md

This file was deleted.

Loading

0 comments on commit cc8c541

Please sign in to comment.