<commit_before>var _ = require('underscore');
var qs = require('querystring');
var tm = require('./lib/tm');
var source = require('./lib/source');
var project = require('./lib/project');
var express = require('express');
var argv = require('optimist')
    .config('config')
    .argv;

var app = express();
app.use(express.bodyParser());
app.use(app.router);
app.use('/app', express.static(__dirname + '/app', { maxAge:3600e3 }));
app.use('/ext', express.static(__dirname + '/ext', { maxAge:3600e3 }));

app.param('project', function(req, res, next) {
    if (req.method === 'PUT' && req.body._recache && req.query.id) {
        source.invalidate(source.resolve(req.query.id, req.body.sources[0]), next);
    } else {
        next();
    }
}, function(req, res, next) {
    var id = req.query.id;
    var tmp = id && tm.tmpid(id);
    var data = false;
    if (req.method === 'PUT') {
        var data = req.body;
    } else if (tmp && req.path === '/project') {
        var data = {
            styles: { 'style.mss': 'Map {\n  background-color:#fff;\n}\n\n#water {\n  polygon-fill:#b8dee6;\n}\n\n#road {\n  line-color:#ccc;\n}\n\n#admin {\n  line-color:rgba(0,32,64,0.2);\n}' },
            sources: ['mbstreets']
        };
    }
    project({
        id: id,
        data: data,
        perm: !tmp && !!data,
        bake: data && data._bake
    }, function(err, project) {
        if (err && !tmp) tm.history(id, true);
        if (err) return next(err);
        if (!tmp) tm.history(id);
        req.project = project;
        req.project.data._tmp = tmp;
        return next();
    });<commit_msg>Load default project from tm2-default-style dep.<commit_after>var _ = require('underscore');
var qs = require('querystring');
var tm = require('./lib/tm');
var fs = require('fs');
var path = require('path');
var source = require('./lib/source');
var project = require('./lib/project');
var express = require('express');
var argv = require('optimist')
    .config('config')
    .argv;

// Load defaults for new projects.
var defaults = {};
project({id:path.dirname(require.resolve('tm2-default-style'))}, function(err, proj) {
    if (err) throw err;
    var data = JSON.parse(JSON.stringify(proj.data));
    delete data.id;
    delete data._id;
    defaults.project = data;
});

var app = express();
app.use(express.bodyParser());
app.use(app.router);
app.use('/app', express.static(__dirname + '/app', { maxAge:3600e3 }));
app.use('/ext', express.static(__dirname + '/ext', { maxAge:3600e3 }));

app.param('project', function(req, res, next) {
    if (req.method === 'PUT' && req.body._recache && req.query.id) {
        source.invalidate(source.resolve(req.query.id, req.body.sources[0]), next);
    } else {
        next();
    }
}, function(req, res, next) {
    var id = req.query.id;
    var tmp = id && tm.tmpid(id);
    var data = false;
    if (req.method === 'PUT') {
        var data = req.body;
    } else if (tmp && req.path === '/project') {
        var data = defaults.project;
    }
    project({
        id: id,
        data: data,
        perm: !tmp && !!data,
        bake: data && data._bake
    }, function(err, project) {
        if (err && !tmp) tm.history(id, true);
        if (err) return next(err);
        if (!tmp) tm.history(id);
        req.project = project;
        req.project.data._tmp = tmp;
        return next();
    });
{'fraction_non_alphanumeric': 0.1977989292088043, 'fraction_numerical': 0.009815585960737656, 'mean_word_length': 2.7533482142857144, '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': '6728355', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1129, 'n_words': 260}