diff --git a/bin.mjs b/bin.mjs deleted file mode 100755 index 67936fb170..0000000000 --- a/bin.mjs +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env node - -import 'tsx'; -import('./src/compiler/index.ts'); diff --git a/package.json b/package.json index a172d7271c..22101a6954 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ }, "type": "module", "bin": { - "azle": "./bin.mjs" + "azle": "./src/compiler/index.ts" }, "main": "./src/lib/stable/index.ts", "repository": { diff --git a/src/compiler/index.ts b/src/compiler/index.ts old mode 100644 new mode 100755 index 4eaf9c766b..ae13fa6189 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env tsx + import { mkdir, rm, writeFile } from 'fs/promises'; import { join } from 'path'; @@ -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 { - 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 { await rm(canisterPath, { recursive: true, force: true }); diff --git a/tsconfig.json b/tsconfig.json index 23242c402b..7655f1d11b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "strict": true, "target": "ES2020", - "module": "ES2020", + "module": "ES2022", "moduleResolution": "node", "allowJs": true, "outDir": "HACK_BECAUSE_OF_ALLOW_JS",