From 7f46639cba32270084c1467ea69dd1b7c28796da Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 13 Nov 2023 17:33:27 -0600 Subject: [PATCH 1/5] feat(create-dapp): `npm create @agoric/dapp ...` uses `agoric init` --- packages/agoric-cli/src/sdk-package-names.js | 1 + packages/create-dapp/.gitignore | 83 ++++++++++++++++++++ packages/create-dapp/.npmignore | 14 ++++ packages/create-dapp/CHANGELOG.md | 4 + packages/create-dapp/README.md | 23 ++++++ packages/create-dapp/jsconfig.json | 7 ++ packages/create-dapp/package.json | 51 ++++++++++++ packages/create-dapp/src/create-dapp.js | 17 ++++ packages/create-dapp/test/test-stub.js | 3 + 9 files changed, 203 insertions(+) create mode 100644 packages/create-dapp/.gitignore create mode 100644 packages/create-dapp/.npmignore create mode 100644 packages/create-dapp/CHANGELOG.md create mode 100644 packages/create-dapp/README.md create mode 100644 packages/create-dapp/jsconfig.json create mode 100644 packages/create-dapp/package.json create mode 100755 packages/create-dapp/src/create-dapp.js create mode 100644 packages/create-dapp/test/test-stub.js diff --git a/packages/agoric-cli/src/sdk-package-names.js b/packages/agoric-cli/src/sdk-package-names.js index 06a0f9c5ac40..d6b5d4b5b39d 100644 --- a/packages/agoric-cli/src/sdk-package-names.js +++ b/packages/agoric-cli/src/sdk-package-names.js @@ -9,6 +9,7 @@ export default [ "@agoric/cosmic-proto", "@agoric/cosmic-swingset", "@agoric/cosmos", + "@agoric/create-dapp", "@agoric/deploy-script-support", "@agoric/deployment", "@agoric/ertp", diff --git a/packages/create-dapp/.gitignore b/packages/create-dapp/.gitignore new file mode 100644 index 000000000000..bf242669fa4f --- /dev/null +++ b/packages/create-dapp/.gitignore @@ -0,0 +1,83 @@ +.vagrant +/dapps + +# emacs and vim +*~ +[._]*.sw[a-p] + +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next + +.idea/ + +# dist files +/dist + +# generated integration-test files +integration-test/.cache +integration-test/bundles +integration-test/transform-tests/output + +# generated Sphinx/ReadTheDocs files +/docs/build/ +/demo +t[0-9]* diff --git a/packages/create-dapp/.npmignore b/packages/create-dapp/.npmignore new file mode 100644 index 000000000000..6579415ef239 --- /dev/null +++ b/packages/create-dapp/.npmignore @@ -0,0 +1,14 @@ +.vagrant + +# Demo +demo +dapps + +# scripts +scripts + +# test +test + +# Travis CI +.travis.yml diff --git a/packages/create-dapp/CHANGELOG.md b/packages/create-dapp/CHANGELOG.md new file mode 100644 index 000000000000..e4d87c4d45c4 --- /dev/null +++ b/packages/create-dapp/CHANGELOG.md @@ -0,0 +1,4 @@ +# Change Log + +All notable changes to this project will be documented in this file. +See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. diff --git a/packages/create-dapp/README.md b/packages/create-dapp/README.md new file mode 100644 index 000000000000..73e9f792c427 --- /dev/null +++ b/packages/create-dapp/README.md @@ -0,0 +1,23 @@ +# Create Agoric Dapp + +To make a new Agoric Dapp in the `foo` subdirectory, you can use: + +``` +$ yarn create @agoric/dapp foo +``` + +or: + +``` +$ npm create @agoric/dapp foo +``` + +or: + +``` +$ pnpm create @agoric/dapp foo +``` + +Each of the above commands are shorthand for installing the `agoric` package, then running `agoric init foo`. + +Please see the [Getting Started website](https://agoric.com/documentation/getting-started/) for information. diff --git a/packages/create-dapp/jsconfig.json b/packages/create-dapp/jsconfig.json new file mode 100644 index 000000000000..e9c3e53b5d9c --- /dev/null +++ b/packages/create-dapp/jsconfig.json @@ -0,0 +1,7 @@ +// This file can contain .js-specific Typescript compiler config. +{ + "extends": "../../tsconfig.json", + "include": [ + "src/**/*.js", + ], +} diff --git a/packages/create-dapp/package.json b/packages/create-dapp/package.json new file mode 100644 index 000000000000..d9d5df11130a --- /dev/null +++ b/packages/create-dapp/package.json @@ -0,0 +1,51 @@ +{ + "name": "@agoric/create-dapp", + "version": "0.1.0", + "description": "Create an Agoric Javascript smart contract application", + "type": "module", + "bin": { + "create-dapp": "src/create-dapp.js" + }, + "files": [ + "src" + ], + "scripts": { + "build": "exit 0", + "test": "ava", + "test:c8": "c8 $C8_OPTIONS ava --config=ava-nesm.config.js", + "test:xs": "exit 0", + "lint-fix": "yarn lint:eslint --fix", + "lint": "run-s --continue-on-error lint:*", + "lint:types": "tsc -p jsconfig.json", + "lint:eslint": "eslint ." + }, + "devDependencies": { + "ava": "^5.2.0", + "c8": "^7.13.0", + "dd-trace": "^3.3.0" + }, + "dependencies": { + "agoric": "^0.21.2-u12.0" + }, + "keywords": [], + "repository": { + "type": "git", + "url": "git+https://github.com/Agoric/agoric-sdk" + }, + "author": "Agoric", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/Agoric/agoric/agoric-sdk" + }, + "homepage": "https://github.com/Agoric/agoric-sdk#readme", + "ava": { + "files": [ + "test/**/test-*.js" + ], + "timeout": "2m", + "workerThreads": false + }, + "publishConfig": { + "access": "public" + } +} diff --git a/packages/create-dapp/src/create-dapp.js b/packages/create-dapp/src/create-dapp.js new file mode 100755 index 000000000000..4bbb451243d7 --- /dev/null +++ b/packages/create-dapp/src/create-dapp.js @@ -0,0 +1,17 @@ +#! /usr/bin/env node +/* global process */ +import { spawnSync } from 'child_process'; +import { createRequire } from 'module'; + +const require = createRequire(import.meta.url); + +const agoricCli = require.resolve('.bin/agoric'); + +const proc = spawnSync(agoricCli, ['init', ...process.argv.slice(2)], { + stdio: 'inherit', +}); + +if (proc.status === null) { + throw proc.error; +} +process.exit(proc.status); diff --git a/packages/create-dapp/test/test-stub.js b/packages/create-dapp/test/test-stub.js new file mode 100644 index 000000000000..4a05abe39764 --- /dev/null +++ b/packages/create-dapp/test/test-stub.js @@ -0,0 +1,3 @@ +import test from 'ava'; + +test.todo('write some tests'); From 94437bf3e84aad6e9a3bef130eb47da532cba783 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 13 Nov 2023 18:23:37 -0600 Subject: [PATCH 2/5] test(create-dapp): basic init flags sanity test --- .github/workflows/test-all-packages.yml | 2 ++ packages/create-dapp/test/test-sanity.js | 18 ++++++++++++++++++ packages/create-dapp/test/test-stub.js | 3 --- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 packages/create-dapp/test/test-sanity.js delete mode 100644 packages/create-dapp/test/test-stub.js diff --git a/.github/workflows/test-all-packages.yml b/.github/workflows/test-all-packages.yml index 253744c2af45..06b851a52e29 100644 --- a/.github/workflows/test-all-packages.yml +++ b/.github/workflows/test-all-packages.yml @@ -204,6 +204,8 @@ jobs: - name: yarn test (casting) if: (success() || failure()) run: cd packages/casting && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT + - name: yarn test (create-dapp) + run: cd packages/create-dapp && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT - name: yarn test (internal) if: (success() || failure()) run: cd packages/internal && yarn ${{ steps.vars.outputs.test }} | $TEST_COLLECT diff --git a/packages/create-dapp/test/test-sanity.js b/packages/create-dapp/test/test-sanity.js new file mode 100644 index 000000000000..f4424d587686 --- /dev/null +++ b/packages/create-dapp/test/test-sanity.js @@ -0,0 +1,18 @@ +import test from 'ava'; +import { spawnSync } from 'child_process'; +import { fileURLToPath } from 'url'; + +const binname = fileURLToPath( + new URL('../src/create-dapp.js', import.meta.url), +); + +test('sanity', async t => { + await null; + const myMain = args => { + return spawnSync(binname, args, { stdio: 'ignore' }).status; + }; + + t.is(await myMain(['--help']), 0, '--help exits zero'); + t.is(await myMain(['--version']), 0, '--version exits zero'); + t.is(await myMain(['--zorgar']), 1, 'unknown flag fails'); +}); diff --git a/packages/create-dapp/test/test-stub.js b/packages/create-dapp/test/test-stub.js deleted file mode 100644 index 4a05abe39764..000000000000 --- a/packages/create-dapp/test/test-stub.js +++ /dev/null @@ -1,3 +0,0 @@ -import test from 'ava'; - -test.todo('write some tests'); From 037e9f56f3a4bafbb412919ed4e713dd660772e9 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 13 Nov 2023 19:49:44 -0600 Subject: [PATCH 3/5] build(xsnap): detect production mode by absence of `test` dir, not `git status` --- packages/xsnap/package.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/xsnap/package.json b/packages/xsnap/package.json index c85605b5058d..59e66476dfc6 100644 --- a/packages/xsnap/package.json +++ b/packages/xsnap/package.json @@ -1,7 +1,7 @@ { "name": "@agoric/xsnap", "version": "0.14.3-u13.0", - "description": "Description forthcoming.", + "description": "Snapshotting VM worker based on Moddable's XS Javascript engine", "author": "Agoric", "license": "Apache-2.0", "type": "module", @@ -12,8 +12,8 @@ }, "scripts": { "repl": "node src/xsrepl.js", - "build:bin": "if git status >/dev/null 2>&1; then node src/build.js; else yarn build:from-env; fi", - "build:env": "if git status >/dev/null 2>&1; then node src/build.js --show-env > build.env; fi", + "build:bin": "if test -d ./test; then node src/build.js; else yarn build:from-env; fi", + "build:env": "test -d ./test && node src/build.js --show-env > build.env", "build:from-env": "{ cat build.env; echo node src/build.js; } | xargs env", "build": "yarn build:bin && yarn build:env", "postinstall": "yarn build:from-env", From 030e68b829b60b06e90f7a4cfd56ce4d551c3869 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Mon, 13 Nov 2023 20:21:52 -0600 Subject: [PATCH 4/5] fix(agoric-cli): `open` should default to `localhost`, not numeric IPv4 --- packages/agoric-cli/src/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/agoric-cli/src/main.js b/packages/agoric-cli/src/main.js index e46823d51eae..348be6b869a8 100644 --- a/packages/agoric-cli/src/main.js +++ b/packages/agoric-cli/src/main.js @@ -96,7 +96,7 @@ const main = async (progname, rawArgs, powers) => { .option( '--hostport ', 'host and port to connect to VM', - '127.0.0.1:8000', + 'localhost:8000', ) .option('--no-browser', `just display the URL, don't open a browser`) .option( From 7e0dcadb315ecd9f9fe37890d998b56a83912577 Mon Sep 17 00:00:00 2001 From: Michael FIG Date: Wed, 15 Nov 2023 10:04:14 -0600 Subject: [PATCH 5/5] build(agoric-cli): add `tools` subdir to NPM --- packages/agoric-cli/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/agoric-cli/package.json b/packages/agoric-cli/package.json index 85465f429c14..6a46d1ca2178 100644 --- a/packages/agoric-cli/package.json +++ b/packages/agoric-cli/package.json @@ -14,6 +14,7 @@ }, "files": [ "src", + "tools", "exported.js" ], "scripts": {