mobilestacks 0.1.22 → 0.1.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +189 -188
- package/dist/cli/index.js +83 -46
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +51 -38
- package/dist/config/config-loading.d.ts.map +1 -1
- package/dist/config/config-loading.js +14 -9
- package/dist/core/dsl.d.ts +12 -16
- package/dist/core/dsl.d.ts.map +1 -1
- package/dist/core/dsl.js +11 -13
- package/dist/core/env.js +1 -1
- package/dist/core/extender.d.ts +1 -0
- package/dist/core/extender.d.ts.map +1 -1
- package/dist/core/extender.js +3 -0
- package/dist/core/runtime-environment.d.ts +10 -7
- package/dist/core/runtime-environment.d.ts.map +1 -1
- package/dist/core/runtime-environment.js +38 -41
- package/dist/core/simnet.d.ts.map +1 -1
- package/dist/core/simnet.js +0 -2
- package/dist/core/tasks-definitions.d.ts +3 -0
- package/dist/core/tasks-definitions.d.ts.map +1 -1
- package/dist/core/tasks-definitions.js +8 -0
- package/dist/tasks/call-contract-function.js +12 -11
- package/dist/tasks/deploy-contract.js +22 -32
- package/dist/tasks/execute-contract.js +55 -35
- package/dist/tasks/faucet-request.js +10 -12
- package/dist/tasks/get-balance.js +21 -31
- package/dist/tasks/get-contract-info.js +9 -10
- package/dist/tasks/get-tx-history.js +16 -30
- package/dist/tasks/list-accounts.js +16 -15
- package/dist/tasks/send-stx.js +13 -30
- package/dist/tasks/utils.d.ts +22 -0
- package/dist/tasks/utils.d.ts.map +1 -0
- package/dist/tasks/utils.js +88 -0
- package/dist/tasks/verify-contract.js +12 -16
- package/dist/types/config.d.ts +1 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js +0 -2
- package/package.json +71 -71
- package/dist/core/dsl.test.d.ts +0 -2
- package/dist/core/dsl.test.d.ts.map +0 -1
- package/dist/core/dsl.test.js +0 -50
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 mobilestacks contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mobilestacks contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,188 +1,189 @@
|
|
|
1
|
-
# mobilestacks
|
|
2
|
-
|
|
3
|
-
A Hardhat-style development framework for Stacks. Write, test, and deploy Clarity smart contracts with a task-based CLI, local Simnet testing, and a pluggable runtime.
|
|
4
|
-
|
|
5
|
-
## Install
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install mobilestacks
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Quick Start
|
|
12
|
-
|
|
13
|
-
Scaffold a new project:
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npx mobilestacks init
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
This generates a config file, a sample Clarity contract, and an example task.
|
|
20
|
-
|
|
21
|
-
## Configuration
|
|
22
|
-
|
|
23
|
-
All config lives in `mobilestacks.config.ts`:
|
|
24
|
-
|
|
25
|
-
```ts
|
|
26
|
-
export default {
|
|
27
|
-
networks: {
|
|
28
|
-
mainnet: { url:
|
|
29
|
-
testnet: { url:
|
|
30
|
-
},
|
|
31
|
-
defaultNetwork:
|
|
32
|
-
wallet: {
|
|
33
|
-
privateKey: process.env.STACKS_PRIVATE_KEY,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
Secrets can live in `.env
|
|
39
|
-
|
|
40
|
-
## CLI
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
npx mobilestacks # list all tasks
|
|
44
|
-
npx mobilestacks deploy-contract # deploy a contract
|
|
45
|
-
npx mobilestacks get-balance # check STX balance
|
|
46
|
-
npx mobilestacks send-stx # send STX
|
|
47
|
-
npx mobilestacks faucet-request # get testnet tokens
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Missing params are prompted interactively. Run any task with `--help` for options.
|
|
51
|
-
|
|
52
|
-
### Built-in Tasks
|
|
53
|
-
|
|
54
|
-
| Task | What it does |
|
|
55
|
-
| ---- | ------------ |
|
|
56
|
-
| `deploy-contract` | Deploy a `.clar` file to mainnet/testnet |
|
|
57
|
-
| `send-stx` | Transfer STX to an address |
|
|
58
|
-
| `get-balance` | Check STX balance for any address |
|
|
59
|
-
| `faucet-request` | Request testnet STX from the faucet |
|
|
60
|
-
| `list-accounts` | List derived wallet accounts |
|
|
61
|
-
| `get-tx-history` | Fetch recent transactions |
|
|
62
|
-
| `call-contract-function` | Call a read-only contract function |
|
|
63
|
-
| `get-contract-info` | Fetch deployed contract metadata |
|
|
64
|
-
| `verify-contract` | Diff on-chain source against a local file |
|
|
65
|
-
|
|
66
|
-
## Writing Tasks
|
|
67
|
-
|
|
68
|
-
Drop a file in `src/tasks
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
import { task } from
|
|
72
|
-
import { z } from
|
|
73
|
-
|
|
74
|
-
task(
|
|
75
|
-
.addParam(
|
|
76
|
-
.setAction(
|
|
77
|
-
return `Hello, ${args.name}! (network: ${env.config.defaultNetwork})`;
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
Subtasks and workflows are also supported:
|
|
82
|
-
|
|
83
|
-
```ts
|
|
84
|
-
import { subtask, runWorkflow } from
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
],
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
extendEnvironment
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
import {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
```
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
npm
|
|
177
|
-
npm
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
1
|
+
# mobilestacks
|
|
2
|
+
|
|
3
|
+
A Hardhat-style development framework for Stacks. Write, test, and deploy Clarity smart contracts with a task-based CLI, local Simnet testing, and a pluggable runtime.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install mobilestacks
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
Scaffold a new project:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx mobilestacks init
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This generates a config file, a sample Clarity contract, and an example task.
|
|
20
|
+
|
|
21
|
+
## Configuration
|
|
22
|
+
|
|
23
|
+
All config lives in `mobilestacks.config.ts`:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
export default {
|
|
27
|
+
networks: {
|
|
28
|
+
mainnet: { url: 'https://api.mainnet.hiro.so', name: 'mainnet' },
|
|
29
|
+
testnet: { url: 'https://api.testnet.hiro.so', name: 'testnet' },
|
|
30
|
+
},
|
|
31
|
+
defaultNetwork: 'testnet',
|
|
32
|
+
wallet: {
|
|
33
|
+
privateKey: process.env.STACKS_PRIVATE_KEY,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Secrets can live in `.env`; they override config values automatically.
|
|
39
|
+
|
|
40
|
+
## CLI
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx mobilestacks # list all tasks
|
|
44
|
+
npx mobilestacks deploy-contract # deploy a contract
|
|
45
|
+
npx mobilestacks get-balance # check STX balance
|
|
46
|
+
npx mobilestacks send-stx # send STX
|
|
47
|
+
npx mobilestacks faucet-request # get testnet tokens
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Missing required params are prompted interactively. Run any task with `--help` for options.
|
|
51
|
+
|
|
52
|
+
### Built-in Tasks
|
|
53
|
+
|
|
54
|
+
| Task | What it does |
|
|
55
|
+
| ---- | ------------ |
|
|
56
|
+
| `deploy-contract` | Deploy a `.clar` file to mainnet/testnet |
|
|
57
|
+
| `send-stx` | Transfer STX to an address |
|
|
58
|
+
| `get-balance` | Check STX balance for any address |
|
|
59
|
+
| `faucet-request` | Request testnet STX from the faucet |
|
|
60
|
+
| `list-accounts` | List derived wallet accounts |
|
|
61
|
+
| `get-tx-history` | Fetch recent transactions |
|
|
62
|
+
| `call-contract-function` | Call a read-only contract function |
|
|
63
|
+
| `get-contract-info` | Fetch deployed contract metadata |
|
|
64
|
+
| `verify-contract` | Diff on-chain source against a local file |
|
|
65
|
+
|
|
66
|
+
## Writing Tasks
|
|
67
|
+
|
|
68
|
+
Drop a file in `src/tasks/`; it is auto-discovered:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import { task } from 'mobilestacks';
|
|
72
|
+
import { z } from 'zod';
|
|
73
|
+
|
|
74
|
+
task('greet', 'Say hello')
|
|
75
|
+
.addParam('name', 'Who to greet', { schema: z.string().min(1) })
|
|
76
|
+
.setAction((args, env) => {
|
|
77
|
+
return `Hello, ${args.name}! (network: ${env.config.defaultNetwork})`;
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Subtasks and workflows are also supported:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { subtask, runWorkflow } from 'mobilestacks';
|
|
85
|
+
|
|
86
|
+
subtask('deploy:validate', 'Pre-deploy check', 'deploy-contract').setAction((args, env) => {
|
|
87
|
+
// validate deployment inputs
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await runWorkflow(
|
|
91
|
+
[
|
|
92
|
+
{ taskName: 'deploy-contract', args: { contractName: 'sample-contract' } },
|
|
93
|
+
{ taskName: 'verify-contract', args: { contractName: 'sample-contract' } },
|
|
94
|
+
],
|
|
95
|
+
env,
|
|
96
|
+
);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Extending the Runtime
|
|
100
|
+
|
|
101
|
+
Add custom properties to the runtime environment, available in every task:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
import { extendEnvironment } from 'mobilestacks';
|
|
105
|
+
|
|
106
|
+
extendEnvironment((env) => {
|
|
107
|
+
env.formatSTX = (micro: number) => `${(micro / 1e6).toFixed(6)} STX`;
|
|
108
|
+
});
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Testing with Simnet
|
|
112
|
+
|
|
113
|
+
Test contracts locally using the Clarinet SDK. No devnet is needed:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
import { describe, it, expect, beforeAll } from 'vitest';
|
|
117
|
+
import { Simnet } from 'mobilestacks';
|
|
118
|
+
import { Cl } from '@stacks/transactions';
|
|
119
|
+
|
|
120
|
+
describe('My Contract', () => {
|
|
121
|
+
let simnet: Simnet;
|
|
122
|
+
|
|
123
|
+
beforeAll(async () => {
|
|
124
|
+
simnet = await Simnet.init();
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('calls hello-world', () => {
|
|
128
|
+
const deployer = simnet.getDeployer();
|
|
129
|
+
const { result } = simnet.callPublic('sample-contract', 'hello-world', [], deployer);
|
|
130
|
+
expect(result).toStrictEqual(Cl.ok(Cl.stringAscii('Hello, Stacks!')));
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Setup
|
|
136
|
+
|
|
137
|
+
Contract tests need a `Clarinet.toml` and test accounts. Run the setup script once:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npm run setup:simnet
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Then run tests:
|
|
144
|
+
|
|
145
|
+
```bash
|
|
146
|
+
npm test
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Programmatic API
|
|
150
|
+
|
|
151
|
+
Use mobilestacks as a library:
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
import { task, subtask, extendEnvironment, Simnet, RuntimeEnvironment } from 'mobilestacks';
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Project Structure
|
|
158
|
+
|
|
159
|
+
```text
|
|
160
|
+
src/
|
|
161
|
+
cli/ CLI entry point and init scaffolding
|
|
162
|
+
core/ DSL, Simnet, RuntimeEnvironment, task registry
|
|
163
|
+
tasks/ Built-in tasks
|
|
164
|
+
types/ Zod schemas and TypeScript types
|
|
165
|
+
index.ts Public API
|
|
166
|
+
tests/ Vitest test files
|
|
167
|
+
contracts/ Clarity contracts
|
|
168
|
+
Clarinet.toml Clarinet project manifest
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Contributing
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
git clone https://github.com/Wizbisy/mobilestacks.git
|
|
175
|
+
cd mobilestacks
|
|
176
|
+
npm install
|
|
177
|
+
npm run setup:simnet
|
|
178
|
+
npm test
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
182
|
+
|
|
183
|
+
## Security
|
|
184
|
+
|
|
185
|
+
Private keys and seed phrases are never logged. Output is scanned for sensitive fields and masked automatically when tasks return transaction IDs. Keep your `.env` out of version control.
|
|
186
|
+
|
|
187
|
+
## License
|
|
188
|
+
|
|
189
|
+
MIT
|
package/dist/cli/index.js
CHANGED
|
@@ -6,27 +6,66 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const commander_1 = require("commander");
|
|
9
|
+
const fs_1 = __importDefault(require("fs"));
|
|
10
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
9
12
|
const config_loading_1 = require("../config/config-loading");
|
|
10
13
|
const runtime_environment_1 = require("../core/runtime-environment");
|
|
11
14
|
const tasks_definitions_1 = require("../core/tasks-definitions");
|
|
12
15
|
const init_1 = require("./init");
|
|
13
|
-
const inquirer_1 = __importDefault(require("inquirer"));
|
|
14
|
-
// Import all user tasks
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
// Auto-load all tasks in src/tasks
|
|
18
16
|
const tasksDir = path_1.default.join(__dirname, '../tasks');
|
|
19
17
|
fs_1.default.readdirSync(tasksDir)
|
|
20
|
-
.filter(
|
|
21
|
-
.
|
|
22
|
-
|
|
18
|
+
.filter((fileName) => {
|
|
19
|
+
return ((fileName.endsWith('.ts') || fileName.endsWith('.js')) &&
|
|
20
|
+
!fileName.endsWith('.d.ts') &&
|
|
21
|
+
!fileName.includes('.test.'));
|
|
22
|
+
})
|
|
23
|
+
.forEach((fileName) => {
|
|
24
|
+
require(path_1.default.join(tasksDir, fileName));
|
|
23
25
|
});
|
|
26
|
+
function getProvidedOptions(argv) {
|
|
27
|
+
return new Set(argv
|
|
28
|
+
.filter((arg) => arg.startsWith('--'))
|
|
29
|
+
.map((arg) => arg.slice(2).split('=')[0])
|
|
30
|
+
.filter(Boolean));
|
|
31
|
+
}
|
|
32
|
+
function parseBoolean(value) {
|
|
33
|
+
if (typeof value === 'boolean')
|
|
34
|
+
return value;
|
|
35
|
+
if (typeof value === 'string') {
|
|
36
|
+
const normalized = value.toLowerCase();
|
|
37
|
+
if (['true', '1', 'yes', 'y'].includes(normalized))
|
|
38
|
+
return true;
|
|
39
|
+
if (['false', '0', 'no', 'n'].includes(normalized))
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return Boolean(value);
|
|
43
|
+
}
|
|
44
|
+
function coerceParamValue(param, value) {
|
|
45
|
+
if (value === undefined)
|
|
46
|
+
return value;
|
|
47
|
+
if (param.type === 'number') {
|
|
48
|
+
const parsed = Number(value);
|
|
49
|
+
if (Number.isNaN(parsed)) {
|
|
50
|
+
throw new Error(`Parameter '${param.name}' must be a number.`);
|
|
51
|
+
}
|
|
52
|
+
return parsed;
|
|
53
|
+
}
|
|
54
|
+
if (param.type === 'boolean') {
|
|
55
|
+
return parseBoolean(value);
|
|
56
|
+
}
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
function getPackageVersion() {
|
|
60
|
+
const packagePath = path_1.default.resolve(__dirname, '../../package.json');
|
|
61
|
+
const packageFile = JSON.parse(fs_1.default.readFileSync(packagePath, 'utf8'));
|
|
62
|
+
return packageFile.version || '0.0.0';
|
|
63
|
+
}
|
|
24
64
|
const program = new commander_1.Command();
|
|
25
65
|
program
|
|
26
66
|
.name('mobilestacks')
|
|
27
67
|
.description('Professional Task Runner for Stacks')
|
|
28
|
-
.version(
|
|
29
|
-
// Init command for project scaffolding
|
|
68
|
+
.version(getPackageVersion());
|
|
30
69
|
program
|
|
31
70
|
.command('init')
|
|
32
71
|
.description('Scaffold a new mobilestacks project and config')
|
|
@@ -34,62 +73,60 @@ program
|
|
|
34
73
|
await (0, init_1.runInit)();
|
|
35
74
|
process.exit(0);
|
|
36
75
|
});
|
|
37
|
-
// List all tasks if no command is given
|
|
38
76
|
program.action(() => {
|
|
39
77
|
console.log(chalk_1.default.bold.blue('\nMobilestacks - Professional Task Runner for Stacks\n'));
|
|
40
78
|
console.log(chalk_1.default.white('USAGE: ') + chalk_1.default.green('mobilestacks <task> [options]\n'));
|
|
41
79
|
console.log(chalk_1.default.bold('Available tasks:'));
|
|
42
|
-
tasks_definitions_1.TaskDefinitions.getInstance()
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
80
|
+
tasks_definitions_1.TaskDefinitions.getInstance()
|
|
81
|
+
.getAllTasks()
|
|
82
|
+
.forEach((task) => {
|
|
83
|
+
const params = task.params.map((param) => chalk_1.default.yellow(`--${param.name}`)).join(' ');
|
|
84
|
+
console.log(` ${chalk_1.default.cyan(task.name)} ${params}`);
|
|
85
|
+
console.log(` ${chalk_1.default.gray(task.description)}`);
|
|
46
86
|
});
|
|
47
|
-
console.log(
|
|
87
|
+
console.log(`\n${chalk_1.default.white('Use ')}${chalk_1.default.green('mobilestacks <task> --help')}${chalk_1.default.white(' for more info on a task.')}`);
|
|
48
88
|
console.log(chalk_1.default.white('\nExample:'));
|
|
49
|
-
console.log(
|
|
50
|
-
console.log(chalk_1.default.white('\nDocs: ') + chalk_1.default.underline('https://github.com/
|
|
89
|
+
console.log(` ${chalk_1.default.green('mobilestacks deploy-contract --contractName my-contract --file ./contracts/my-contract.clar --network testnet')}`);
|
|
90
|
+
console.log(chalk_1.default.white('\nDocs: ') + chalk_1.default.underline('https://github.com/Wizbisy/mobilestacks#readme'));
|
|
51
91
|
program.help({ error: false });
|
|
52
92
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
task.params.forEach(param => {
|
|
58
|
-
const optStr = `--${param.name} <value>`;
|
|
59
|
-
|
|
60
|
-
cmd.option(optStr, param.description);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
cmd.option(optStr, param.description, param.defaultValue);
|
|
64
|
-
}
|
|
93
|
+
tasks_definitions_1.TaskDefinitions.getInstance()
|
|
94
|
+
.getAllTasks()
|
|
95
|
+
.forEach((task) => {
|
|
96
|
+
const cmd = program.command(task.name).description(task.description);
|
|
97
|
+
task.params.forEach((param) => {
|
|
98
|
+
const optStr = param.type === 'boolean' ? `--${param.name}` : `--${param.name} <value>`;
|
|
99
|
+
cmd.option(optStr, param.description, param.defaultValue);
|
|
65
100
|
});
|
|
66
101
|
cmd.action(async (opts) => {
|
|
67
102
|
try {
|
|
68
|
-
const
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
103
|
+
const providedOptions = getProvidedOptions(process.argv.slice(3));
|
|
104
|
+
const missingRequiredParams = task.params.filter((param) => {
|
|
105
|
+
return param.required !== false && !providedOptions.has(param.name);
|
|
106
|
+
});
|
|
107
|
+
if (missingRequiredParams.length > 0 && process.stdout.isTTY) {
|
|
108
|
+
const answers = await inquirer_1.default.prompt(missingRequiredParams.map((param) => ({
|
|
109
|
+
type: param.type === 'boolean' ? 'confirm' : 'input',
|
|
110
|
+
name: param.name,
|
|
111
|
+
message: param.description,
|
|
112
|
+
default: opts[param.name] !== undefined ? opts[param.name] : param.defaultValue,
|
|
76
113
|
})));
|
|
77
114
|
Object.assign(opts, answers);
|
|
78
115
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (opts[
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
opts[p.name] = Boolean(opts[p.name]);
|
|
116
|
+
task.params.forEach((param) => {
|
|
117
|
+
opts[param.name] = coerceParamValue(param, opts[param.name]);
|
|
118
|
+
if (param.required !== false && (opts[param.name] === undefined || opts[param.name] === '')) {
|
|
119
|
+
throw new Error(`Missing required parameter '${param.name}'.`);
|
|
120
|
+
}
|
|
85
121
|
});
|
|
86
122
|
const config = (0, config_loading_1.loadConfig)();
|
|
87
123
|
const env = new runtime_environment_1.RuntimeEnvironment(config);
|
|
124
|
+
await env.ready;
|
|
88
125
|
const result = await task.action(opts, env);
|
|
89
|
-
if (typeof result === 'object') {
|
|
126
|
+
if (typeof result === 'object' && result !== null) {
|
|
90
127
|
const resObj = result;
|
|
91
128
|
if (resObj.txid) {
|
|
92
|
-
console.log(chalk_1.default.yellowBright('Transaction broadcasted to mempool
|
|
129
|
+
console.log(chalk_1.default.yellowBright('Transaction broadcasted to mempool. Check explorer for final confirmation.'));
|
|
93
130
|
}
|
|
94
131
|
else {
|
|
95
132
|
console.log(chalk_1.default.greenBright('Success!'));
|
package/dist/cli/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/cli/init.ts"],"names":[],"mappings":"AAmBA,wBAAsB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAmG7C"}
|