/
near
executable file
·117 lines (108 loc) · 2.68 KB
/
near
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env node
const yargs = require('yargs');
const main = require('../');
const exitOnError = async function(promise) {
try {
await promise;
} catch (e) {
console.log("Error: ", e);
process.exit(1);
}
}
const deploy = {
command: 'deploy',
desc: 'deploy your smart contract',
builder: (yargs) => yargs
.option('wasmFile', {
desc: 'Path to wasm file to deploy',
type: 'string',
default: './out/main.wasm'
}),
handler: (argv) => exitOnError(main.deploy(argv))
};
const { spawn } = require('child_process');
const build = {
command: 'build',
desc: 'build your smart contract',
handler: (argv) => {
const gulp = spawn('gulp');
gulp.stdout.on('data', function (data) {
console.log(data.toString());
});
gulp.stderr.on('data', function (data) {
console.log(data.toString());
});
gulp.on('exit', function (code) {
process.exit(code);
});
}
};
const createAccount = {
command: 'create_account',
desc: 'create a developer account',
builder: (yargs) => yargs
.option('accountId', {
desc: 'Unique identifier for the newly created account',
type: 'string',
required: true
}),
handler: (argv) => exitOnError(main.createDevAccount(argv))
};
const clean = {
command: 'clean',
desc: 'clean the build environment',
builder: (yargs) => yargs
.option('outDir', {
desc: 'build directory',
type: 'string',
default: './out'
}),
handler: (argv) => exitOnError(main.clean(argv))
};
const newProject = {
command: 'new_project',
desc: 'create a new blank project',
builder: (yargs) => yargs
.option('projectDir', {
desc: 'project directory',
type: 'string',
default: '.'
}),
handler: (argv) => exitOnError(main.newProject(argv))
};
let config = require('../get-config')();
yargs // eslint-disable-line
.option('nodeUrl', {
desc: 'NEAR node URL',
type: 'string',
default: 'http://localhost:3030'
})
.option('helperUrl', {
desc: 'NEAR contract helper URL',
type: 'string',
})
.option('useDevAccount', {
desc: 'Forces use of special "developer" account (only works on local node)',
type: 'boolean',
})
.option('accountId', {
desc: 'Unique identifier for the account',
type: 'string',
})
.command(createAccount)
.command(build)
.command(deploy)
.command(clean)
.command(newProject)
.config(config)
.alias({
'accountId': ['account_id', 'contractName', 'contract_name'],
'nodeUrl': 'node_url',
'wasmFile': 'wasm_file',
'projectDir': 'project_dir',
'outDir': 'out_dir'
})
.showHelpOnFail(true)
.demandCommand(1, 'Please enter a command')
.strict()
.argv;