diff --git a/.gitignore b/.gitignore index b5ec510d..5f971840 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # build output dist app/renderer +compiled_app bin/cli.* # dependencies diff --git a/app/utils/colors.js b/app/utils/colors.ts similarity index 81% rename from app/utils/colors.js rename to app/utils/colors.ts index f571edd3..5aa7fafd 100644 --- a/app/utils/colors.js +++ b/app/utils/colors.ts @@ -19,7 +19,9 @@ const colorList = [ 'grayscale' ]; -exports.getColorMap = colors => { +export const getColorMap: { + (colors: T): T extends (infer U)[] ? { [k: string]: U } : T +} = colors => { if (!Array.isArray(colors)) { return colors; } diff --git a/lib/tsconfig.json b/lib/tsconfig.json new file mode 100644 index 00000000..1371f9e3 --- /dev/null +++ b/lib/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "allowJs": true, + "checkJs": false, + "downlevelIteration": true, + "esModuleInterop": true, + "jsx": "react", + "lib": ["dom", "es2017"], + "module": "esnext", + "moduleResolution": "node", + "noEmit": true, + "preserveConstEnums": true, + "removeComments": false, + "resolveJsonModule": true, + "sourceMap": true, + "strict": true, + "target": "es6" + }, + "include": [ + "./**/*" + ] +} diff --git a/package.json b/package.json index 3d982be9..2385aaa5 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "repository": "zeit/hyper", "scripts": { "start": "echo 'please run `yarn run dev` in one tab and then `yarn run app` in another one'", - "app": "electron app", + "app": "electron compiled_app", "dev": "webpack -w", "build": "cross-env NODE_ENV=production webpack", "lint": "eslint . --ext .js,.jsx,.ts,.tsx", @@ -14,7 +14,8 @@ "prepush": "yarn test", "postinstall": "electron-builder install-app-deps && yarn run rebuild-node-pty", "rebuild-node-pty": "electron-rebuild -f -w app/node_modules/node-pty -m app", - "dist": "yarn run build && cross-env BABEL_ENV=production babel --out-file app/renderer/bundle.js --no-comments --minified app/renderer/bundle.js && build", + "dist": + "yarn run build && cross-env BABEL_ENV=production babel --out-file compiled_app/renderer/bundle.js --no-comments --minified compiled_app/renderer/bundle.js && build", "clean": "node ./bin/rimraf-standalone.js node_modules && node ./bin/rimraf-standalone.js ./app/node_modules && node ./bin/rimraf-standalone.js ./app/renderer" }, "eslintConfig": { @@ -296,6 +297,7 @@ "husky": "0.14.3", "inquirer": "5.1.0", "node-gyp": "3.6.2", + "null-loader": "3.0.0", "prettier": "1.18.2", "proxyquire": "1.8.0", "spectron": "3.8.0", diff --git a/tsconfig.json b/tsconfig.json index 99d354b4..9082bc22 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -6,9 +6,9 @@ "esModuleInterop": true, "jsx": "react", "lib": ["dom", "es2017"], - "module": "esnext", + "module": "commonjs", "moduleResolution": "node", - "noEmit": true, + "outDir": "./compiled_app/", "preserveConstEnums": true, "removeComments": false, "resolveJsonModule": true, @@ -17,7 +17,7 @@ "target": "es6" }, "include": [ - "./lib/" + "./app/" ], "exclude": ["node_modules", "**/node_modules/*", "bin/*", "renderer/*"] } diff --git a/webpack.config.js b/webpack.config.js index 06d702d3..c9c17823 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,4 +1,5 @@ const path = require('path'); +const exec = require('child_process').exec; const webpack = require('webpack'); const Copy = require('copy-webpack-plugin'); @@ -8,6 +9,68 @@ const nodeEnv = process.env.NODE_ENV || 'development'; const isProd = nodeEnv === 'production'; module.exports = [ + { + mode: 'none', + name: 'hyper-app', + resolve: { + extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'] + }, + entry: './app/index.js', + output: { + path: path.join(__dirname, 'compiled_app'), + filename: 'ignore_this.js' + }, + module: { + rules: [ + { + test: /\.(js|jsx|ts|tsx)$/, + exclude: /node_modules/, + loader: 'null-loader' + } + ] + }, + plugins: [ + new Copy([ + { + from: './app/*.html', + exclude: /node_modules/, + to: '.', + flatten: true + }, + { + from: './app/*.json', + exclude: /node_modules/, + to: '.', + flatten: true + }, + { + from: './app/keymaps/*.json', + exclude: /node_modules/, + to: './keymaps', + flatten: true + } + // { + // from: './app/node_modules', // gives really long output in webpack, used cp instead + // to: './node_modules' + // } + ]), + + { + apply: compiler => { + compiler.hooks.afterEmit.tap('AfterEmitPlugin', () => { + exec('cp -r ./app/node_modules ./compiled_app && tsc', (err, stdout, stderr) => { + if (stdout) process.stdout.write(stdout); + if (stderr) process.stderr.write(stderr); + process.stdout.write('\nCompiled\n\n'); + }); + }); + } + }, + new ForkTsCheckerWebpackPlugin() + ], + target: 'electron-main' + }, + { mode: 'none', name: 'hyper', @@ -17,7 +80,7 @@ module.exports = [ devtool: isProd ? 'hidden-source-map' : 'cheap-module-source-map', entry: './lib/index.js', output: { - path: path.join(__dirname, 'app', 'renderer'), + path: path.join(__dirname, 'compiled_app', 'renderer'), filename: 'bundle.js' }, module: { @@ -52,7 +115,9 @@ module.exports = [ to: './assets' } ]), - new ForkTsCheckerWebpackPlugin() + new ForkTsCheckerWebpackPlugin({ + tsconfig: './lib/tsconfig.json' + }) ], target: 'electron-renderer' }, diff --git a/yarn.lock b/yarn.lock index fad4c131..c664a89f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6030,6 +6030,14 @@ nugget@^2.0.0: single-line-log "^1.1.2" throttleit "0.0.2" +null-loader@3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/null-loader/-/null-loader-3.0.0.tgz#3e2b6c663c5bda8c73a54357d8fa0708dc61b245" + integrity sha512-hf5sNLl8xdRho4UPBOOeoIwT3WhjYcMUQm0zj44EhD6UscMAz72o2udpoDFBgykucdEDGIcd6SXbc/G6zssbzw== + dependencies: + loader-utils "^1.2.3" + schema-utils "^1.0.0" + num2fraction@^1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/num2fraction/-/num2fraction-1.2.2.tgz#6f682b6a027a4e9ddfa4564cd2589d1d4e669ede"