Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
w.bundle()
.on('error', function(err) {
console.error(colors.red('\nError: ') + err.message);
res.end('console.error("' + err.message + '")');
this.emit('end');
})
.pipe(res);
});
// static files
server.use(serveStatic(directory));
server.use(serveIndex(directory));
// livereload server
if (process.env.NODE_ENV !== 'production') {
server.use(livereloadServer.middleware({ app: server }));
}
// start the server
server.listen(process.env.PORT || program.port, function () {
var htmlFile = (projectType === 'module') ? 'test.html' : '';
console.log(
colors.grey('%s running at ') + colors.cyan('http://localhost:%s/%s'),
projectType.charAt(0).toUpperCase() + projectType.slice(1),
program.port,
htmlFile
);
exec('open "http://localhost:' + program.port + '/' + htmlFile + '"');
});
em.on(evt, function(file) {
file = path.normalize(file);
// file = path.relative(cwd,file).replace(/\\/g,"/") || file;
file = path.relative(RES_ROOT,file).replace(/\\/g,"/") || file || "error/path";
console.log(getCurT() + " Send-Changed: " + color(file,"cyan"));
// send msg of changed file info
// sendMsg(file || "index.html");
tinyLr.changed(file || "index.html");//It is not 'server.changed({ params: { files: files }})'
});
});
console.log(`You are in ${process.env.NODE_ENV} mode`)
console.log(
'which means every change in your themes (templates, partials and assets), reference and structure folders will dynamically update your site'
)
console.log("In production, this mode shouldn't be used.")
this._watchersStart()
var lport = process.env.LIVERELOAD_PORT || 35729
this.lserver = express()
// Launching a Livereload server
this.lserver
.use(bodyParser.json())
.use(bodyParser.urlencoded({extended: true}))
.use(tinylr.middleware({app: this.lserver}))
.listen(lport, function() {
console.log('Livereload listening on %d', lport)
})
.on('error', function(err) {
if (err.code == 'EADDRINUSE') {
console.error(
clc.red("can't start the Abe's watch server\n"),
`This watch server has tried to listen on the port ${lport} but this server is already in use by another process...`
)
} else {
console.error(err)
}
})
process.on('SIGINT', () => {
try {
export default function docify(options = {}) {
let port = options.port || 3000;
let docsPath = options.src || 'docs';
let pkgPath = options.pkg || process.cwd();
let themePath = options.theme
|| fs.existsSync('docs/theme') && 'docs/theme'
|| path.join(__dirname, '../themes/minimal');
let builder = new broccoli.Builder(docsTree({ docsPath, pkgPath, themePath }));
let server = broccoli.server.serve(builder, { host: 'localhost', port });
// Start a livereload server
let lrserver = tinylr();
lrserver.listen(35729, () => {
setTimeout(() => {
// Trigger a reload on first start
lrserver.changed({ body: { files: [ 'livereload files' ] } });
}, 1000);
});
// Notify it on changes
server.watcher.on('change', function() {
lrserver.changed({ body: { files: [ 'livereload files' ] } });
});
}
monitor.on('created', (f, stat) => {
if (f.indexOf(`.${config.files.templates.extension}`) < 0) {
cmsTemplates.assets.copy()
tinylr.changed(f)
console.log(
'Assets have been synchronized after this creation: ' + f
)
} else {
this.getKeysFromSelect()
this.updateStructureAndTemplates()
if (typeof this.lserver != 'undefined') {
tinylr.changed(f)
}
this.events.template.emit('update')
}
})
monitor.on('changed', (f, curr, prev) => {
watcher.on('change', function (filepath) {
console.log('[Livereload] %s changed. Updating page.', filepath);
tinylr.changed(filepath);
});
});
monitor.on('created', f => {
this.updateReferences(f)
if (typeof this.lserver != 'undefined') {
tinylr.changed(f)
}
this.events.reference.emit('update')
})
monitor.on('changed', f => {
var server = express();
var startFileWatcher = function() {
var watcher = chokidar.watch(assetPath + '/**/*');
watcher.on('ready', function(){
console.log('Livereload enabled. Watching for changes in', assetPath);
watcher.on('all', function(event, path) {
tinylr.changed(path)
});
});
};
if(livereload) {
server
.use(tinylr.middleware({ app: server, dashboard: true }))
.use(require('connect-livereload')({
src: '/livereload.js?snipver=1',
include: [ '/', '.*\.html']
}));
}
if(cors) {
server.use(function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', req.get('Access-Control-Request-Headers') || '*');
next();
});
}
server
.use(express.static(assetPath, {
bundlerEmitter.on('update', () => {
LiveReload.changed(bundleUrl)
})
app.use(injectLiveReloadScript())
.on('all', function(event, file) {
livereloadServer.changed(file);
});