diff --git a/package.json b/package.json index f97f093ba5..c6ada8e394 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "make": "make -C ../../.. snarkyjs", "make:no-types": "npm run clean && make -C ../../.. snarkyjs_no_types", "bindings": "cd ../../.. && ./scripts/update-snarkyjs-bindings.sh && cd src/lib/snarkyjs", - "build": "rimraf ./src/bindings/compiled/_node_bindings && cp -r src/bindings/compiled/node_bindings src/bindings/compiled/_node_bindings && rimraf ./dist/node && npx tsc -p tsconfig.node.json && node src/build/copy-to-dist.js && node src/build/buildNode.js", + "build": "node src/build/copy-artifacts.js && rimraf ./dist/node && npm run dev && node src/build/buildNode.js", "build:test": "npx tsc -p tsconfig.test.json && cp src/snarky.d.ts dist/node/snarky.d.ts", "build:node": "npm run build", "build:web": "rimraf ./dist/web && node src/build/buildWeb.js", diff --git a/src/build/copy-artifacts.js b/src/build/copy-artifacts.js new file mode 100644 index 0000000000..b5a218e8b1 --- /dev/null +++ b/src/build/copy-artifacts.js @@ -0,0 +1,8 @@ +// copy some files from /src to /dist/node that tsc doesn't copy because we have .d.ts files for them +import { copyFromTo } from './utils.js'; + +await copyFromTo( + ['src/bindings/compiled/node_bindings/'], + 'node_bindings', + '_node_bindings' +); diff --git a/src/build/copy-to-dist.js b/src/build/copy-to-dist.js index a338d0a1e9..635f761594 100644 --- a/src/build/copy-to-dist.js +++ b/src/build/copy-to-dist.js @@ -1,22 +1,8 @@ -// copy some files from /src to /dist/node that tsc doesn't copy because -// we have .d.ts files for them -import fse from 'fs-extra'; +// copy some files from /src to /dist/node that tsc doesn't copy because we have .d.ts files for them +import { copyFromTo } from './utils.js'; -let files = ['src/snarky.d.ts', 'src/bindings/compiled/_node_bindings']; - -await copyToDist(files); - -async function copyToDist(files) { - let promises = []; - for (let source of files) { - let target = source.replace('src/', 'dist/node/'); - promises.push( - fse.copy(source, target, { - recursive: true, - overwrite: true, - dereference: true, - }) - ); - } - await Promise.all(promises); -} +await copyFromTo( + ['src/snarky.d.ts', 'src/bindings/compiled/_node_bindings'], + 'src', + 'dist/node' +); diff --git a/src/build/utils.js b/src/build/utils.js new file mode 100644 index 0000000000..6eb7635fa9 --- /dev/null +++ b/src/build/utils.js @@ -0,0 +1,18 @@ +import fse from 'fs-extra'; + +export { copyFromTo }; + +async function copyFromTo(files, srcDir = undefined, targetDir = undefined) { + let promises = []; + for (let source of files) { + let target = source.replace(`${srcDir}/`, `${targetDir}/`); + promises.push( + fse.copy(source, target, { + recursive: true, + overwrite: true, + dereference: true, + }) + ); + } + await Promise.all(promises); +}