Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: dev eject and build for "serverless" #82

Merged
merged 30 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9dbdc53
feat: init eject
peterpeterparker Jan 20, 2024
bf5aff3
feat: dev command and review colors of help
peterpeterparker Jan 21, 2024
c92790a
feat: dev command entry
peterpeterparker Jan 21, 2024
5e4ec00
feat: ask for overwrite
peterpeterparker Jan 21, 2024
653e7e3
feat: eject success msg
peterpeterparker Jan 21, 2024
a94acd4
feat: build
peterpeterparker Jan 21, 2024
77e273b
feat: build
peterpeterparker Jan 21, 2024
b4d82ea
feat: wording
peterpeterparker Jan 25, 2024
171429e
fix: first build
peterpeterparker Jan 25, 2024
a87213e
feat: docker start
peterpeterparker Jan 25, 2024
be5e8e4
feat: set rust min version to 1.70.0
peterpeterparker Jan 26, 2024
a4a4f60
build: update
peterpeterparker Jan 26, 2024
b60ffaa
feat: use candid extractor
peterpeterparker Jan 26, 2024
d2a56dd
refactor: move constants
peterpeterparker Jan 26, 2024
ed8671b
chore: lint
peterpeterparker Jan 26, 2024
f77ffc3
feat: embed did information
peterpeterparker Jan 26, 2024
519ad79
feat: path and did
peterpeterparker Jan 27, 2024
7262a00
fix: catch errors
peterpeterparker Jan 27, 2024
da76e95
feat: new function
peterpeterparker Jan 27, 2024
46acb2d
feat: custom dev did file
peterpeterparker Jan 27, 2024
d2316f0
chore: lint
peterpeterparker Jan 27, 2024
f2b1251
feat: stop
peterpeterparker Jan 27, 2024
a9ad640
feat: check docker running
peterpeterparker Jan 27, 2024
11acba5
feat: rename to extension
peterpeterparker Jan 27, 2024
bd5fe12
feat: custom wasm module metadata to identify type of canister
peterpeterparker Jan 30, 2024
f44eca6
fix: extended flag set as string
peterpeterparker Jan 31, 2024
168737c
feat: assert build types
peterpeterparker Feb 2, 2024
77d4a88
build: bump admin next
peterpeterparker Feb 2, 2024
ec6eaa6
chore: merge main
peterpeterparker Feb 2, 2024
5a211c7
feat: update did version
peterpeterparker Feb 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ UserInterfaceState.xcuserstate

dist/

target
target/
22 changes: 11 additions & 11 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
Expand Up @@ -27,7 +27,7 @@
"@dfinity/candid": "^0.20.2",
"@dfinity/identity": "^0.20.2",
"@dfinity/principal": "^0.20.2",
"@junobuild/admin": "^0.0.43",
"@junobuild/admin": "^0.0.44-next-2024-02-02",
"@junobuild/core-peer": "^0.0.8",
"@junobuild/utils": "^0.0.17",
"conf": "^12.0.0",
Expand Down
27 changes: 27 additions & 0 deletions src/commands/dev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {red} from 'kleur';
import {build} from '../services/build.services';
import {start, stop} from '../services/docker.services';
import {eject} from '../services/eject.services';
import {helpDev} from './help';

export const dev = async (args?: string[]) => {
const [subCommand] = args ?? [];

switch (subCommand) {
case 'eject':
await eject();
break;
case 'build':
await build();
break;
case 'start':
await start();
break;
case 'stop':
await stop();
break;
default:
console.log(`${red('Unknown command.')}`);
console.log(helpDev);
}
};
101 changes: 62 additions & 39 deletions src/commands/help.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cyan, grey} from 'kleur';
import {cyan, green, grey, magenta, yellow} from 'kleur';
import {version} from '../../package.json';

const JUNO_LOGO = ` __ __ __ __ _ ____
Expand All @@ -11,36 +11,39 @@ export const help = `
${TITLE}


Usage: ${cyan('juno [command]')}
Usage: ${green('juno')} ${cyan('<command>')}

Commands:
${cyan(
'clear'
)} clear existing dapp code by removing JavaScript, HTML, CSS, and other files from your satellite
${cyan('config')} apply configuration to satellite
${cyan('deploy')} deploy your dapp to your satellite
${cyan('init')} configure the current directory as a satellite
${cyan('help')} display help information
${cyan('login')} generate an authentication for use in non-interactive environments
${cyan('logout')} log out of the current device using the CLI
${cyan('open')} open your satellite in your browser
${cyan('upgrade')} upgrade your satellite to a specific version code
${cyan('use')} switch between multiple profiles
${cyan('version')} check the version of a satellite, mission control and cli
${cyan('whoami')} display the current controller
)} Clear existing dapp code by removing JavaScript, HTML, CSS, and other files from your satellite.
${cyan('config')} Apply configuration to satellite.
${cyan('deploy')} Deploy your dapp to your satellite.
${cyan(
'dev'
)} Handle development-related tasks such as building and deploying locally using Cargo and Docker.
${cyan('init')} Configure the current directory as a satellite.
${cyan('help')} Display help information.
${cyan('login')} Generate an authentication for use in non-interactive environments.
${cyan('logout')} Log out of the current device using the CLI.
${cyan('open')} Open your satellite in your browser.
${cyan('upgrade')} Upgrade your satellite to a specific version code.
${cyan('use')} Switch between multiple profiles.
${cyan('version')} Check the version of a satellite, mission control and cli.
${cyan('whoami')} Display the current controller.
`;

export const helpUpgrade = `
${TITLE}

Usage: ${cyan('juno upgrade [options]')}
Usage: ${green('juno')} ${cyan('upgrade')} ${yellow('[options]')}

Options:
${cyan('-s, --src')} a local wasm file for the upgrade
${cyan('-m, --mission-control')} target a mission control
${cyan('-o, --orbiter')} target an orbiter
${cyan('-r, --reset')} reset to the initial state
${cyan('-h, --help')} output usage information
${yellow('-s, --src')} A local wasm file for the upgrade.
${yellow('-m, --mission-control')} Target a mission control.
${yellow('-o, --orbiter')} Target an orbiter.
${yellow('-r, --reset')} Reset to the initial state.
${yellow('-h, --help')} Output usage information.

Notes:

Expand All @@ -51,60 +54,80 @@ Notes:
export const helpCommand = (command: string) => `
${TITLE}

Usage: ${cyan(`juno ${command}`)}
Usage: ${green('juno')} ${cyan(command)} ${yellow('[options]')}

Options:
${cyan('-h, --help')} output usage information
${yellow('-h, --help')} Output usage information.
`;

export const helpLogin = `
${TITLE}

Usage: ${cyan('juno login [options]')}
Usage: ${green('juno')} ${cyan('login')} ${yellow('[options]')}

Options:
${cyan('-b, --browser')} a particular browser to open. supported: chrome|firefox|edge
${cyan('-h, --help')} output usage information
${yellow('-b, --browser')} A particular browser to open. supported: chrome|firefox|edge.
${yellow('-h, --help')} Output usage information.
`;

export const helpUse = `
${TITLE}

Usage: ${cyan('juno use [options]')}
Usage: ${green('juno')} ${cyan('use')} ${yellow('[options]')}

Options:
${cyan('-p, --profile')} the profile that should be use
${cyan('-l, --list')} what are the available profiles
${cyan('-h, --help')} output usage information
${yellow('-p, --profile')} The profile that should be use.
${yellow('-l, --list')} What are the available profiles.
${yellow('-h, --help')} Output usage information.
`;

export const helpOpen = `
${TITLE}

Usage: ${cyan('juno open [options]')}
Usage: ${green('juno')} ${cyan('open')} ${yellow('[options]')}

Options:
${cyan('-b, --browser')} a particular browser to open. supported: chrome|firefox|edge
${cyan('-c, --console')} open satellite in the console
${cyan('-h, --help')} output usage information
${yellow('-b, --browser')} A particular browser to open. supported: chrome|firefox|edge.
${yellow('-c, --console')} Open satellite in the console.
${yellow('-h, --help')} Output usage information.
`;

export const helpDeploy = `
${TITLE}

Usage: ${cyan('juno deploy [options]')}
Usage: ${green('juno')} ${cyan('deploy')} ${yellow('[options]')}

Options:
${cyan('-c, --clear')} clear existing dapp files before proceeding with deployment
${cyan('-h, --help')} output usage information
${yellow('-c, --clear')} Clear existing dapp files before proceeding with deployment.
${yellow('-h, --help')} Output usage information.
`;

export const helpClear = `
${TITLE}

Usage: ${cyan('juno clear [options]')}
Usage: ${green('juno')} ${cyan('clear')} ${yellow('[options]')}

Options:
${cyan('-f, --fullPath')} clear a particular file of your dapp
${cyan('-h, --help')} output usage information
${yellow('-f, --fullPath')} Clear a particular file of your dapp.
${yellow('-h, --help')} Output usage information.
`;

export const helpDevSubCommands = `${magenta(
'build'
)} Compile satellite features using Cargo.
${magenta(
'start'
)} Start a local Internet Computer network, encapsulated in a Docker environment.`;

export const helpDev = `
${TITLE}

Usage: ${green('juno')} ${cyan('dev')} ${magenta('<sub-command>')}

Sub-commands:
${helpDevSubCommands}
${magenta(
'eject'
)} Create a Rust template for custom satellite feature hooks and extensions.
${magenta('stop')} Stop the Docker environment.
`;
26 changes: 12 additions & 14 deletions src/commands/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import {
ORBITER_WASM_NAME,
SATELLITE_WASM_NAME
} from '../constants/constants';
import {assertSatelliteBuildType} from '../services/upgrade-assert.services';
import {redoCustomDomains, upgradeWasmCdn, upgradeWasmLocal} from '../services/upgrade.services';
import type {AssetKey} from '../types/asset-key';
import type {UpgradeWasm, UpgradeWasmModule} from '../types/upgrade';
import {actorParameters} from '../utils/actor.utils';
import {hasArgs, nextArg} from '../utils/args.utils';
import {toAssetKeys} from '../utils/asset-key.utils';
Expand Down Expand Up @@ -159,10 +161,7 @@ const upgradeSatelliteRelease = async ({
return;
}

const upgrade = async (params: {
upgrade: ({wasm_module}: {wasm_module: Uint8Array}) => Promise<void>;
reset?: boolean;
}) => {
const upgrade = async (params: Pick<UpgradeWasm, 'upgrade' | 'reset' | 'assert'>) => {
await upgradeWasmCdn({version, assetKey: 'satellite', ...params});
};

Expand Down Expand Up @@ -193,10 +192,7 @@ const upgradeSatelliteCustom = async ({
satellite
});

const upgrade = async (params: {
upgrade: ({wasm_module}: {wasm_module: Uint8Array}) => Promise<void>;
reset?: boolean;
}) => {
const upgrade = async (params: Pick<UpgradeWasm, 'upgrade' | 'reset' | 'assert'>) => {
await upgradeWasmLocal({src, ...params});
};

Expand All @@ -217,17 +213,14 @@ const executeUpgradeSatellite = async ({
satellite: SatelliteParameters;
args?: string[];
currentVersion: string;
upgrade: (params: {
upgrade: ({wasm_module}: {wasm_module: Uint8Array}) => Promise<void>;
reset?: boolean;
}) => Promise<void>;
upgrade: (params: Pick<UpgradeWasm, 'upgrade' | 'reset' | 'assert'>) => Promise<void>;
}) => {
const reset = await confirmReset({args, assetKey: 'satellite'});

// Information we want to try to redo once the satellite has been updated and resetted
const customDomains = reset ? await listCustomDomains({satellite}) : [];

const upgradeSatelliteWasm = async ({wasm_module}: {wasm_module: Uint8Array}) => {
const upgradeSatelliteWasm = async ({wasm_module}: UpgradeWasmModule) => {
await upgradeSatelliteAdmin({
satellite,
wasm_module,
Expand All @@ -238,9 +231,14 @@ const executeUpgradeSatellite = async ({
});
};

const assert = async (params: UpgradeWasmModule) => {
await assertSatelliteBuildType({satellite, ...params});
};

await upgrade({
upgrade: upgradeSatelliteWasm,
reset
reset,
assert
});

if (reset && customDomains.length > 0) {
Expand Down
10 changes: 10 additions & 0 deletions src/constants/dev.constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {join} from 'node:path';

export const DEVELOPER_PROJECT_SATELLITE_PATH = join(process.cwd(), 'src', 'satellite');

export const TEMPLATE_PATH = '../templates/eject';
export const TEMPLATE_SATELLITE_PATH = join(TEMPLATE_PATH, 'src', 'satellite');

export const RUST_MIN_VERSION = '1.70.0';
export const IC_WASM_MIN_VERSION = '0.3.6';
export const DOCKER_MIN_VERSION = '24.0.0';
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import {login, logout} from './commands/auth';
import {clear} from './commands/clear';
import {config} from './commands/config';
import {deploy} from './commands/deploy';
import {dev} from './commands/dev';
import {
help,
helpClear,
helpCommand,
helpDeploy,
helpDev,
helpLogin,
helpOpen,
helpUpgrade,
Expand All @@ -26,6 +28,11 @@ import {checkNodeVersion} from './utils/env.utils';
export const run = async () => {
const {valid} = checkNodeVersion();

if (valid === 'error') {
console.error(`Cannot detect your Node runtime version. Is NodeJS installed on your machine?`);
return;
}

if (!valid) {
return;
}
Expand Down Expand Up @@ -58,6 +65,9 @@ export const run = async () => {
case 'deploy':
console.log(helpDeploy);
break;
case 'dev':
console.log(helpDev);
break;
default:
console.log(helpCommand(cmd));
}
Expand Down Expand Up @@ -100,6 +110,9 @@ export const run = async () => {
case 'use':
use(args);
break;
case 'dev':
await dev(args);
break;
case 'help':
console.log(help);
break;
Expand All @@ -114,6 +127,7 @@ export const run = async () => {
try {
await run();
} catch (err: unknown) {
console.log(`${red('An unexpected error happened 😫.')}`, err);
console.log(`${red('An unexpected error happened 😫.')}\n`);
console.log(err);
}
})();
Loading
Loading