Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create NPM and NPX Scripts #45

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion containers.txt

This file was deleted.

File renamed without changes.
21 changes: 2 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
"module": "./dist/index.js",
"types": "./dist/types/index.d.ts",
"bin": {
"drpm": "dist/cli/drpm.js"
"drpm": "./dist/esm/cli/drpm.js",
"create-dpk": "./dist/esm/cli/create-dpk.js"
},
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/cjs/index.js",
"package.json": "./package.json"
"require": "./dist/cjs/index.js"
}
},
"homepage": "https://drpm.tools",
Expand Down Expand Up @@ -87,11 +87,12 @@
},
"scripts": {
"dev": "nodemon",
"start": "node ./dist/registry/server.js",
"prepack": "npm run build && npm run cli:version && chmod +x ./dist/cli/drpm.js",
"postinstall": "curl -fsSL https://raw.githubusercontent.com/bnonni/drpm.tools/refs/heads/main/setup.sh | sh",
"start": "node ./dist/esm/registry/server.js",
"prepack": "npm run build && chmod +x ./dist/esm/cli/drpm.js ./dist/esm/cli/create-dpk.js ./dist/esm/cli/init-dpk.js",
"clean": "rimraf dist coverage tests/compiled",
"wipe": "rimraf node_modules package-lock.json DATA",
"create": "npm create dpk",
"init-dpk": "npx init-dpk",
"tab:1-setup-npmrc": "[[ -f ~/.npmrc ]] && cp ~/.npmrc ~/.npmrc.drpm.bak || cp .npmrc ~/.npmrc",
"tab:2-start-dwn": "sh build/docker.sh",
"tab:3-create-did": "./dist/cli/drpm.js profile create -e http://localhost:3000",
Expand All @@ -114,7 +115,6 @@
"docker:run": "docker run -d --rm --network drpm-network -p 2092:2092 --name drpm-registry registry.digitalocean.com/nonni/drpm-registry"
},
"dependencies": {
"@bugsnag/cuid": "^3.1.1",
"@inquirer/prompts": "^7.0.1",
"@tbd54566975/dwn-sdk-js": "^0.5.1",
"@web5/agent": "^0.8.1",
Expand Down Expand Up @@ -164,4 +164,4 @@
"typescript": "^5.6.2",
"typescript-eslint": "^8.5.0"
}
}
}
24 changes: 0 additions & 24 deletions profile.json.template

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/cli/commands/connect.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DWeb5 } from '../../drpm/dweb5.js';
import { Profile } from '../../drpm/profile.js';
import { DWeb5 } from '../../lib/dweb5.js';
import { Profile } from '../../lib/profile.js';
import { ICommand } from '../drpm.js';

export class ConnectCommand implements ICommand {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Profile } from '../../drpm/profile.js';
import { Profile } from '../../lib/profile.js';
import { Logger } from '../../utils/logger.js';
import { ICommand } from '../drpm.js';
import { DRegistryPackageManagerError } from './error.js';
Expand Down
6 changes: 3 additions & 3 deletions src/cli/commands/dwn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DWeb5 } from '../../drpm/dweb5.js';
import { DwnProtocols, DwnRecords, DwnSync } from '../../drpm/dwn.js';
import { Profile } from '../../drpm/profile.js';
import { DWeb5 } from '../../lib/dweb5.js';
import { DwnProtocols, DwnRecords, DwnSync } from '../../lib/dwn.js';
import { Profile } from '../../lib/profile.js';
import { Logger } from '../../utils/logger.js';
import { DRegistryPackageManagerError } from './error.js';

Expand Down
114 changes: 13 additions & 101 deletions src/cli/commands/package.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { DWeb5, Web5Connection } from '../../drpm/dweb5.js';
import { Profile } from '../../drpm/profile.js';
import dwn from '../../utils/dwn/protocol.js';
import { DWeb5 } from '../../lib/dweb5.js';
import { Package } from '../../lib/package.js';
import { Profile } from '../../lib/profile.js';
import { Logger } from '../../utils/logger.js';
import { ResponseUtils } from '../../utils/response.js';
import { DpkMetadata } from '../../utils/types.js';
import { ICommand } from '../drpm.js';
import { DRegistryPackageManagerError } from './error.js';

export class PackageCommand implements ICommand {
async execute(options: any, subcommand?: string): Promise<void> {
async execute({ options, subcommand }: { options?: any; subcommand?: string}): Promise<void> {
try {
const name = options.name ?? Profile.loadStaticSync().name;
options.connection = await DWeb5.connect({ name });
console.log('PackageCommand: execute => options, subcommand', options, subcommand);
options.connection = await DWeb5.connect({ name: options.name ?? Profile.loadStaticSync().name });
switch (subcommand) {
case 'init':
case 'create':
await this.init(options);
await Package.init(options);
break;
case 'publish':
await this.publish(options);
case 'publish metadata':
await Package.metadata(options);
break;
case 'publish release':
await Package.release(options);
break;
case 'run':
await this.run(options);
await Package.run(options);
break;
default:
throw new DRegistryPackageManagerError(`PackageCommand: Unknown subcommand ${subcommand}`);
Expand All @@ -31,93 +32,4 @@ export class PackageCommand implements ICommand {
throw error;
}
}

async init(options: any): Promise<void> {
throw new Error('PackageCommand: init not implemented: ' + options);
}

async run(options: any): Promise<void> {
throw new Error('PackageCommand: run not implemented: ' + options);
}

async publish(options: any): Promise<void> {
if(options.type === 'package') {
await this.package(options);
} else if(['release', 'package/release'].includes(options.type)) {
await this.release(options);
} else {
await this.package(options);
await this.release(options);
}
}

async package(params: { metadata: DpkMetadata; connection: Web5Connection }) {
try {
const { metadata, connection: { web5, did } } = params ?? {};
const { 'dist-tags': distTags, name } = metadata ?? {};
const { record: _package = null, status } = await web5.dwn.records.create({
store : true,
data : metadata,
message : {
published : true,
dataFormat : 'application/json',
schema : dwn.types.package.schema,
protocolPath : 'package',
protocol : dwn.protocol,
tags : { name, latest: distTags.latest },
},
});

if (ResponseUtils.dwnFail({ status }) || !_package) {
Logger.error('Failed to create local package record', status);
throw new Error('Failed to create package record');
}

const {status: sent} = await _package.send(did);
Logger.log('Package record created and sent to remote!', {status, sent});

} catch (error: any) {
Logger.error('Error during package record creation', error);
throw error;
}
}

async release(options: {
parentId: string;
name: string;
version: string;
integrity: string;
data: any
connection: Web5Connection;
}) {
try {
const { parentId, name, version, integrity, data, connection: { web5, did } } = options ?? {};
const { record: release = null, status } = await web5.dwn.records.create({
data,
store : true,
message : {
published : true,
parentContextId : parentId,
dataFormat : 'application/gzip',
schema : dwn.types.release.schema,
protocolPath : 'package/release',
protocol : dwn.protocol,
tags : { name, version, integrity }
},
});

if (ResponseUtils.dwnFail({ status }) || !release) {
Logger.error('Failed to create local release record', status);
throw new Error('Failed to create release record');
}

Logger.log('Local release record created!', status);
const {status: sent} = await release.send(did);
Logger.log('Release record created and sent to remote!', {status, sent});

} catch (error: any) {
Logger.error('Error during release record creation', error);
throw error;
}
}
}
2 changes: 1 addition & 1 deletion src/cli/commands/profile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Profile } from '../../drpm/profile.js';
import { Profile } from '../../lib/profile.js';
import { Logger } from '../../utils/logger.js';
import { ICommand } from '../drpm.js';
import { DRegistryPackageManagerError } from './error.js';
Expand Down
11 changes: 11 additions & 0 deletions src/cli/create-dpk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env node

import { Package } from '../lib/package.js';
import { Logger } from '../utils/logger.js';

try {
await Package.init();
} catch (error: any) {
Logger.error(error.message);
process.exit(1);
}
Loading