<commit_before>var path = require('path');
var chalk = require('chalk');
var files = require('../files');
var logMsg = require('../utils').logMsg;

module.exports = function initFileSync(wsServer, options){
  wsServer.addClientApi(path.join(__dirname, 'client.js'));

  // define commands -> use
  wsServer.on('connection', function(socket){
    socket.on('saveFile', require('./command/saveFile')(options));
    socket.on('createFile', require('./command/createFile')(options));
    socket.on('readFile', require('./command/readFile')(options));

    socket.on('handshake', require('./command/handshake')(options));
    socket.on('openFile', require('./command/openFile')(options));
    socket.on('getAppProfile', require('./command/getAppProfile')(options));
    socket.on('getBundle', require('./command/getBundle')(options));

    // temporary here
    // TODO: move to proper place
    socket.on('basisjs.devpanel.command', function(data){
      socket.broadcast.emit('basisjs.devpanel.command', data);
    });
    socket.on('basisjs.devpanel.data', function(data){
      socket.broadcast.emit('basisjs.devpanel.data', data);
    });
  });

  // clients notification
  files.onRead(function(err, filename, content, digest){
    if (err)
      return;

    var file = files.get(filename);
    var relFilename = files.relativePath(filename);

    if (!wsServer.hasClients() || /^basisjs-tools:/.test(relFilename))
      return;

    if (file.notify && file.content !== null)
    {
      logMsg('bcast', chalk.green('updateFile') + ' ' + relFilename);
      wsServer.emit('updateFile', {
        filename: relFilename,
        digest: digest,<commit_msg>server: fix await file notification<commit_after>var path = require('path');
var chalk = require('chalk');
var files = require('../files');
var logMsg = require('../utils').logMsg;

module.exports = function initFileSync(wsServer, options){
  wsServer.addClientApi(path.join(__dirname, 'client.js'));

  // define commands -> use
  wsServer.on('connection', function(socket){
    socket.on('saveFile', require('./command/saveFile')(options));
    socket.on('createFile', require('./command/createFile')(options));
    socket.on('readFile', require('./command/readFile')(options));

    socket.on('handshake', require('./command/handshake')(options));
    socket.on('openFile', require('./command/openFile')(options));
    socket.on('getAppProfile', require('./command/getAppProfile')(options));
    socket.on('getBundle', require('./command/getBundle')(options));

    // temporary here
    // TODO: move to proper place
    socket.on('basisjs.devpanel.command', function(data){
      socket.broadcast.emit('basisjs.devpanel.command', data);
    });
    socket.on('basisjs.devpanel.data', function(data){
      socket.broadcast.emit('basisjs.devpanel.data', data);
    });
  });

  // clients notification
  files.onRead(function(err, filename, content, digest){
    if (err)
      return;

    var file = files.get(filename);
    var relFilename = files.relativePath(filename);

    if (!wsServer.hasClients() || /^basisjs-tools:/.test(relFilename))
      return;

    if (file.notify)
    {
      logMsg('bcast', chalk.green('updateFile') + ' ' + relFilename);
      wsServer.emit('updateFile', {
        filename: relFilename,
        digest: digest,
{'fraction_non_alphanumeric': 0.18223028105167724, 'fraction_numerical': 0.0, 'mean_word_length': 4.0303951367781155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6597228', 'n_tokens_mistral': 998, 'n_tokens_neox': 963, 'n_words': 167}