Skip to content

Commit

Permalink
remove compile directory mostly
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Aug 27, 2024
1 parent 6f108c9 commit ca4916d
Show file tree
Hide file tree
Showing 54 changed files with 166 additions and 2,615 deletions.
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
File renamed without changes.
5 changes: 5 additions & 0 deletions src/build/experimental/commands/compile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from '../../../stable/commands/compile';
import { execSyncPretty } from '../../../stable/utils/exec_sync_pretty';
import { CanisterConfig } from '../../../stable/utils/types';
import { logSuccess } from '../../utils/log_success';
import { getCandidAndMethodMeta } from './candid_and_method_meta';
import { setupFileWatcher } from './file_watcher/setup_file_watcher';
import { getContext } from './get_context';
Expand Down Expand Up @@ -79,6 +80,10 @@ export async function runCommand(
canisterName,
methodMeta.post_upgrade?.index ?? -1
);

if (canisterConfig.custom?.candid_gen === 'http') {
logSuccess(canisterName, canisterId);
}
}

function buildAssets(canisterConfig: CanisterConfig, ioType: IOType): void {
Expand Down
5 changes: 4 additions & 1 deletion src/build/experimental/commands/compile/javascript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ export function getBuildOptions(
const customJsModulesPath = join(
AZLE_PACKAGE_PATH,
'src',
'compiler',
'build',
'experimental',
'commands',
'compile',
'custom_js_modules'
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { readFile, writeFile } from 'fs/promises';
import { copy } from 'fs-extra/esm';
import { join } from 'path';

import { AZLE_PACKAGE_PATH } from './utils/global_paths';
import { AZLE_PACKAGE_PATH } from '../../stable/utils/global_paths';

export async function generateNewAzleProject(
azleVersion: string
): Promise<void> {
export async function runCommand(azleVersion: string): Promise<void> {
if (process.argv[3] === undefined) {
console.error('You must provide a name for your Azle project');
return;
Expand Down
6 changes: 5 additions & 1 deletion src/build/experimental/utils/experimental_message.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function experimentalMessage(description: string): string {
export function experimentalMessageDfxJson(description: string): string {
return `Azle: Experimental mode must be enabled to use ${description}. You can enable experimental mode in your dfx.json file like this:
{
"canisters": {
Expand All @@ -13,3 +13,7 @@ export function experimentalMessage(description: string): string {
}
`;
}

export function experimentalMessageCli(description: string): string {
return `Azle: Experimental mode must be enabled to use ${description}. You can enable experimental mode with the --experimental flag as the final argument`;
}
16 changes: 16 additions & 0 deletions src/build/experimental/utils/log_success.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { execSyncPretty } from '../../stable/utils/exec_sync_pretty';

export function logSuccess(canisterName: string, canisterId: string): void {
const replicaWebServerPort = execSyncPretty(`dfx info webserver-port`)
.toString()
.trim();

const url =
process.env.DFX_NETWORK === 'ic'
? `https://${canisterId}.raw.icp0.io`
: `http://${canisterId}.localhost:${replicaWebServerPort}`;

console.info(
`\nCanister ${canisterName} serving HTTP requests at: ${url}\n`
);
}
71 changes: 61 additions & 10 deletions src/build/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#!/usr/bin/env -S tsx --abort-on-uncaught-exception

import { IOType } from 'child_process';
import { join } from 'path';

import { version as azleVersion } from '../../package.json';
import { runCommand as runExperimentalCompileCommand } from './experimental/commands/compile';
import { runCommand as runUploadAssetsCommand } from './experimental/commands/upload_assets';
import { experimentalMessage } from './experimental/utils/experimental_message';
import {
experimentalMessageCli,
experimentalMessageDfxJson
} from './experimental/utils/experimental_message';
import { runCommand as runCleanCommand } from './stable/commands/clean';
import { runCommand as runStableCompileCommand } from './stable/commands/compile';
import { runCommand as runInstallDfxExtension } from './stable/commands/install_dfx_extension';
import { runCommand as runInstallDfxExtensionCommand } from './stable/commands/install_dfx_extension';
import { runCommand as runNewCommand } from './stable/commands/new';
import { runCommand as runVersionCommand } from './stable/commands/version';
import { getCanisterConfig } from './stable/utils/get_canister_config';
import { AZLE_PACKAGE_PATH } from './stable/utils/global_paths';
import { Command } from './stable/utils/types';

build();
Expand All @@ -24,19 +33,37 @@ async function build(): Promise<void> {
const ioType = process.env.AZLE_VERBOSE === 'true' ? 'inherit' : 'pipe';

if (command === 'install-dfx-extension') {
handleCommandInstallDfxExtension(ioType);
handleInstallDfxExtensionCommand(ioType);

return;
}

if (command === 'upload-assets') {
await handleCommandUploadAssets();
await handleUploadAssetsCommand();

return;
}

if (command === 'compile') {
await handleCommandCompile(ioType);
await handleCompileCommand(ioType);

return;
}

if (command === '--version') {
runVersionCommand();

return;
}

if (command === 'clean') {
await runCleanCommand();

return;
}

if (command === 'new') {
await handleNewCommand();

return;
}
Expand All @@ -46,26 +73,28 @@ async function build(): Promise<void> {
);
}

function handleCommandInstallDfxExtension(ioType: IOType): void {
runInstallDfxExtension(ioType);
function handleInstallDfxExtensionCommand(ioType: IOType): void {
runInstallDfxExtensionCommand(ioType);
}

async function handleCommandUploadAssets(): Promise<void> {
async function handleUploadAssetsCommand(): Promise<void> {
const canisterName = process.argv[3];
const canisterConfig = await getCanisterConfig(canisterName);

const experimental = canisterConfig?.custom?.experimental === true;

if (experimental === false) {
if (canisterConfig.custom?.assets !== undefined) {
throw new Error(experimentalMessage('the upload-assets command'));
throw new Error(
experimentalMessageDfxJson('the upload-assets command')
);
}
} else {
await runUploadAssetsCommand();
}
}

async function handleCommandCompile(ioType: IOType): Promise<void> {
async function handleCompileCommand(ioType: IOType): Promise<void> {
const canisterName = process.argv[3];
const canisterConfig = await getCanisterConfig(canisterName);

Expand All @@ -92,3 +121,25 @@ async function handleCommandCompile(ioType: IOType): Promise<void> {
);
}
}

async function handleNewCommand(): Promise<void> {
const experimental = process.argv.includes('--experimental');

if (experimental === false) {
if (process.argv.includes('--http-server')) {
throw new Error(experimentalMessageCli('the --http-server option'));
}

const templatePath = join(
AZLE_PACKAGE_PATH,
'examples',
'hello_world_candid_rpc'
);

await runNewCommand(azleVersion, templatePath);
} else {
const templatePath = join(AZLE_PACKAGE_PATH, 'examples', 'hello_world');

await runNewCommand(azleVersion, templatePath);
}
}
33 changes: 33 additions & 0 deletions src/build/stable/commands/clean.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { rm } from 'fs/promises';

import { GLOBAL_AZLE_CONFIG_DIR } from '../utils/global_paths';

export async function runCommand(): Promise<void> {
await rm(GLOBAL_AZLE_CONFIG_DIR, {
recursive: true,
force: true
});

console.info(`~/.config/azle directory deleted`);

await rm('.azle', {
recursive: true,
force: true
});

console.info(`.azle directory deleted`);

await rm('.dfx', {
recursive: true,
force: true
});

console.info(`.dfx directory deleted`);

await rm('node_modules', {
recursive: true,
force: true
});

console.info(`node_modules directory deleted`);
}
33 changes: 33 additions & 0 deletions src/build/stable/commands/new.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { readFile, writeFile } from 'fs/promises';
// @ts-ignore
import { copy } from 'fs-extra/esm';
import { join } from 'path';

export async function runCommand(
azleVersion: string,
templatePath: string
): Promise<void> {
if (process.argv[3] === undefined) {
console.error('You must provide a name for your Azle project');
return;
}

const projectName = process.argv[3];

await copy(templatePath, projectName);

const packageJson = (
await readFile(join(templatePath, 'package.json'))
).toString();

let parsedPackageJson = JSON.parse(packageJson);

parsedPackageJson.dependencies.azle = `^${azleVersion}`;

await writeFile(
join(projectName, 'package.json'),
JSON.stringify(parsedPackageJson, null, 4)
);

console.info(`${projectName} created successfully`);
}
5 changes: 5 additions & 0 deletions src/build/stable/commands/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { version } from '../../../../package.json';

export function runCommand(): void {
console.info(version);
}
2 changes: 1 addition & 1 deletion src/build/stable/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type CandidAndMethodMeta = {
methodMeta: MethodMeta;
};

export type CandidGen = 'automatic' | 'custom';
export type CandidGen = 'automatic' | 'custom' | 'http';

// TODO in stable we should detect if certain properties exist
// TODO and throw if not in experimental mode
Expand Down
Loading

0 comments on commit ca4916d

Please sign in to comment.