Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((resolve, reject) => {
// We write sketch actions to a specitic file, so we can listen to this file
// to know in node when an action has been fired
watch.createMonitor(ACTIONS_FOLDER_PATH, monitor => {
monitor.on('created', () => {
// NOTE: for some reason the action API doesn't work when running a plugin
// from anywhere else than the plugin folder, so we cannot rely on it to
// resolve the promise
//
// TODO: find alternative way!
//
// saveDocument();
// setTimeout(() => {
// resolve();
// monitor.stop();
// }, 200);
});
// Run command with current plugin and given identifier
sketchtool.runPluginWithIdentifier(
function fileWatch(monitorPath, remote) {
var monitor;
// start watch
file.walk(monitorPath, onFileWalk);
watch.createMonitor(monitorPath, function(_monitor) {
monitor = _monitor;
monitor.on('created', function(f, stat) {
f = resolvePath(f);
console.log('file added:', f);
if (validFile(f) && ! stat.isDirectory()) {
remote.emit('file added', f);
}
});
monitor.on('removed', function(f) {
f = resolvePath(f);
if (validFile(f)) remote.emit('file removed', f);
});
});
// compile and save
var compiled = dust.compile(String(data), templateId);
var dirname = path.dirname(output_path);
if (!fs.existsSync(dirname)) {
fs.mkdirSync(dirname);
}
fs.writeFile(output_path, compiled, function(err) {
if (err) throw err;
console.log('Saved ' + output_path);
});
});
}
watch.createMonitor(input_path, {
persistent: true,
interval: 100
}, function (monitor) {
console.log("Watching " + input_path);
monitor.files = ['*.dust', '*/*'];
monitor.on("created", function (f, stat) {
if (fs.lstatSync(f).isDirectory()) {
return;
}
compile_dust(f);
});
monitor.on("changed", function (f, curr, prev) {
if (fs.lstatSync(f).isDirectory()) {
return;
}
compile_dust(f);
fs.outputJson(paths.build + '/manifest.json', manifest);
// Copy framework
console.log('Copy satchel framework');
fs.emptyDirSync(paths.build + '/Satchel.framework');
fs.copySync(paths.framework, paths.build + '/Satchel.framework');
// Done :)
console.log(chalk.green('✓ Compiled successfully.'));
console.log();
// Start watching
if (!watching) {
console.log('Start watching...');
watching = true;
watch.createMonitor(paths.src, function (monitor) {
monitor.on("created", build);
monitor.on("changed", build);
monitor.on("removed", build);
});
}
}).catch(function (e) {
// Catch any possible parse errors
monitor: function(){
var watch = require('watch'), me = this;
watch.createMonitor(require('path').resolve(this.path),function(monitor){
monitor.on("created", function (filename, stat) {
if (!me.running)
return; // Ignore if the server isn't running
/**
* @event filecreated
* Fired when a new file is created in the server directory (recursive)
*/
me.emit('filecreated',{filename:filename,server:me});
me.syslog.log((filename+' created.'));
});
monitor.on("changed", function (filename, curr, prev) {
if (!me.running)
return; // Ignore if the server isn't running
/**
* @event fileupdated
* Fired when a file is modified somewhere in the server directory (recursive)
var setupWatchMonitor = function(dir) {
watch.createMonitor(dir, function (monitor) {
monitor.on("created", function (f, stat) {
// Handle file changes
scli.log("New file detected: '" + f + "'");
rider.templates = [];
readAndCompile();
});
monitor.on("changed", function (f, curr, prev) {
// Handle new files
scli.log("File change detected: '" + f + "'");
rider.templates = [];
readAndCompile();
});
monitor.on("removed", function (f, stat) {
// Handle removed files
scli.log("File removed: '" + f + "'");
rider.templates = [];
var init = module.exports.init = function(_uiDirectory, _hashes, callback) {
// Cache the ui directory path and make sure we have the absolute path
uiDirectory = _uiDirectory;
hashes = _hashes;
// Load all the globalize cultures
require('globalize/lib/cultures/globalize.cultures');
// Cache all of the widget manifest files
cacheWidgetManifests();
// Monitor the UI repository for changes and refresh the cache.
// This will only be done in development mode
if (process.env['NODE_ENV'] !== 'production') {
watch.createMonitor(uiDirectory, {'ignoreDotFiles': true}, function(monitor) {
monitor.on('created', updateFileCaches);
monitor.on('changed', updateFileCaches);
monitor.on('removed', updateFileCaches);
});
}
// Cache the base skin file
_cacheSkinVariables(function(err) {
if (err) {
return callback(err);
}
// Ensure the skins are not cached, as they may be invalid now
cachedSkins = {};
// Cache the i18n bundles
monitor.on('removed', f => {
coreUtils.locales.instance.reloadLocales()
if (typeof this.lserver != 'undefined') {
tinylr.changed(f)
}
this.events.locales.emit('update')
})
}
)
} catch (e) {
console.log('the directory ' + this.pathLocales + ' does not exist')
}
try {
fse.accessSync(this.pathScripts, fse.F_OK)
this._watchScripts = watch.createMonitor(this.pathScripts, monitor => {
monitor.on('created', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
monitor.on('changed', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
monitor.on('removed', () => {
abeExtend.plugins.instance.updateScripts()
this.events.scripts.emit('update')
})
})
} catch (e) {
console.log('the directory ' + this.pathScripts + ' does not exist')
}
glob('data/service/**/*.json', {}, function (err, files) {
if (err) throw err
if (!files.length) console.warn('none service defination file found')
files.forEach(function (item, index) {
addNewServiceByFilePath(item)
})
watch.createMonitor('data/service', function (monitor) {
monitor.on("created", function (f, stat) {
if (path.extname(f) !== '.json') return null
addNewServiceByFilePath(f)
})
monitor.on("changed", function (f, curr, prev) {
updateServiceByFilePath(f)
})
monitor.on("removed", function (f, stat) {
var appId = path.basename(f, '.json')
Service.remove({appId: appId}, {}, function (err, numRemoved) {
if (err) throw err
})
})
})
})
watch(root) {
watch.createMonitor(root, (monitor) => {
this.unwatch();
this.root = root;
this.monitor = monitor;
this.files = { ...monitor.files };
monitor.on('created', (f, stat) => {
this.files[f] = stat;
});
monitor.on('changed', (f, curr, prev) => {
this.files[f] = curr;
});
monitor.on('removed', (f, stat) => {
delete this.files[f];
});
});
}