Skip to content

Commit

Permalink
Merge pull request #649 from Agoric/646-dapp-simple-exchange
Browse files Browse the repository at this point in the history
Create a Simple Exchange dApp
  • Loading branch information
michaelfig authored Mar 4, 2020
2 parents 03c054b + 700c3a9 commit 6dd0ca3
Show file tree
Hide file tree
Showing 94 changed files with 4,740 additions and 42,409 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
run: cd packages/captp && yarn test
- name: yarn test (cosmic-swingset)
run: cd packages/cosmic-swingset && yarn test
- name: yarn test (dapp-simple-exchange)
run: cd packages/dapp-simple-exchange && yarn test
- name: yarn test (default-evaluate-options)
run: cd packages/default-evaluate-options && yarn test
- name: yarn test (deployment)
Expand All @@ -85,8 +87,6 @@ jobs:
run: cd packages/same-structure && yarn test
- name: yarn test (sharing-service)
run: cd packages/sharing-service && yarn test
- name: yarn test (simple-exchange-frontend)
run: cd packages/simple-exchange-frontend && yarn test
- name: yarn test (sparse-ints)
run: cd packages/sparse-ints && yarn test
- name: yarn test (spawner)
Expand Down
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,14 @@
"packages/ERTP",
"packages/spawner",
"packages/sharing-service",
"packages/simple-exchange-frontend",
"packages/wallet-frontend",
"packages/zoe",
"packages/cosmic-swingset",
"packages/dapp-simple-exchange",
"packages/dapp-simple-exchange/.agservers",
"packages/dapp-simple-exchange/api",
"packages/dapp-simple-exchange/contract",
"packages/generator-agoric-dapp",
"packages/agoric-cli",
"packages/agoric-cli/template/.agservers",
"packages/agoric-cli/template/api",
"packages/agoric-cli/template/contract",
"packages/agoric-cli/template/ui",
"packages/deployment"
],
"devDependencies": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
56 changes: 43 additions & 13 deletions packages/agoric-cli/lib/init.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
import parseArgs from 'minimist';
import chalk from 'chalk';

const DEFAULT_DAPP_TEMPLATE = '@agoric/dapp-simple-exchange';

export default async function initMain(progname, rawArgs, priv) {
const { console, error, fs } = priv;
const { _: args, force } = parseArgs(rawArgs, { boolean: ['force'] });
const { _: args, force, 'dapp-template': dappTemplate } = parseArgs(rawArgs, {
boolean: ['force'],
default: { 'dapp-template': DEFAULT_DAPP_TEMPLATE },
});

if (args.length !== 1) {
return error(`you must specify exactly one DIR`);
}
const [DIR] = args;

const slashPJson = '/package.json';
const pjson = require.resolve(`${dappTemplate}${slashPJson}`);
const dappRoot = pjson.substr(0, pjson.length - slashPJson.length);

const {
mkdir,
stat,
Expand All @@ -34,15 +43,15 @@ export default async function initMain(progname, rawArgs, priv) {
name === 'node_modules' ||
(suffix === '/.agservers' && name !== 'package.json' && name[0] !== '.');

const writeTemplate = async (templateDir, stem) => {
const writeTemplate = async (templateDir, destDir = DIR, stem) => {
const template = await readFile(`${templateDir}${stem}`, 'utf-8');
const content = template
.replace(/['"]@DIR@['"]/g, JSON.stringify(DIR))
.replace(/@DIR@/g, DIR);
return writeFile(`${DIR}${stem}`, content);
return writeFile(`${destDir}${stem}`, content);
};

const recursiveTemplate = async (templateDir, suffix = '') => {
const recursiveTemplate = async (templateDir, destDir = DIR, suffix = '') => {
const cur = `${templateDir}${suffix}`;
const list = await readdir(cur);
await Promise.all(
Expand All @@ -54,32 +63,53 @@ export default async function initMain(progname, rawArgs, priv) {
const st = await lstat(`${templateDir}${stem}`);
let target;
try {
target = await stat(`${DIR}${stem}`);
target = await stat(`${destDir}${stem}`);
} catch (e) {
if (e.code !== 'ENOENT') {
throw e;
}
}
if (st.isDirectory()) {
if (!target) {
console.log(`mkdir ${DIR}${stem}`);
await mkdir(`${DIR}${stem}`);
console.log(`mkdir ${destDir}${stem}`);
await mkdir(`${destDir}${stem}`);
}
await recursiveTemplate(templateDir, `${stem}`);
await recursiveTemplate(templateDir, destDir, `${stem}`);
} else if (st.isSymbolicLink()) {
console.log(`symlink ${DIR}${stem}`);
console.log(`symlink ${destDir}${stem}`);
await symlink(
await readlink(`${templateDir}${stem}`),
`${DIR}${stem}`,
`${destDir}${stem}`,
);
} else {
console.log(`write ${DIR}${stem}`);
await writeTemplate(templateDir, stem);
console.log(`write ${destDir}${stem}`);
await writeTemplate(templateDir, destDir, stem);
}
}),
);
};
await recursiveTemplate(`${__dirname}/../template`);
await recursiveTemplate(dappRoot);
await mkdir(`${DIR}/.agwallet`);
await recursiveTemplate(`${__dirname}/../agwallet`, `${DIR}/.agwallet`);

const ps = ['', 'api/', 'contract/', 'ui/'].map(dir => {
const path = `${DIR}/${dir}package.json`;
return readFile(path, 'utf-8')
.then(contents => JSON.parse(contents))
.then(pkg => {
if (!pkg.name || !pkg.name.startsWith(dappTemplate)) {
throw Error(
`${path}: "name" must start with ${JSON.stringify(dappTemplate)}`,
);
}
pkg.name = `${DIR}${pkg.name.substr(dappTemplate.length)}`;
const json = JSON.stringify(pkg, undefined, 2);
return writeFile(path, json);
})
.catch(e => console.error(chalk.bold.blue(`Cannot rewrite ${path}`), e));
});

await Promise.all(ps);

console.log(chalk.bold.yellow(`Done initializing`));
return 0;
Expand Down
3 changes: 0 additions & 3 deletions packages/agoric-cli/template/ui/.env.local

This file was deleted.

3 changes: 0 additions & 3 deletions packages/agoric-cli/template/ui/.env.local.example

This file was deleted.

21 changes: 0 additions & 21 deletions packages/agoric-cli/template/ui/.eslintrc

This file was deleted.

14 changes: 0 additions & 14 deletions packages/agoric-cli/template/ui/README.md

This file was deleted.

Loading

0 comments on commit 6dd0ca3

Please sign in to comment.