1
- import path from "path" ;
1
+ import { dirname , join } from "path" ;
2
2
import fs from "fs" ;
3
- import { createRequire } from "module" ;
4
3
import { fileURLToPath } from "url" ;
5
4
6
- const dirname = path . dirname ( fileURLToPath ( import . meta. url ) ) ;
7
- const require = createRequire ( import . meta. url ) ;
8
- const pkg = require ( "../package-lock.json" ) ;
5
+ const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
9
6
10
- const mainVersion = pkg . version ;
11
- const binaryenVersion = pkg . dependencies . binaryen . version ;
12
- const longVersion = pkg . dependencies . long . version ;
7
+ export function buildWeb ( ) {
8
+ const pkg = JSON . parse ( fs . readFileSync ( join ( __dirname , "../package-lock.json" ) ) ) ;
13
9
14
- const distUrl = mainVersion === "0.0.0" ? `./` : `https://cdn.jsdelivr.net/npm/assemblyscript@${ mainVersion } /dist/` ;
15
- const binaryenUrl = `https://cdn.jsdelivr.net/npm/binaryen@${ binaryenVersion } /index.js` ;
16
- const longUrl = `https://cdn.jsdelivr.net/npm/long@${ longVersion } /index.js` ;
17
- const importmap = {
18
- "imports" : {
19
- "assemblyscript" : `${ distUrl } assemblyscript.js` ,
20
- "assemblyscript/asc" : `${ distUrl } asc.js` ,
21
- "binaryen" : binaryenUrl ,
22
- "long" : longUrl
23
- }
24
- } ;
10
+ const mainVersion = pkg . version ;
11
+ const binaryenVersion = pkg . dependencies . binaryen . version ;
12
+ const longVersion = pkg . dependencies . long . version ;
13
+
14
+ const distUrl = mainVersion === "0.0.0" ? `./` : `https://cdn.jsdelivr.net/npm/assemblyscript@${ mainVersion } /dist/` ;
15
+ const binaryenUrl = `https://cdn.jsdelivr.net/npm/binaryen@${ binaryenVersion } /index.js` ;
16
+ const longUrl = `https://cdn.jsdelivr.net/npm/long@${ longVersion } /index.js` ;
17
+ const importmap = {
18
+ "imports" : {
19
+ "assemblyscript" : `${ distUrl } assemblyscript.js` ,
20
+ "assemblyscript/asc" : `${ distUrl } asc.js` ,
21
+ "binaryen" : binaryenUrl ,
22
+ "long" : longUrl
23
+ }
24
+ } ;
25
25
26
- fs . writeFileSync ( path . join ( dirname , ".." , "dist" , "importmap.json" ) , `${ JSON . stringify ( importmap , null , 2 ) }
27
- ` ) ;
28
- fs . writeFileSync ( path . join ( dirname , ".." , "dist" , "web.js" ) , `var ASSEMBLYSCRIPT_VERSION = ${ JSON . stringify ( mainVersion ) } ;
29
- var ASSEMBLYSCRIPT_IMPORTMAP = ${ JSON . stringify ( importmap , null , 2 ) } ;
30
- if (!document.currentScript.src.includes("noinstall")) {
31
- let elem = document.createElement("script");
32
- elem.type = "importmap";
33
- elem.text = JSON.stringify(ASSEMBLYSCRIPT_IMPORTMAP);
34
- document.head.appendChild(elem);
35
- }
36
- if (!document.currentScript.src.includes("noshim")) {
37
- let elem = document.createElement("script");
38
- elem.async = true;
39
- elem.src = "https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.wasm.min.js";
40
- document.head.appendChild(elem);
41
- }
42
- ` ) ;
26
+ fs . writeFileSync ( join ( __dirname , ".." , "dist" , "importmap.json" ) , `${ JSON . stringify ( importmap , null , 2 ) }
27
+ ` ) ;
28
+ fs . writeFileSync ( join ( __dirname , ".." , "dist" , "web.js" ) , `var ASSEMBLYSCRIPT_VERSION = ${ JSON . stringify ( mainVersion ) } ;
29
+ var ASSEMBLYSCRIPT_IMPORTMAP = ${ JSON . stringify ( importmap , null , 2 ) } ;
30
+ if (!document.currentScript.src.includes("noinstall")) {
31
+ let elem = document.createElement("script");
32
+ elem.type = "importmap";
33
+ elem.text = JSON.stringify(ASSEMBLYSCRIPT_IMPORTMAP);
34
+ document.head.appendChild(elem);
35
+ }
36
+ if (!document.currentScript.src.includes("noshim")) {
37
+ let elem = document.createElement("script");
38
+ elem.async = true;
39
+ elem.src = "https://cdn.jsdelivr.net/npm/es-module-shims@1/dist/es-module-shims.wasm.min.js";
40
+ document.head.appendChild(elem);
41
+ }
42
+ ` ) ;
43
+ }
0 commit comments