Skip to content

Commit

Permalink
Add --deploy flag to specify installation arguments (#49)
Browse files Browse the repository at this point in the history
* Add '--argument' flag for `dfx deploy`

* Set up defaults for deployArgs

* Implement deploy args

* 0.10.1

* Update readme

* Reformat

* 0.11.0
  • Loading branch information
rvanasa authored Jul 5, 2023
1 parent 223b60f commit 6ca688b
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ Only run the dev server for specific canisters (`--canister` or `-c`):
mo-dev --canister foo --canister bar --deploy
```

Pass an installation argument to `dfx deploy` (`--argument` or `-a`):

```sh
mo-dev --deploy --argument '()'
```

## Advanced Features

Show additional debug output in the console (`--verbose` or `-v`):
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mo-dev",
"version": "0.10.0",
"version": "0.11.0",
"description": "A live reload development server for Motoko smart contracts.",
"author": "DFINITY Foundation (https://dfinity.org)",
"license": "Apache-2.0",
Expand Down
20 changes: 18 additions & 2 deletions src/commands/mo-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,25 @@ const increaseVerbosity = () => verbosity++;

const testModes: TestMode[] = [];
const addTestMode = (mode: string) => testModes.push(asTestMode(mode));

const testFiles: string[] = [];
const addTestFile = (file: string) => testFiles.push(file);

const canisterNames: string[] = [];
const addCanisterName = (name: string) => canisterNames.push(name);

const deployArgs: string[] = [];
const addDeployArg = (arg: string) => deployArgs.push(arg);

const examples: [string, string][] = [
['-d', 'redeploy canisters on file change'],
['-d -y', 'upgrade canisters on file change'],
['-g', 'generate TypeScript bindings on file change'],
['-t', 'run unit tests on file change'],
['-r -c foo_canister -c bar_canister', 'redeploy `foo_canister` and `bar_canister` on file change'],
[
'-r -c foo_canister -c bar_canister',
'redeploy `foo_canister` and `bar_canister` on file change',
],
];

const {
Expand Down Expand Up @@ -62,6 +70,11 @@ const {
`use the given Motoko canister`,
addCanisterName,
)
.option(
'-a, --argument <arg>',
`pass an install argument to \`dfx deploy\``,
addDeployArg,
)
.option(
'-y, --yes',
`respond "yes" to reinstall prompts (may reset canister state)`,
Expand Down Expand Up @@ -97,10 +110,13 @@ const settings: Settings = {
verbosity,
generate: !!generate || defaultSettings.generate,
deploy: !!deploy || defaultSettings.deploy,
deployArgs: deployArgs.length ? deployArgs : defaultSettings.deployArgs,
test: !!test || defaultSettings.test,
testModes: testModes.length ? testModes : defaultSettings.testModes,
testFiles: testFiles.length ? testFiles : defaultSettings.testFiles,
canisterNames: canisterNames.length ? canisterNames : defaultSettings.canisterNames,
canisterNames: canisterNames.length
? canisterNames
: defaultSettings.canisterNames,
reinstall: !!yes || defaultSettings.reinstall,
hotReload: !!hotReload || defaultSettings.hotReload,
// ci: !!ci || defaultSettings.ci,
Expand Down
2 changes: 2 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Settings {
verbosity: number;
generate: boolean;
deploy: boolean;
deployArgs: string[];
test: boolean;
testModes: TestMode[];
testFiles: string[];
Expand All @@ -27,6 +28,7 @@ export const defaultSettings: Settings = {
verbosity: 0,
generate: false,
deploy: false,
deployArgs: [],
test: false,
testModes: ['interpreter'],
testFiles: [],
Expand Down
8 changes: 8 additions & 0 deletions src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ export async function watch(settings: Settings) {
hotReload,
} = settings;

const deployArgs: string[] = [];
settings.deployArgs.forEach((arg) => {
deployArgs.push('--argument', arg);
});

const log = (level: number, ...args: any[]) => {
if (verbosity >= level) {
const time = new Date().toLocaleTimeString();
Expand Down Expand Up @@ -187,6 +192,7 @@ export async function watch(settings: Settings) {
});
}
});
// TODO: handle deploy args
dependencies.forEach((alias) => {
log(0, pc.green('prepare'), pc.gray(alias));
runDfx(['deploy', alias], 1);
Expand All @@ -202,6 +208,7 @@ export async function watch(settings: Settings) {
'deploy',
canister.alias,
...(reinstall ? ['-y'] : []),
...deployArgs,
],
1,
);
Expand Down Expand Up @@ -402,6 +409,7 @@ export async function watch(settings: Settings) {
canister.alias,
...(verbosity >= 1 ? [] : ['-qq']),
...(reinstall ? ['-y'] : []),
...deployArgs,
],
// TODO: hide 'Module hash ... is already installed' warnings
pipe: pipe || !reinstall,
Expand Down

0 comments on commit 6ca688b

Please sign in to comment.