@sum.cumo/nuxt-custom-route-folder
Advanced tools
Comparing version 3.0.0-beta.2 to 3.0.0-beta.3
@@ -23,2 +23,6 @@ 'use strict'; | ||
var _minimatch = require('minimatch'); | ||
var _minimatch2 = _interopRequireDefault(_minimatch); | ||
var _operators = require('rxjs/operators'); | ||
@@ -76,9 +80,14 @@ | ||
var watch$ = (0, _observe2.default)(glob, watch); | ||
var watch$ = (0, _observe2.default)(srcDir, watch).pipe((0, _operators.filter)(function (_ref2) { | ||
var event = _ref2.event, | ||
file = _ref2.file; | ||
return event === 'ready' || (0, _minimatch2.default)(file, glob); | ||
})); | ||
var getRoute = function () { | ||
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref2) { | ||
var file = _ref2.file; | ||
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref3) { | ||
var file = _ref3.file; | ||
var basePath, urlPath, chunkName, _ref4, _ref5, routePath, name, meta, component; | ||
var basePath, urlPath, chunkName, _ref5, _ref6, routePath, name, meta, component; | ||
@@ -98,8 +107,8 @@ return regeneratorRuntime.wrap(function _callee$(_context) { | ||
case 5: | ||
_ref4 = _context.sent; | ||
_ref5 = _slicedToArray(_ref4, 4); | ||
routePath = _ref5[0]; | ||
name = _ref5[1]; | ||
meta = _ref5[2]; | ||
component = _ref5[3]; | ||
_ref5 = _context.sent; | ||
_ref6 = _slicedToArray(_ref5, 4); | ||
routePath = _ref6[0]; | ||
name = _ref6[1]; | ||
meta = _ref6[2]; | ||
component = _ref6[3]; | ||
return _context.abrupt('return', { | ||
@@ -123,3 +132,3 @@ path: routePath, | ||
return function getRoute(_x) { | ||
return _ref3.apply(this, arguments); | ||
return _ref4.apply(this, arguments); | ||
}; | ||
@@ -129,3 +138,3 @@ }(); | ||
var processFileMsg = function () { | ||
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(message) { | ||
var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(message) { | ||
var include; | ||
@@ -190,8 +199,8 @@ return regeneratorRuntime.wrap(function _callee2$(_context2) { | ||
return function processFileMsg(_x2) { | ||
return _ref6.apply(this, arguments); | ||
return _ref7.apply(this, arguments); | ||
}; | ||
}(); | ||
var readyFilter = (0, _operators.filter)(function (_ref7) { | ||
var event = _ref7.event; | ||
var readyFilter = (0, _operators.filter)(function (_ref8) { | ||
var event = _ref8.event; | ||
return event === 'ready'; | ||
@@ -219,8 +228,8 @@ }); | ||
fs$.pipe((0, _operators.filter)(function (_ref8) { | ||
var event = _ref8.event; | ||
fs$.pipe((0, _operators.filter)(function (_ref9) { | ||
var event = _ref9.event; | ||
return event !== 'ready'; | ||
})).forEach(function (_ref9) { | ||
var event = _ref9.event, | ||
route = _ref9.route; | ||
})).forEach(function (_ref10) { | ||
var event = _ref10.event, | ||
route = _ref10.route; | ||
@@ -227,0 +236,0 @@ if (event === 'unlink') { |
@@ -19,5 +19,8 @@ 'use strict'; | ||
var builder = null; | ||
var initialUpdate = false; | ||
var update = function update() { | ||
if (builder) { | ||
builder.generateRoutesAndFiles(); | ||
} else if (nuxt.options.dev) { | ||
initialUpdate = true; | ||
} | ||
@@ -28,5 +31,13 @@ }; | ||
builder = b; | ||
if (initialUpdate) { | ||
console.log('routes got updated in initial build - rebuilding.'); | ||
b.generateRoutesAndFiles(); | ||
} | ||
}); | ||
nuxt.hook('build:extendRoutes', function (routes) { | ||
if (nuxt.options.dev && !builder) { | ||
return; | ||
} | ||
customRoutes.forEach(function (route) { | ||
@@ -33,0 +44,0 @@ if (!routes.includes(route)) { |
@@ -8,2 +8,6 @@ 'use strict'; | ||
var _path = require('path'); | ||
var path = _interopRequireWildcard(_path); | ||
var _rxjs = require('rxjs'); | ||
@@ -17,9 +21,16 @@ | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
var cache = {}; | ||
function observe(glob, watch) { | ||
if (!cache[glob]) { | ||
cache[glob] = _rxjs.Observable.create(function (observer) { | ||
var done = false; | ||
var watcher = _chokidar2.default.watch(glob);['add', 'change', 'unlink'].forEach(function (event) { | ||
function observe(srcDir, watch) { | ||
if (!cache[srcDir]) { | ||
var watcher = _chokidar2.default.watch(path.join(srcDir, '**'), { | ||
ignored: path.join(srcDir, '**', 'node_modules', '**') | ||
}); | ||
watcher.setMaxListeners(30); | ||
cache[srcDir] = _rxjs.Observable.create(function (observer) { | ||
var done = false;['add', 'change', 'unlink'].forEach(function (event) { | ||
watcher.on(event, function (file) { | ||
@@ -61,3 +72,3 @@ observer.next({ | ||
return cache[glob]; | ||
return cache[srcDir]; | ||
} |
{ | ||
"name": "@sum.cumo/nuxt-custom-route-folder", | ||
"version": "3.0.0-beta.2", | ||
"version": "3.0.0-beta.3", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
import path from 'path' | ||
import kebabCase from 'lodash.kebabcase' | ||
import { Observable } from 'rxjs' | ||
import minimatch from 'minimatch' | ||
import { | ||
@@ -30,3 +31,7 @@ concatMap, | ||
const watch$ = observe(glob, watch) | ||
const watch$ = observe(srcDir, watch).pipe( | ||
rxFilter(({ event, file }) => { | ||
return event === 'ready' || minimatch(file, glob) | ||
}) | ||
) | ||
@@ -33,0 +38,0 @@ const getRoute = async ({ file }) => { |
@@ -8,5 +8,8 @@ import CHUNK_PREFIX from './chunkPrefix' | ||
let builder = null | ||
let initialUpdate = false | ||
const update = () => { | ||
if (builder) { | ||
builder.generateRoutesAndFiles() | ||
} else if (nuxt.options.dev) { | ||
initialUpdate = true | ||
} | ||
@@ -17,5 +20,13 @@ } | ||
builder = b | ||
if (initialUpdate) { | ||
console.log('routes got updated in initial build - rebuilding.') | ||
b.generateRoutesAndFiles() | ||
} | ||
}) | ||
nuxt.hook('build:extendRoutes', (routes) => { | ||
if (nuxt.options.dev && !builder) { | ||
return | ||
} | ||
customRoutes.forEach((route) => { | ||
@@ -22,0 +33,0 @@ if (!routes.includes(route)) { |
@@ -0,1 +1,2 @@ | ||
import * as path from 'path' | ||
import { Observable } from 'rxjs' | ||
@@ -6,7 +7,12 @@ import chokidar from 'chokidar' | ||
export default function observe(glob, watch) { | ||
if (!cache[glob]) { | ||
cache[glob] = Observable.create((observer) => { | ||
export default function observe(srcDir, watch) { | ||
if (!cache[srcDir]) { | ||
const watcher = chokidar.watch(path.join(srcDir, '**'), { | ||
ignored: path.join(srcDir, '**', 'node_modules', '**'), | ||
}) | ||
watcher.setMaxListeners(30) | ||
cache[srcDir] = Observable.create((observer) => { | ||
let done = false | ||
const watcher = chokidar.watch(glob) | ||
;['add', 'change', 'unlink'].forEach((event) => { | ||
@@ -49,3 +55,3 @@ watcher.on(event, (file) => { | ||
return cache[glob] | ||
return cache[srcDir] | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
338411
613
1