From 8a56c7235dc8173f3b7d87a66ada846f1321d6ad Mon Sep 17 00:00:00 2001 From: cha0s Date: Tue, 1 Dec 2020 03:20:44 -0600 Subject: [PATCH] feat: core start --- packages/core/.gitignore | 1 + packages/core/.neutrinorc.js | 11 ++++ packages/core/package.json | 9 ++-- packages/core/src/start.js | 28 ++++++++++ packages/core/webpack.config.js | 6 +++ packages/core/yarn.lock | 90 +++++++++++++++++++++++++++++++-- template/.neutrinorc.js | 3 ++ template/src/index.js | 26 +--------- 8 files changed, 143 insertions(+), 31 deletions(-) create mode 100644 packages/core/.neutrinorc.js create mode 100644 packages/core/src/start.js create mode 100644 packages/core/webpack.config.js diff --git a/packages/core/.gitignore b/packages/core/.gitignore index e69de29..004003a 100644 --- a/packages/core/.gitignore +++ b/packages/core/.gitignore @@ -0,0 +1 @@ +/start.js* diff --git a/packages/core/.neutrinorc.js b/packages/core/.neutrinorc.js new file mode 100644 index 0000000..8a95bbc --- /dev/null +++ b/packages/core/.neutrinorc.js @@ -0,0 +1,11 @@ +const copy = require('@neutrinojs/copy'); + +const config = require('../../config/.neutrinorc'); +config.options = { + mains: { + index: 'index', + start: 'start', + }, +}; + +module.exports = config; diff --git a/packages/core/package.json b/packages/core/package.json index ffec284..050e998 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -5,14 +5,16 @@ "author": "cha0s", "license": "MIT", "scripts": { - "build": "NODE_PATH=./node_modules webpack --mode production --config ../../config/webpack.config.js", + "build": "NODE_PATH=./node_modules webpack --mode production", "lint": "NODE_PATH=./node_modules eslint --format codeframe --ext mjs,js .", "test": "NODE_PATH=./node_modules mocha --config ../../config/.mocharc.js", - "watch": "NODE_PATH=./node_modules webpack --watch --mode development --config ../../config/webpack.config.js" + "watch": "NODE_PATH=./node_modules webpack --watch --mode development" }, "files": [ "index.js", - "index.js.map" + "index.js.map", + "start.js", + "start.js.map" ], "dependencies": { "js-yaml": "3.14.0", @@ -20,6 +22,7 @@ }, "devDependencies": { "@neutrinojs/airbnb-base": "^9.4.0", + "@neutrinojs/copy": "^9.4.0", "@neutrinojs/library": "^9.4.0", "@neutrinojs/mocha": "^9.4.0", "chai": "4.2.0", diff --git a/packages/core/src/start.js b/packages/core/src/start.js new file mode 100644 index 0000000..8725791 --- /dev/null +++ b/packages/core/src/start.js @@ -0,0 +1,28 @@ +import {join} from 'path'; + +import Plugins from './plugins'; +import readConfig from './read-config'; + +process.stdout.write('Latus starting...\n'); + +// eslint-disable-next-line no-eval +const r = eval('require'); + +(async () => { + const config = readConfig(); + const paths = Object.entries(config).map(([plugin]) => { + try { + r.resolve(plugin); + return plugin; + } + catch (error) { + return join(process.cwd(), plugin); + } + }); + const plugins = new Plugins({ + config, + modules: paths.map((path) => r(path)), + }); + await Promise.all(plugins.invokeFlat('@latus/core/up')); + process.stdout.write('Latus up!\n'); +})(); diff --git a/packages/core/webpack.config.js b/packages/core/webpack.config.js new file mode 100644 index 0000000..54d98e8 --- /dev/null +++ b/packages/core/webpack.config.js @@ -0,0 +1,6 @@ +// Whilst the configuration object can be modified here, the recommended way of making +// changes is via the presets' options or Neutrino's API in `.neutrinorc.js` instead. +// Neutrino's inspect feature can be used to view/export the generated configuration. +const neutrino = require('neutrino'); + +module.exports = neutrino(require(`${__dirname}/.neutrinorc`)).webpack(); diff --git a/packages/core/yarn.lock b/packages/core/yarn.lock index 4ecb7cb..287e08e 100644 --- a/packages/core/yarn.lock +++ b/packages/core/yarn.lock @@ -871,6 +871,13 @@ "@babel/core" "^7.11.4" babel-loader "^8.1.0" +"@neutrinojs/copy@^9.4.0": + version "9.4.0" + resolved "https://npm.i12e.cha0s.io/@neutrinojs%2fcopy/-/copy-9.4.0.tgz#258b72297c2feac32d3fc756175fa539c0543d62" + integrity sha512-8Ki7aFHZV+3FNHTDNPfIfOHYVAVDVrv1GGiyHwEGpXEjYIioSVT9KlWXanJpNEJZ2MkEduhljL7mcM5+5yBRcg== + dependencies: + copy-webpack-plugin "^5.1.1" + "@neutrinojs/eslint@9.4.0": version "9.4.0" resolved "https://npm.i12e.cha0s.io/@neutrinojs%2feslint/-/eslint-9.4.0.tgz#05436d95d8b0a07f305e289af3e72825859eab9f" @@ -1178,6 +1185,11 @@ ansi-colors@4.1.1, ansi-colors@^4.1.1: resolved "https://npm.i12e.cha0s.io/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348" integrity sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA== +ansi-colors@^3.0.0: + version "3.2.4" + resolved "https://npm.i12e.cha0s.io/ansi-colors/-/ansi-colors-3.2.4.tgz#e3a3da4bfbae6c86a9c285625de124a234026fbf" + integrity sha512-hHUXGagefjN2iRrID63xckIvotOXOojhQKWIPUZ4mNUZ9nLZW+7FMNoE1lOkEhNWYsx/7ysGIuJYCiMAA9FnrA== + ansi-regex@^3.0.0: version "3.0.0" resolved "https://npm.i12e.cha0s.io/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" @@ -1569,7 +1581,7 @@ builtin-status-codes@^3.0.0: resolved "https://npm.i12e.cha0s.io/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" integrity sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug= -cacache@^12.0.2: +cacache@^12.0.2, cacache@^12.0.3: version "12.0.4" resolved "https://npm.i12e.cha0s.io/cacache/-/cacache-12.0.4.tgz#668bcbd105aeb5f1d92fe25570ec9525c8faa40c" integrity sha512-a0tMB40oefvuInr4Cwb3GerbL9xTj1D5yg0T5xrjGCGyfvbxseIXX7BAO/u/hIXdafzOI5JC3wDwHyf24buOAQ== @@ -1859,6 +1871,24 @@ copy-descriptor@^0.1.0: resolved "https://npm.i12e.cha0s.io/copy-descriptor/-/copy-descriptor-0.1.1.tgz#676f6eb3c39997c2ee1ac3a924fd6124748f578d" integrity sha1-Z29us8OZl8LuGsOpJP1hJHSPV40= +copy-webpack-plugin@^5.1.1: + version "5.1.2" + resolved "https://npm.i12e.cha0s.io/copy-webpack-plugin/-/copy-webpack-plugin-5.1.2.tgz#8a889e1dcafa6c91c6cd4be1ad158f1d3823bae2" + integrity sha512-Uh7crJAco3AjBvgAy9Z75CjK8IG+gxaErro71THQ+vv/bl4HaQcpkexAY8KVW/T6D2W2IRr+couF/knIRkZMIQ== + dependencies: + cacache "^12.0.3" + find-cache-dir "^2.1.0" + glob-parent "^3.1.0" + globby "^7.1.1" + is-glob "^4.0.1" + loader-utils "^1.2.3" + minimatch "^3.0.4" + normalize-path "^3.0.0" + p-limit "^2.2.1" + schema-utils "^1.0.0" + serialize-javascript "^4.0.0" + webpack-log "^2.0.0" + core-js-compat@^3.7.0: version "3.8.0" resolved "https://npm.i12e.cha0s.io/core-js-compat/-/core-js-compat-3.8.0.tgz#3248c6826f4006793bd637db608bca6e4cd688b1" @@ -2079,6 +2109,13 @@ diffie-hellman@^5.0.0: miller-rabin "^4.0.0" randombytes "^2.0.0" +dir-glob@^2.0.0: + version "2.2.2" + resolved "https://npm.i12e.cha0s.io/dir-glob/-/dir-glob-2.2.2.tgz#fa09f0694153c8918b18ba0deafae94769fc50c4" + integrity sha512-f9LBi5QWzIW3I6e//uxZoLBlUt9kcp66qo0sSCxL6YZKc75R1c4MFCoe/LaZiBGmgujvQdxc5Bn3QhfyvK5Hsw== + dependencies: + path-type "^3.0.0" + doctrine@1.5.0: version "1.5.0" resolved "https://npm.i12e.cha0s.io/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa" @@ -2739,7 +2776,7 @@ glob-parent@^5.0.0, glob-parent@~5.1.0: dependencies: is-glob "^4.0.1" -glob@7.1.6, glob@^7.0.3, glob@^7.1.3, glob@^7.1.4: +glob@7.1.6, glob@^7.0.3, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4: version "7.1.6" resolved "https://npm.i12e.cha0s.io/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== @@ -2810,6 +2847,18 @@ globby@^6.1.0: pify "^2.0.0" pinkie-promise "^2.0.0" +globby@^7.1.1: + version "7.1.1" + resolved "https://npm.i12e.cha0s.io/globby/-/globby-7.1.1.tgz#fb2ccff9401f8600945dfada97440cca972b8680" + integrity sha1-+yzP+UAfhgCUXfral0QMypcrhoA= + dependencies: + array-union "^1.0.1" + dir-glob "^2.0.0" + glob "^7.1.2" + ignore "^3.3.5" + pify "^3.0.0" + slash "^1.0.0" + graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.2.0: version "4.2.4" resolved "https://npm.i12e.cha0s.io/graceful-fs/-/graceful-fs-4.2.4.tgz#2256bde14d3632958c465ebc96dc467ca07a29fb" @@ -2931,6 +2980,11 @@ iferr@^0.1.5: resolved "https://npm.i12e.cha0s.io/iferr/-/iferr-0.1.5.tgz#c60eed69e6d8fdb6b3104a1fcbca1c192dc5b501" integrity sha1-xg7taebY/bazEEofy8ocGS3FtQE= +ignore@^3.3.5: + version "3.3.10" + resolved "https://npm.i12e.cha0s.io/ignore/-/ignore-3.3.10.tgz#0a97fb876986e8081c631160f8f9f389157f0043" + integrity sha512-Pgs951kaMm5GXP7MOvxERINe3gsaVjUWFm+UZPSq9xYriQAksyhg0csnS0KXSNRD5NmNdapXEpjxG49+AKh/ug== + ignore@^4.0.6: version "4.0.6" resolved "https://npm.i12e.cha0s.io/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" @@ -3819,7 +3873,7 @@ p-limit@^1.1.0: dependencies: p-try "^1.0.0" -p-limit@^2.0.0, p-limit@^2.2.0: +p-limit@^2.0.0, p-limit@^2.2.0, p-limit@^2.2.1: version "2.3.0" resolved "https://npm.i12e.cha0s.io/p-limit/-/p-limit-2.3.0.tgz#3dd33c647a214fdfffd835933eb086da0dc21db1" integrity sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w== @@ -3977,6 +4031,13 @@ path-type@^2.0.0: dependencies: pify "^2.0.0" +path-type@^3.0.0: + version "3.0.0" + resolved "https://npm.i12e.cha0s.io/path-type/-/path-type-3.0.0.tgz#cef31dc8e0a1a3bb0d105c0cd97cf3bf47f4e36f" + integrity sha512-T2ZUsdZFHgA3u4e5PfPbjd7HDDpxPnQb5jN0SrDsjNSuVXHJqtwTnWqG0B1jZrgmJ/7lj1EmVIByWt1gxGkWvg== + dependencies: + pify "^3.0.0" + pathval@^1.1.0: version "1.1.0" resolved "https://npm.i12e.cha0s.io/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0" @@ -4003,6 +4064,11 @@ pify@^2.0.0: resolved "https://npm.i12e.cha0s.io/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" integrity sha1-7RQaasBDqEnqWISY59yosVMw6Qw= +pify@^3.0.0: + version "3.0.0" + resolved "https://npm.i12e.cha0s.io/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" + integrity sha1-5aSs0sEB/fPZpNB/DbxNtJ3SgXY= + pify@^4.0.1: version "4.0.1" resolved "https://npm.i12e.cha0s.io/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231" @@ -4499,6 +4565,11 @@ shebang-regex@^3.0.0: resolved "https://npm.i12e.cha0s.io/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +slash@^1.0.0: + version "1.0.0" + resolved "https://npm.i12e.cha0s.io/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" + integrity sha1-xB8vbDn8FtHNF61LXYlhFK5HDVU= + slice-ansi@^2.1.0: version "2.1.0" resolved "https://npm.i12e.cha0s.io/slice-ansi/-/slice-ansi-2.1.0.tgz#cacd7693461a637a5788d92a7dd4fba068e81636" @@ -5023,6 +5094,11 @@ util@^0.11.0: dependencies: inherits "2.0.3" +uuid@^3.3.2: + version "3.4.0" + resolved "https://npm.i12e.cha0s.io/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" + integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== + v8-compile-cache@^2.0.3, v8-compile-cache@^2.1.1: version "2.2.0" resolved "https://npm.i12e.cha0s.io/v8-compile-cache/-/v8-compile-cache-2.2.0.tgz#9471efa3ef9128d2f7c6a7ca39c4dd6b5055b132" @@ -5084,6 +5160,14 @@ webpack-cli@^3: v8-compile-cache "^2.1.1" yargs "^13.3.2" +webpack-log@^2.0.0: + version "2.0.0" + resolved "https://npm.i12e.cha0s.io/webpack-log/-/webpack-log-2.0.0.tgz#5b7928e0637593f119d32f6227c1e0ac31e1b47f" + integrity sha512-cX8G2vR/85UYG59FgkoMamwHUIkSSlV3bBMRsbxVXVUk2j6NleCKjQ/WE9eYg9WY4w25O9w8wKP4rzNZFmUcUg== + dependencies: + ansi-colors "^3.0.0" + uuid "^3.3.2" + webpack-node-externals@^1.7.2: version "1.7.2" resolved "https://npm.i12e.cha0s.io/webpack-node-externals/-/webpack-node-externals-1.7.2.tgz#6e1ee79ac67c070402ba700ef033a9b8d52ac4e3" diff --git a/template/.neutrinorc.js b/template/.neutrinorc.js index 716f524..7c73049 100644 --- a/template/.neutrinorc.js +++ b/template/.neutrinorc.js @@ -31,6 +31,9 @@ module.exports = { .use(EnvironmentPlugin, [{ SIDE: 'server', }]); + neutrino.config + .entry('index') + .prepend('@latus/core/start'); if ('production' !== neutrino.config.get('mode')) { neutrino.config .entry('index') diff --git a/template/src/index.js b/template/src/index.js index 858e50b..6327b0e 100644 --- a/template/src/index.js +++ b/template/src/index.js @@ -1,25 +1 @@ -// eslint-disable-next-line import/no-extraneous-dependencies -const {join} = require('path'); - -const {Plugins, readConfig} = require('@latus/core'); - -process.stdout.write('Latus starting...\n'); - -(async () => { - const config = readConfig(); - const paths = Object.entries(config).map(([plugin]) => { - try { - __non_webpack_require__.resolve(plugin); - return plugin; - } - catch (error) { - return join(process.cwd(), plugin); - } - }); - const plugins = new Plugins({ - config, - modules: paths.map((path) => __non_webpack_require__(path)), - }); - await Promise.all(plugins.invokeFlat('@latus/core/up')); - process.stdout.write('Latus up!\n'); -})(); +process.stdout.write('Your application is starting...\n');