diff --git a/.github/workflows/offchain-deploy.yml b/.github/workflows/offchain-deploy.yml index 2d5b1f1..89d414b 100644 --- a/.github/workflows/offchain-deploy.yml +++ b/.github/workflows/offchain-deploy.yml @@ -25,7 +25,8 @@ jobs: run: 'gcloud info' - name: Deploy to GCF run: | - gcloud functions deploy bounty-icp-gh-app \ + cd offchain/github + gcloud functions deploy offchain/github \ --runtime nodejs20 \ --allow-unauthenticated \ --trigger-http \ diff --git a/.github/workflows/offchain-release.yml b/.github/workflows/offchain-release.yml index e55d420..9409edc 100644 --- a/.github/workflows/offchain-release.yml +++ b/.github/workflows/offchain-release.yml @@ -13,6 +13,7 @@ jobs: with: node-version: lts/* cache: npm + - run: cd offchain/github - run: npx semantic-release env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/offchain-test.yml b/.github/workflows/offchain-test.yml index 87cb870..9657d5e 100644 --- a/.github/workflows/offchain-test.yml +++ b/.github/workflows/offchain-test.yml @@ -16,5 +16,6 @@ jobs: with: cache: npm node-version: 20 + - run: cd offchain/github - run: npm ci - run: npm test diff --git a/package-lock.json b/offchain/github/package-lock.json similarity index 100% rename from package-lock.json rename to offchain/github/package-lock.json diff --git a/offchain/github/package.json b/offchain/github/package.json new file mode 100644 index 0000000..d9ed960 --- /dev/null +++ b/offchain/github/package.json @@ -0,0 +1,41 @@ +{ + "name": "offchain", + "version": "1.0.0", + "private": true, + "description": "ICP Bounty gh-app on Google Cloud Functions", + "keywords": [ + "Internet Computer", + "Node", + "JavaScript", + "Canister" + ], + "scripts": { + "start": "probot run ./src/main/app.js", + "test": "node ./src/test/test.js", + "clean": "rm -rf node_modules", + "reinstall": "npm run clean && npm install", + "generate": "dfx generate backend", + "rebuild": "npm run clean && npm install && npm run build", + "lint": "standard" + }, + "author": "Prom3th3us", + "license": "ISC", + "repository": "github:Prom3th3us/bounty-icp", + "dependencies": { + "probot": "^13.2.2", + "@dfinity/agent": "^0.15.6", + "@dfinity/candid": "^0.15.6", + "@dfinity/principal": "^0.15.6" + }, + "devDependencies": { + "nock": "^14.0.0-beta.6", + "smee-client": "^2.0.1", + "uvu": "^0.5.6", + "standard": "^17.1.0" + }, + "release": { + "branches": [ + "release" + ] + } +} \ No newline at end of file diff --git a/package.json b/package.json index 1d7c136..a6701cb 100644 --- a/package.json +++ b/package.json @@ -1,41 +1,48 @@ { - "name": "offchain", - "version": "1.0.0", - "private": true, - "description": "ICP Bounty gh-app on Google Cloud Functions", + "name": "frontend", + "version": "0.2.0", + "description": "Internet Computer starter application", "keywords": [ "Internet Computer", - "Node", + "Rust", "JavaScript", "Canister" ], "scripts": { - "start": "probot run ./offchain/github/src/main/app.js", - "test": "node ./offchain/github/src/test/test.js", - "clean": "rm -rf node_modules", - "reinstall": "npm run clean && npm install", - "generate": "dfx generate backend", - "rebuild": "npm run clean && npm install && npm run build", - "lint": "standard" + "build": "webpack", + "prebuild": "dfx generate", + "start": "webpack serve --mode development --env development", + "deploy:local": "dfx deploy --network=local", + "deploy:ic": "dfx deploy --network=ic", + "generate": "dfx generate backend" }, - "author": "Prom3th3us", - "license": "ISC", - "repository": "github:Prom3th3us/bounty-icp", "dependencies": { - "probot": "^13.2.2", "@dfinity/agent": "^0.15.6", "@dfinity/candid": "^0.15.6", "@dfinity/principal": "^0.15.6" }, "devDependencies": { - "nock": "^14.0.0-beta.6", - "smee-client": "^2.0.1", - "uvu": "^0.5.6", - "standard": "^17.1.0" + "assert": "2.0.0", + "buffer": "6.0.3", + "copy-webpack-plugin": "^11.0.0", + "dotenv": "^16.0.3", + "events": "3.3.0", + "html-webpack-plugin": "5.5.0", + "process": "0.11.10", + "stream-browserify": "3.0.0", + "terser-webpack-plugin": "^5.3.3", + "util": "0.12.4", + "webpack": "^5.73.0", + "webpack-cli": "^4.10.0", + "webpack-dev-server": "^4.8.1" }, - "release": { - "branches": [ - "release" - ] - } -} \ No newline at end of file + "engines": { + "node": "16 || ^18 || ^20" + }, + "browserslist": [ + "last 2 chrome version", + "last 2 firefox version", + "last 2 safari version", + "last 2 edge version" + ] +} diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..4792c05 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,96 @@ +require("dotenv").config(); +const path = require("path"); +const webpack = require("webpack"); +const HtmlWebpackPlugin = require("html-webpack-plugin"); +const TerserPlugin = require("terser-webpack-plugin"); +const CopyPlugin = require("copy-webpack-plugin"); + +const isDevelopment = process.env.NODE_ENV !== "production"; + +const frontendDirectory = "frontend"; + +const frontend_entry = path.join("src", frontendDirectory, "src", "index.html"); + +module.exports = { + target: "web", + mode: isDevelopment ? "development" : "production", + entry: { + // The frontend.entrypoint points to the HTML file for this build, so we need + // to replace the extension to `.js`. + index: path.join(__dirname, frontend_entry).replace(/\.html$/, ".js"), + }, + devtool: isDevelopment ? "source-map" : false, + optimization: { + minimize: !isDevelopment, + minimizer: [new TerserPlugin()], + }, + resolve: { + extensions: [".js", ".ts", ".jsx", ".tsx"], + fallback: { + assert: require.resolve("assert/"), + buffer: require.resolve("buffer/"), + events: require.resolve("events/"), + stream: require.resolve("stream-browserify/"), + util: require.resolve("util/"), + }, + }, + output: { + filename: "index.js", + path: path.join(__dirname, "dist", frontendDirectory), + }, + + // Depending in the language or framework you are using for + // front-end development, add module loaders to the default + // webpack configuration. For example, if you are using React + // modules and CSS as described in the "Adding a stylesheet" + // tutorial, uncomment the following lines: + // module: { + // rules: [ + // { test: /\.(ts|tsx|jsx)$/, loader: "ts-loader" }, + // { test: /\.css$/, use: ['style-loader','css-loader'] } + // ] + // }, + plugins: [ + new HtmlWebpackPlugin({ + template: path.join(__dirname, frontend_entry), + cache: false, + }), + new webpack.EnvironmentPlugin([ + ...Object.keys(process.env).filter((key) => { + if (key.includes("CANISTER")) return true; + if (key.includes("DFX")) return true; + return false; + }), + ]), + new webpack.ProvidePlugin({ + Buffer: [require.resolve("buffer/"), "Buffer"], + process: require.resolve("process/browser"), + }), + new CopyPlugin({ + patterns: [ + { + from: `src/${frontendDirectory}/src/.ic-assets.json*`, + to: ".ic-assets.json5", + noErrorOnMissing: true, + }, + ], + }), + ], + // proxy /api to port 4943 during development. + // if you edit dfx.json to define a project-specific local network, change the port to match. + devServer: { + proxy: { + "/api": { + target: "http://127.0.0.1:4943", + changeOrigin: true, + pathRewrite: { + "^/api": "/api", + }, + }, + }, + static: path.resolve(__dirname, "src", frontendDirectory, "assets"), + hot: true, + watchFiles: [path.resolve(__dirname, "src", frontendDirectory)], + liveReload: true, + }, +};