Skip to content

Commit 3ca11ab

Browse files
committed
[CLI] create app command
1 parent fb0eb44 commit 3ca11ab

File tree

13 files changed

+3221
-34
lines changed

13 files changed

+3221
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe("WAO", function () {
147147
it("should spawn a process and send messages", async () => {
148148
const ao = await new AO().init(acc[0])
149149
const { p } = await ao.deploy({ src_data })
150-
assert.equal(await p.d("Hello", "Hello, World!")
150+
assert.equal(await p.d("Hello", false), "Hello, World!")
151151
})
152152
})
153153
```

app/components/Global.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { AO, acc } from "wao/web"
5454
// guide
5555
import { bps, bfiles } from "/lib/guide"
5656

57-
const tg = m => m?.msg?.Tags ?? m.tags ?? m.Tags ?? []
57+
const tg = m => m?.msg?.Tags ?? m?.tags ?? m?.tags ?? []
5858

5959
export default function Global({}) {
6060
g.filesRef = useRef(null)

app/public/docs/tutorials/use-sdk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe("WAO", function () {
1818
it("should spawn a process and send messages", async () => {
1919
const ao = await new AO().init(acc[0])
2020
const { p } = await ao.deploy({ src_data })
21-
assert.equal(await p.d("Hello", "Hello, World!")
21+
assert.equal(await p.d("Hello", false), "Hello, World!")
2222
})
2323
})
2424
```

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "wao",
3-
"version": "0.19.2",
3+
"version": "0.19.6",
44
"bin": "./src/cli.js",
55
"type": "module",
66
"main": "dist/cjs/index.js",
77
"module": "dist/src/index.js",
88
"scripts": {
9-
"build:cjs": "babel src --out-dir dist/cjs --config-file ./.babelrc-cjs && cp src/waosm-node/waosm_bg.wasm dist/cjs/waosm-node/",
10-
"build": "rm -rf dist && npm run build:cjs && cp src -rf dist/esm && node make.js && cp .npmignore dist/ && cp src/lua/* dist/cjs/lua -rf",
9+
"build:cjs": "babel src --out-dir dist/cjs --config-file ./.babelrc-cjs && cp src/waosm-node/waosm_bg.wasm dist/cjs/waosm-node/ && rm -rf dist/cjs/workspace && cp -rf src/workspace dist/cjs/",
10+
"build": "rm -rf dist && npm run build:cjs && cp src -rf dist/esm && node make.js && cp .npmignore dist/ && cp src/lua/* dist/cjs/lua -rf && rm -rf dist/esm/workspace && cp -rf src/workspace dist/esm/",
1111
"test": "node --experimental-wasm-memory64",
1212
"test-only": "node --experimental-wasm-memory64 --test-only",
1313
"server": "node cli-esm.js"

src/cli.js

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,79 @@ import pm2 from "pm2"
33
import { dirname } from "./utils.js"
44
import { resolve } from "path"
55
const args = process.argv.slice(2)
6+
import util from "node:util"
7+
import { exec as _exec } from "node:child_process"
8+
const exec = util.promisify(_exec)
9+
import { cpSync, existsSync } from "fs"
610

711
const cmds = {
812
wao: { script: "run.js" },
913
hub: { script: "hub/index.js" },
1014
fs: { script: "hub/fs.js" },
1115
proxy: { script: "hub/ws-proxy.js" },
16+
create: { script: "create.js" },
1217
}
1318

1419
const cmd = cmds[args[0]] ?? cmds["wao"]
20+
const isCreate = args[0] === "create"
1521
if (cmds[args[0]]) args.shift()
1622

1723
if (!cmd) {
1824
console.log("The wrong command")
1925
process.exit()
2026
}
2127

22-
pm2.connect(false, async err => {
23-
if (err) {
24-
console.error("Error connecting to PM2:", err)
25-
process.exit(2)
28+
const create = async () => {
29+
const appname = args[0] ?? "waoapp"
30+
const appdir = resolve(process.cwd(), appname)
31+
if (existsSync(appdir)) return console.error(`appdir exists: ${appdir}`)
32+
const app = resolve(await dirname(), "workspace")
33+
try {
34+
cpSync(app, appdir, { recursive: true })
35+
const { error, stdout, stderr } = await exec(`cd ${appdir} && yarn`)
36+
if (error) {
37+
console.error(`something went wrong...`)
38+
} else {
39+
console.log(`${appname} successfully created!`)
40+
}
41+
} catch (e) {
42+
console.error(e)
2643
}
44+
}
2745

28-
pm2.start(
29-
{
30-
script: resolve(await dirname(), cmd.script),
31-
nodeArgs: "--experimental-wasm-memory64",
32-
instances: 1,
33-
force: true,
34-
args: args,
35-
daemon: false,
36-
name: "wao",
37-
},
38-
err => {
39-
if (err) {
40-
console.error("Error starting process:", err)
41-
pm2.disconnect()
42-
process.exit(2)
43-
}
46+
if (isCreate) create()
47+
else {
48+
pm2.connect(false, async err => {
49+
if (err) {
50+
console.error("Error connecting to PM2:", err)
51+
process.exit(2)
4452
}
45-
)
46-
pm2.streamLogs("all", 0, false)
47-
})
4853

49-
process.on("SIGINT", () => {
50-
pm2.delete("wao", err => {
51-
pm2.disconnect()
52-
process.exit(err ? 1 : 0)
54+
pm2.start(
55+
{
56+
script: resolve(await dirname(), cmd.script),
57+
nodeArgs: "--experimental-wasm-memory64",
58+
instances: 1,
59+
force: true,
60+
args: args,
61+
daemon: false,
62+
name: "wao",
63+
},
64+
err => {
65+
if (err) {
66+
console.error("Error starting process:", err)
67+
pm2.disconnect()
68+
process.exit(2)
69+
}
70+
}
71+
)
72+
pm2.streamLogs("all", 0, false)
5373
})
54-
})
74+
75+
process.on("SIGINT", () => {
76+
pm2.delete("wao", err => {
77+
pm2.disconnect()
78+
process.exit(err ? 1 : 0)
79+
})
80+
})
81+
}

src/create.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
import util from "node:util"
3+
import { exec as _exec } from "node:child_process"
4+
const exec = util.promisify(_exec)
5+
import { cpSync, existsSync } from "fs"
6+
import { resolve } from "path"
7+
import { dirname } from "./utils.js"
8+
9+
const main = async () => {
10+
const appname = process.argv[2] ?? "waoapp"
11+
const appdir = resolve(process.cwd(), appname)
12+
if (existsSync(appdir)) return console.error(`appdir exists: ${appdir}`)
13+
const app = resolve(await dirname(), "workspace")
14+
try {
15+
cpSync(app, appdir, { recursive: true })
16+
const { error, stdout, stderr } = await exec(`cd ${appdir} && yarn`)
17+
if (error) {
18+
console.error(`something went wrong...`)
19+
} else {
20+
console.log(`${appname} successfully created!`)
21+
}
22+
} catch (e) {
23+
console.error(e)
24+
}
25+
}
26+
27+
main()

src/workspace/.gitignore

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
.wallet.json
2+
.db/
3+
4+
# Logs
5+
logs
6+
*.log
7+
npm-debug.log*
8+
yarn-debug.log*
9+
yarn-error.log*
10+
lerna-debug.log*
11+
.pnpm-debug.log*
12+
13+
# Diagnostic reports (https://nodejs.org/api/report.html)
14+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
15+
16+
# Runtime data
17+
pids
18+
*.pid
19+
*.seed
20+
*.pid.lock
21+
22+
# Directory for instrumented libs generated by jscoverage/JSCover
23+
lib-cov
24+
25+
# Coverage directory used by tools like istanbul
26+
coverage
27+
*.lcov
28+
29+
# nyc test coverage
30+
.nyc_output
31+
32+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
33+
.grunt
34+
35+
# Bower dependency directory (https://bower.io/)
36+
bower_components
37+
38+
# node-waf configuration
39+
.lock-wscript
40+
41+
# Compiled binary addons (https://nodejs.org/api/addons.html)
42+
build/Release
43+
44+
# Dependency directories
45+
node_modules/
46+
jspm_packages/
47+
48+
# Snowpack dependency directory (https://snowpack.dev/)
49+
web_modules/
50+
51+
# TypeScript cache
52+
*.tsbuildinfo
53+
54+
# Optional npm cache directory
55+
.npm
56+
57+
# Optional eslint cache
58+
.eslintcache
59+
60+
# Optional stylelint cache
61+
.stylelintcache
62+
63+
# Microbundle cache
64+
.rpt2_cache/
65+
.rts2_cache_cjs/
66+
.rts2_cache_es/
67+
.rts2_cache_umd/
68+
69+
# Optional REPL history
70+
.node_repl_history
71+
72+
# Output of 'npm pack'
73+
*.tgz
74+
75+
# Yarn Integrity file
76+
.yarn-integrity
77+
78+
# dotenv environment variable files
79+
.env
80+
.env.development.local
81+
.env.test.local
82+
.env.production.local
83+
.env.local
84+
85+
# parcel-bundler cache (https://parceljs.org/)
86+
.cache
87+
.parcel-cache
88+
89+
# Next.js build output
90+
.next
91+
out
92+
93+
# Nuxt.js build / generate output
94+
.nuxt
95+
dist
96+
97+
# Gatsby files
98+
.cache/
99+
# Comment in the public line in if your project uses Gatsby and not Next.js
100+
# https://nextjs.org/blog/next-9-1#public-directory-support
101+
# public
102+
103+
# vuepress build output
104+
.vuepress/dist
105+
106+
# vuepress v2.x temp and cache directory
107+
.temp
108+
.cache
109+
110+
# Docusaurus cache and generated files
111+
.docusaurus
112+
113+
# Serverless directories
114+
.serverless/
115+
116+
# FuseBox cache
117+
.fusebox/
118+
119+
# DynamoDB Local files
120+
.dynamodb/
121+
122+
# TernJS port file
123+
.tern-port
124+
125+
# Stores VSCode versions used for testing VSCode extensions
126+
.vscode-test
127+
128+
# yarn v2
129+
.yarn/cache
130+
.yarn/unplugged
131+
.yarn/build-state.yml
132+
.yarn/install-state.gz
133+
.pnp.*

src/workspace/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#### 1. Create an APP
2+
3+
```bash
4+
npx wao create waoapp && cd waoapp
5+
```
6+
7+
#### 2. Run WAO Proxy
8+
9+
```bash
10+
npx wao proxy
11+
```
12+
13+
#### 3. Connect the Browser to the Proxy
14+
15+
Go to [the web app](https://wao-localnet.vercel.app/) and open `Networks`, then click `Proxy`.
16+
17+
#### 4. Run Test
18+
19+
```bash
20+
yarn test test/test.js
21+
```
22+
23+
#### 5. Deploy a Process to AO Testnet
24+
25+
```bash
26+
yarn deploy src/counter.lua --wallet PATH_TO_WALLET_JSON
27+
```

src/workspace/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "wao-workspace",
3+
"version": "0.0.1",
4+
"type": "module",
5+
"scripts": {
6+
"test": "node --experimental-wasm-memory64",
7+
"test-only": "node --experimental-wasm-memory64 --test-only",
8+
"deploy": "node scripts/deploy.js"
9+
},
10+
"dependencies": {
11+
"wao": "^0.19.6"
12+
}
13+
}

src/workspace/scripts/deploy.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { AO } from "wao"
2+
const lua = process.argv[2]
3+
4+
import { readFileSync } from "fs"
5+
import { resolve } from "path"
6+
import yargs from "yargs"
7+
8+
let { wallet = null } = yargs(process.argv.slice(2)).argv
9+
10+
let src_data = null
11+
try {
12+
src_data = readFileSync(resolve(process.cwd(), lua), "utf-8")
13+
} catch (e) {
14+
console.log("lua script not found")
15+
process.exit()
16+
}
17+
18+
let jwk = null
19+
try {
20+
jwk = JSON.parse(readFileSync(resolve(process.cwd(), wallet), "utf-8"))
21+
} catch (e) {
22+
console.log("wallet not found")
23+
process.exit()
24+
}
25+
26+
const deploy = async () => {
27+
const ao = await new AO().init(jwk)
28+
const { pid, p } = await ao.deploy({ src_data })
29+
console.log("process deployed!", pid)
30+
31+
//console.log(await p.m("Inc", false))
32+
//console.log(await p.d("Get", false))
33+
}
34+
35+
deploy()

0 commit comments

Comments
 (0)