<commit_before>'use strict';

var fs = require('fs');
var path = require('path');
var Q = require('q');
var ffs = require('final-fs');

var VFS = (function(){

    var isModule = function(path) {
        return path.substring(0, 'modules'.length) === 'modules';
    };

    var modulePath = function(path) {
        var modulePath = path.substring('modules/'.length);
        return modulePath.substring(0, modulePath.lastIndexOf('.'));
    };

    var moduleExtension = function(path){
        var m = modulePath(path);
        return path.substring(m.length + 'modules/'.length + 1);
    };

    var normalizeLocalProjectPath = function(localProjectPath){
        return localProjectPath[localProjectPath.length - 1] === '/' ? localProjectPath : (localProjectPath + '/');
    };

    var encodeLocalPath = function(path) {
        var segments = path.split('/');
        var result = [];
        segments.forEach(function(segment){
            result.push(encodeURIComponent(segment));
        });
        return result.join('/');
    };

    var encodeRemotePath = function(path) {
        var segments = path.split('/');
        var result = [];
        segments.forEach(function(segment){
            result.push(decodeURIComponent(segment));
        });
        return result.join('/');
    };

    function VFS($28, projectName, projectToken, localProjectPath){
        this.$28 = $28;
        this.projectName = projectName;
        this.projectToken = projectToken;
        this.localProjectPath = localProjectPath ? normalizeLocalProjectPath(localProjectPath) : '';
    }

    VFS.prototype.getLocalQuery = function(path){
        return fs.readFileSync(path, 'utf-8');
    };

    VFS.prototype.getLocalQueries = function(){
        var that = this;
        ffs.mkdirRecursiveSync(this.localProjectPath + 'modules', 511);
        ffs.mkdirRecursiveSync(this.localProjectPath + 'public', 511);
        ffs.mkdirRecursiveSync(this.localProjectPath + 'private', 511);
        return Q.all([
            ffs.readdirRecursive(this.localProjectPath + 'modules', true, 'modules'),
            ffs.readdirRecursive(this.localProjectPath + 'public', true,  'public'),
            ffs.readdirRecursive(this.localProjectPath + 'private', true, 'private')
        ]).then(function(lists){
            var queries = {};
            lists.forEach(function(files){
                files.filter(function(file){
                    return file.substring(file.length - 2) === 'jq' || file.substring(file.length - 2) === 'xq'
                }).forEach(function(file){
                    queries[file] = {
                        lastModified: new Date(fs.statSync(that.localProjectPath + file).mtime).toISOString()
                    };
                });
            });
            return queries;
        });
    };

    VFS.prototype.getRemoteQueries = function(){
        return Q.all([
            //Modules need to be listed/uploaded first,
            //so compilation errors on main queries can make sense.
            this.$28.Modules(this.projectName).listModules({
                includeSystem: false,
                includeNs: false,
                includeSrc: false,
                token: this.projectToken
            }),
            this.$28.Queries(this.projectName).listQueries({
                visibility: '',
                token: this.projectToken
            })
        ]).then(function(lists){
            var queries = {};
            //Modules need to be listed/uploaded first,<commit_msg>:green_heart: fix build<commit_after>'use strict';

var fs = require('fs');
var path = require('path');
var Q = require('q');
var ffs = require('final-fs');

var VFS = (function(){

    var isModule = function(path) {
        return path.substring(0, 'modules'.length) === 'modules';
    };

    var modulePath = function(path) {
        var modulePath = path.substring('modules/'.length);
        return modulePath.substring(0, modulePath.lastIndexOf('.'));
    };

    var moduleExtension = function(path){
        var m = modulePath(path);
        return path.substring(m.length + 'modules/'.length + 1);
    };

    var normalizeLocalProjectPath = function(localProjectPath){
        return localProjectPath[localProjectPath.length - 1] === '/' ? localProjectPath : (localProjectPath + '/');
    };

    var encodeLocalPath = function(path) {
        var segments = path.split('/');
        var result = [];
        segments.forEach(function(segment){
            result.push(encodeURIComponent(segment));
        });
        return result.join('/');
    };

    var encodeRemotePath = function(path) {
        var segments = path.split('/');
        var result = [];
        segments.forEach(function(segment){
            result.push(decodeURIComponent(segment));
        });
        return result.join('/');
    };

    function VFS($28, projectName, projectToken, localProjectPath){
        this.$28 = $28;
        this.projectName = projectName;
        this.projectToken = projectToken;
        this.localProjectPath = localProjectPath ? normalizeLocalProjectPath(localProjectPath) : '';
    }

    VFS.prototype.getLocalQuery = function(path){
        return fs.readFileSync(path, 'utf-8');
    };

    VFS.prototype.getLocalQueries = function(){
        var that = this;
        ffs.mkdirRecursiveSync(this.localProjectPath + 'modules', 511);
        ffs.mkdirRecursiveSync(this.localProjectPath + 'public', 511);
        ffs.mkdirRecursiveSync(this.localProjectPath + 'private', 511);
        return Q.all([
            ffs.readdirRecursive(this.localProjectPath + 'modules', true, 'modules'),
            ffs.readdirRecursive(this.localProjectPath + 'public', true,  'public'),
            ffs.readdirRecursive(this.localProjectPath + 'private', true, 'private')
        ]).then(function(lists){
            var queries = {};
            lists.forEach(function(files){
                files.filter(function(file){
                    return file.substring(file.length - 2) === 'jq' || file.substring(file.length - 2) === 'xq';
                }).forEach(function(file){
                    queries[file] = {
                        lastModified: new Date(fs.statSync(that.localProjectPath + file).mtime).toISOString()
                    };
                });
            });
            return queries;
        });
    };

    VFS.prototype.getRemoteQueries = function(){
        return Q.all([
            //Modules need to be listed/uploaded first,
            //so compilation errors on main queries can make sense.
            this.$28.Modules(this.projectName).listModules({
                includeSystem: false,
                includeNs: false,
                includeSrc: false,
                token: this.projectToken
            }),
            this.$28.Queries(this.projectName).listQueries({
                visibility: '',
                token: this.projectToken
            })
        ]).then(function(lists){
            var queries = {};
            //Modules need to be listed/uploaded first,
{'fraction_non_alphanumeric': 0.13389180746840834, 'fraction_numerical': 0.0073832173789578305, 'mean_word_length': 2.1629995509654245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1614112', 'n_tokens_mistral': 1944, 'n_tokens_neox': 1867, 'n_words': 367}