Skip to content

Commit

Permalink
get rid of bin.mjs, use top level await in main file
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jul 15, 2024
1 parent cac0b85 commit 9715985
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 96 deletions.
4 changes: 0 additions & 4 deletions bin.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"type": "module",
"bin": {
"azle": "./bin.mjs"
"azle": "./src/compiler/index.ts"
},
"main": "./src/lib/stable/index.ts",
"repository": {
Expand Down
177 changes: 87 additions & 90 deletions src/compiler/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env tsx

import { mkdir, rm, writeFile } from 'fs/promises';
import { join } from 'path';

Expand All @@ -12,103 +14,98 @@ import { green } from './utils/colors';
import { execSyncPretty } from './utils/exec_sync_pretty';
import { CompilerInfo } from './utils/types';

azle();

async function azle(): Promise<void> {
const commandExecuted = await handleCli();
const commandExecuted = await handleCli();

if (commandExecuted === true) {
return;
}
if (commandExecuted === true) {
process.exit();
}

const {
stdioType,
wasmedgeQuickJsPath,
replicaWebServerPort,
canisterName,
canisterPath,
canisterConfig,
candidPath,
envVars,
rustStagingWasmPath,
canisterId,
reloadedJsPath,
esmAliases,
esmExternals
} = await getNames();

await time(
`\nBuilding canister ${green(canisterName)}`,
'default',
async () => {
createAzleDirectories(canisterPath);

const canisterJavaScript = unwrap(
await getCanisterJavaScript(
canisterConfig.main,
wasmedgeQuickJsPath,
esmAliases,
esmExternals
)
);

await writeFile(join(canisterPath, 'main.js'), canisterJavaScript);

const { candid, canisterMethods } =
await getCandidAndCanisterMethods(
canisterConfig.candid_gen,
candidPath,
canisterName,
stdioType,
envVars,
rustStagingWasmPath,
canisterJavaScript,
canisterConfig,
canisterPath
);

// This is for the dfx.json candid property
await writeFile(candidPath, candid);

const compilerInfo: CompilerInfo = {
// The spread is because canisterMethods is a function with properties
canister_methods: {
...canisterMethods
},
env_vars: envVars
};

await generateWasmBinary(
canisterName,
stdioType,
canisterJavaScript,
compilerInfo,
canisterConfig,
canisterPath
);

if (
canisterConfig.build_assets !== undefined &&
canisterConfig.build_assets !== null
) {
execSyncPretty(canisterConfig.build_assets, stdioType);
}

setupFileWatcher(
reloadedJsPath,
canisterId,
const {
stdioType,
wasmedgeQuickJsPath,
replicaWebServerPort,
canisterName,
canisterPath,
canisterConfig,
candidPath,
envVars,
rustStagingWasmPath,
canisterId,
reloadedJsPath,
esmAliases,
esmExternals
} = await getNames();

await time(
`\nBuilding canister ${green(canisterName)}`,
'default',
async () => {
createAzleDirectories(canisterPath);

const canisterJavaScript = unwrap(
await getCanisterJavaScript(
canisterConfig.main,
wasmedgeQuickJsPath,
esmAliases,
esmExternals,
canisterName,
canisterMethods.post_upgrade?.index ?? -1
);
esmExternals
)
);

await writeFile(join(canisterPath, 'main.js'), canisterJavaScript);

const { candid, canisterMethods } = await getCandidAndCanisterMethods(
canisterConfig.candid_gen,
candidPath,
canisterName,
stdioType,
envVars,
rustStagingWasmPath,
canisterJavaScript,
canisterConfig,
canisterPath
);

// This is for the dfx.json candid property
await writeFile(candidPath, candid);

const compilerInfo: CompilerInfo = {
// The spread is because canisterMethods is a function with properties
canister_methods: {
...canisterMethods
},
env_vars: envVars
};

await generateWasmBinary(
canisterName,
stdioType,
canisterJavaScript,
compilerInfo,
canisterConfig,
canisterPath
);

if (
canisterConfig.build_assets !== undefined &&
canisterConfig.build_assets !== null
) {
execSyncPretty(canisterConfig.build_assets, stdioType);
}
);

logSuccess(canisterName, canisterId, replicaWebServerPort);
}
setupFileWatcher(
reloadedJsPath,
canisterId,
canisterConfig.main,
wasmedgeQuickJsPath,
esmAliases,
esmExternals,
canisterName,
canisterMethods.post_upgrade?.index ?? -1
);
}
);

logSuccess(canisterName, canisterId, replicaWebServerPort);

async function createAzleDirectories(canisterPath: string): Promise<void> {
await rm(canisterPath, { recursive: true, force: true });
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"strict": true,
"target": "ES2020",
"module": "ES2020",
"module": "ES2022",
"moduleResolution": "node",
"allowJs": true,
"outDir": "HACK_BECAUSE_OF_ALLOW_JS",
Expand Down

0 comments on commit 9715985

Please sign in to comment.