From 96a1ff995a25a9b3837ea831730f58749a9fa8ec Mon Sep 17 00:00:00 2001 From: "romain.lenzotti" Date: Tue, 6 Nov 2018 15:18:36 +0100 Subject: [PATCH] feat(fractal): Add fractal copy task --- packages/cli-plugin-fractal/index.js | 51 ++++-- packages/cli-plugin-fractal/package-lock.json | 173 +++++++++++++++--- packages/cli-plugin-fractal/package.json | 3 + .../cli-plugin-fractal/src/fractal/index.js | 28 +++ packages/cli/package-lock.json | 28 +-- 5 files changed, 224 insertions(+), 59 deletions(-) diff --git a/packages/cli-plugin-fractal/index.js b/packages/cli-plugin-fractal/index.js index ccbfcf8..f595841 100644 --- a/packages/cli-plugin-fractal/index.js +++ b/packages/cli-plugin-fractal/index.js @@ -1,4 +1,4 @@ -/* eslint-disable global-require,import/no-dynamic-require */ +/* eslint-disable global-require,import/no-dynamic-require,no-case-declarations */ const log = require('fancy-log'); const chalk = require('chalk'); const fractal = require('./src/fractal'); @@ -7,7 +7,7 @@ module.exports = (api, config) => { api.registerCommand( 'fractal', { - usage: ' [options]', + usage: ' [options]', description: 'Run or build a fractal server', options: { '-e, --execute ': { @@ -19,24 +19,41 @@ module.exports = (api, config) => { async (commander, args) => { const [mode = 'serve'] = args; - if (mode === 'serve') { - let port; - if (commander.execute) { - port = await fractal.runDevBefore(commander.execute); - } + switch (mode) { + case 'serve': + let port; + if (commander.execute) { + port = await fractal.runDevBefore(commander.execute); + } - await fractal.dev(config, port); - } else { - log(`Starting build fractal...`); - await fractal.build(config); + await fractal.dev(config, port); + break; - if (commander.execute) { - log(`Starting build app '${chalk.cyan(commander.execute)}'...`); - await fractal.runBuildAfter(commander.execute, config); - log(`Finished build'${chalk.cyan(commander.execute)}'`); - } + case 'build': + log(`Starting build fractal...`); + await fractal.build(config); + + if (commander.execute) { + log(`Starting build app '${chalk.cyan(commander.execute)}'...`); + await fractal.runBuildAfter(commander.execute, config); + log(`Finished build'${chalk.cyan(commander.execute)}'`); + } + + log(`Fractal static HTML build complete in ${config.fractal.outputDir}`); + break; + + case 'copy': + if (config.get('fractal').copy) { + log(`Starting copy documentation...`); + await fractal.copy(config); + } else { + log(`No copy tasks has registered in fractal configuration`); + } + + break; - log(`Fractal static HTML build complete in ${config.fractal.outputDir}`); + default: + break; } } ); diff --git a/packages/cli-plugin-fractal/package-lock.json b/packages/cli-plugin-fractal/package-lock.json index 4ba8ce1..c84943b 100644 --- a/packages/cli-plugin-fractal/package-lock.json +++ b/packages/cli-plugin-fractal/package-lock.json @@ -187,6 +187,14 @@ "string-width": "^1.0.1" } }, + "ansi-cyan": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ansi-cyan/-/ansi-cyan-0.1.1.tgz", + "integrity": "sha1-U4rlKK+JgvKK4w2G8vF0VtJgmHM=", + "requires": { + "ansi-wrap": "0.1.0" + } + }, "ansi-escapes": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-1.4.0.tgz", @@ -2403,14 +2411,12 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "optional": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2425,20 +2431,17 @@ "code-point-at": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", - "optional": true + "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "optional": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", - "optional": true + "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=" }, "core-util-is": { "version": "1.0.2", @@ -2555,8 +2558,7 @@ "inherits": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", - "optional": true + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, "ini": { "version": "1.3.5", @@ -2568,7 +2570,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -2583,7 +2584,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -2591,14 +2591,12 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "optional": true + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "minipass": { "version": "2.2.4", "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.2.4.tgz", "integrity": "sha512-hzXIWWet/BzWhYs2b+u7dRHlruXhwdgvlTMDKC6Cb1U7ps6Ac6yQlR39xsbjWJE377YTCtKwIXIpJ5oP+j5y8g==", - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -2617,7 +2615,6 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "optional": true, "requires": { "minimist": "0.0.8" } @@ -2698,8 +2695,7 @@ "number-is-nan": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", - "optional": true + "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, "object-assign": { "version": "4.1.1", @@ -2711,7 +2707,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "optional": true, "requires": { "wrappy": "1" } @@ -2833,7 +2828,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -2910,6 +2904,11 @@ "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz", "integrity": "sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==" }, + "get-own-enumerable-property-symbols": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/get-own-enumerable-property-symbols/-/get-own-enumerable-property-symbols-3.0.0.tgz", + "integrity": "sha512-CIJYJC4GGF06TakLg8z4GQKvDsx9EMspVxOYih7LerEL/WosUnFIww45CGfxfeKHqlg3twgUrYRT1O3WQqjGCg==" + }, "get-stream": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.0.0.tgz", @@ -3040,6 +3039,37 @@ "toml": "^2.3.2" } }, + "gulp-debug": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/gulp-debug/-/gulp-debug-4.0.0.tgz", + "integrity": "sha512-cn/GhMD2nVZCVxAl5vWao4/dcoZ8wUJ8w3oqTvQaGDmC1vT7swNOEbhQTWJp+/otKePT64aENcqAQXDcdj5H1g==", + "requires": { + "chalk": "^2.3.0", + "fancy-log": "^1.3.2", + "plur": "^3.0.0", + "stringify-object": "^3.0.0", + "through2": "^2.0.0", + "tildify": "^1.1.2" + } + }, + "gulp-newer": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/gulp-newer/-/gulp-newer-1.4.0.tgz", + "integrity": "sha512-h79fGO55S/P9eAADbLAP9aTtVYpLSR1ONj08VPaSdVVNVYhTS8p1CO1TW7kEMu+hC+sytmCqcUr5LesvZEtDoQ==", + "requires": { + "glob": "^7.0.3", + "kew": "^0.7.0", + "plugin-error": "^0.1.2" + } + }, + "gulp-tap": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gulp-tap/-/gulp-tap-1.0.1.tgz", + "integrity": "sha1-5nESThJZtM6iGe0cqXt/WFwzRpA=", + "requires": { + "through2": "^2.0.3" + } + }, "handlebars": { "version": "4.0.11", "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", @@ -3601,6 +3631,11 @@ "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz", "integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4=" }, + "irregular-plurals": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/irregular-plurals/-/irregular-plurals-2.0.0.tgz", + "integrity": "sha512-Y75zBYLkh0lJ9qxeHlMjQ7bSbyiSqNW/UOPWDmzC7cXskL1hekSITh1Oc6JV0XCWWZ9DE8VYSB71xocLk3gmGw==" + }, "is-absolute": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-absolute/-/is-absolute-1.0.0.tgz", @@ -3777,6 +3812,11 @@ "resolved": "https://registry.npmjs.org/is-redirect/-/is-redirect-1.0.0.tgz", "integrity": "sha1-HQPd7VO9jbDzDCbk+V02/HyH3CQ=" }, + "is-regexp": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-regexp/-/is-regexp-1.0.0.tgz", + "integrity": "sha1-/S2INUXEa6xaYz57mgnof6LLUGk=" + }, "is-relative": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-relative/-/is-relative-1.0.0.tgz", @@ -3869,6 +3909,11 @@ "graceful-fs": "^4.1.6" } }, + "kew": { + "version": "0.7.0", + "resolved": "http://registry.npmjs.org/kew/-/kew-0.7.0.tgz", + "integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=" + }, "kind-of": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", @@ -4746,6 +4791,60 @@ "pinkie": "^2.0.0" } }, + "plugin-error": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/plugin-error/-/plugin-error-0.1.2.tgz", + "integrity": "sha1-O5uzM1zPAPQl4HQ34ZJ2ln2kes4=", + "requires": { + "ansi-cyan": "^0.1.1", + "ansi-red": "^0.1.1", + "arr-diff": "^1.0.1", + "arr-union": "^2.0.1", + "extend-shallow": "^1.1.2" + }, + "dependencies": { + "arr-diff": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/arr-diff/-/arr-diff-1.1.0.tgz", + "integrity": "sha1-aHwydYFjWI/vfeezb6vklesaOZo=", + "requires": { + "arr-flatten": "^1.0.1", + "array-slice": "^0.2.3" + } + }, + "arr-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/arr-union/-/arr-union-2.1.0.tgz", + "integrity": "sha1-IPnqtexw9cfSFbEHexw5Fh0pLH0=" + }, + "array-slice": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/array-slice/-/array-slice-0.2.3.tgz", + "integrity": "sha1-3Tz7gO15c6dRF82sabC5nshhhvU=" + }, + "extend-shallow": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-1.1.4.tgz", + "integrity": "sha1-Gda/lN/AnXa6cR85uHLSH/TdkHE=", + "requires": { + "kind-of": "^1.1.0" + } + }, + "kind-of": { + "version": "1.1.0", + "resolved": "http://registry.npmjs.org/kind-of/-/kind-of-1.1.0.tgz", + "integrity": "sha1-FAo9LUGjbS78+pN3tiwk+ElaXEQ=" + } + } + }, + "plur": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/plur/-/plur-3.0.1.tgz", + "integrity": "sha512-lJl0ojUynAM1BZn58Pas2WT/TXeC1+bS+UqShl0x9+49AtOn7DixRXVzaC8qrDOIxNDmepKnLuMTH7NQmkX0PA==", + "requires": { + "irregular-plurals": "^2.0.0" + } + }, "portscanner": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/portscanner/-/portscanner-1.2.0.tgz", @@ -5667,6 +5766,16 @@ "safe-buffer": "~5.1.0" } }, + "stringify-object": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/stringify-object/-/stringify-object-3.3.0.tgz", + "integrity": "sha512-rHqiFh1elqCQ9WPLIC8I0Q/g/wj5J1eMkyoiD6eoQApWHP0FtlK7rqnhmabL5VUY9JQCcqwwvlOaSuutekgyrw==", + "requires": { + "get-own-enumerable-property-symbols": "^3.0.0", + "is-obj": "^1.0.1", + "is-regexp": "^1.0.0" + } + }, "strip-ansi": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", @@ -5751,6 +5860,23 @@ "resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz", "integrity": "sha1-DdTJ/6q8NXlgsbckEV1+Doai4fU=" }, + "through2": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.4.tgz", + "integrity": "sha512-q030OX7royN1Bo549nYMOpKwiGJIzUppv10IgB6ALN6DiJ/XgsRIehiz18x5RWCA3+s4G6ovKqtzgU+pYhjvvg==", + "requires": { + "readable-stream": "2 || 3", + "xtend": "~4.0.1" + } + }, + "tildify": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/tildify/-/tildify-1.2.0.tgz", + "integrity": "sha1-3OwD9V3Km3qj5bBPIYF+tW5jWIo=", + "requires": { + "os-homedir": "^1.0.0" + } + }, "time-stamp": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/time-stamp/-/time-stamp-1.1.0.tgz", @@ -6239,6 +6365,11 @@ "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.5.tgz", "integrity": "sha1-wodrBhaKrcQOV9l+gRkayPQ5iz4=" }, + "xtend": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz", + "integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68=" + }, "y18n": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz", diff --git a/packages/cli-plugin-fractal/package.json b/packages/cli-plugin-fractal/package.json index 84e2417..518fea4 100644 --- a/packages/cli-plugin-fractal/package.json +++ b/packages/cli-plugin-fractal/package.json @@ -16,6 +16,9 @@ "fancy-log": "^1.3.2", "fs-extra": "^7.0.0", "globby": "^8.0.1", + "gulp-debug": "^4.0.0", + "gulp-newer": "^1.4.0", + "gulp-tap": "^1.0.1", "http-proxy-middleware": "^0.18.0", "serve-static": "^1.13.2", "strip-ansi": "^4.0.0" diff --git a/packages/cli-plugin-fractal/src/fractal/index.js b/packages/cli-plugin-fractal/src/fractal/index.js index 755aa8c..d0e47f5 100644 --- a/packages/cli-plugin-fractal/src/fractal/index.js +++ b/packages/cli-plugin-fractal/src/fractal/index.js @@ -1,11 +1,39 @@ /* eslint-disable global-require,import/no-dynamic-require */ const execa = require('execa'); +const gulp = require('gulp'); +// const chalk = require('chalk'); +// const tap = require('gulp-tap'); +const debug = require('gulp-debug'); +const newer = require('gulp-newer'); const fs = require('fs-extra'); const log = require('fancy-log'); const stripAnsi = require('strip-ansi'); const createInstance = require('./create-instance'); +const toPromise = stream => + new Promise((resolve, reject) => + stream + .on('end', resolve) + .on('finish', resolve) + .on('error', reject) + ); + module.exports = { + async copy(config) { + const { copy = [] } = config.get('fractal'); + + const promises = copy.map(task => { + return toPromise( + gulp + .src(task.paths) + .pipe(newer(task.outputDir)) + .pipe(debug({ title: 'Copying ' })) + .pipe(gulp.dest(task.outputDir)) + ); + }); + + return Promise.all(promises); + }, /** * * @returns {*} diff --git a/packages/cli/package-lock.json b/packages/cli/package-lock.json index 33aed6b..007452f 100644 --- a/packages/cli/package-lock.json +++ b/packages/cli/package-lock.json @@ -1438,13 +1438,11 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true, - "optional": true + "bundled": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, - "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1457,18 +1455,15 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "concat-map": { "version": "0.0.1", - "bundled": true, - "optional": true + "bundled": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true, - "optional": true + "bundled": true }, "core-util-is": { "version": "1.0.2", @@ -1571,8 +1566,7 @@ }, "inherits": { "version": "2.0.3", - "bundled": true, - "optional": true + "bundled": true }, "ini": { "version": "1.3.5", @@ -1582,7 +1576,6 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, - "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1595,20 +1588,17 @@ "minimatch": { "version": "3.0.4", "bundled": true, - "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true, - "optional": true + "bundled": true }, "minipass": { "version": "2.2.4", "bundled": true, - "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -1625,7 +1615,6 @@ "mkdirp": { "version": "0.5.1", "bundled": true, - "optional": true, "requires": { "minimist": "0.0.8" } @@ -1698,8 +1687,7 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true, - "optional": true + "bundled": true }, "object-assign": { "version": "4.1.1", @@ -1709,7 +1697,6 @@ "once": { "version": "1.4.0", "bundled": true, - "optional": true, "requires": { "wrappy": "1" } @@ -1815,7 +1802,6 @@ "string-width": { "version": "1.0.2", "bundled": true, - "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",