<commit_before>fs = require "fs"
spawn = require("child_process").spawn
exec = require("child_process").exec
rimraf = require "rimraf"
Path = require "path"
semver = require "semver"
knox = require "knox"
crypto = require "crypto"
async = require "async"
settings = require("settings-sharelatex")


SERVICES = [{
	name: "web"
	repo: "https://github.com/sharelatex/web-sharelatex.git"
	version: "master"
}, {
	name: "real-time"
	repo: "https://github.com/sharelatex/real-time-sharelatex.git"
	version: "master"
}, {
	name: "document-updater"
	repo: "https://github.com/sharelatex/document-updater-sharelatex.git"
	version: "master"
}, {
	name: "clsi"
	repo: "https://github.com/sharelatex/clsi-sharelatex.git"
	version: "master"
}, {
	name: "filestore"
	repo: "https://github.com/sharelatex/filestore-sharelatex.git"
	version: "master"
}, {
	name: "track-changes"
	repo: "https://github.com/sharelatex/track-changes-sharelatex.git"
	version: "master"
}, {
	name: "docstore"
	repo: "https://github.com/sharelatex/docstore-sharelatex.git"
	version: "master"
}, {
	name: "chat"
	repo: "https://github.com/sharelatex/chat-sharelatex.git"
	version: "master"
}, {
	name: "tags"
	repo: "https://github.com/sharelatex/tags-sharelatex.git"
	version: "master"
}, {
	name: "spelling"
	repo: "https://github.com/sharelatex/spelling-sharelatex.git"
	version: "master"
}]

module.exports = (grunt) ->
	grunt.loadNpmTasks 'grunt-bunyan'
	grunt.loadNpmTasks 'grunt-execute'
	grunt.loadNpmTasks 'grunt-available-tasks'
	grunt.loadNpmTasks 'grunt-concurrent'
	grunt.loadNpmTasks "grunt-contrib-coffee"
	grunt.loadNpmTasks "grunt-shell"


	execute = {}
	for service in SERVICES
		execute[service.name] =
			src: "#{service.name}/app.js"

	grunt.initConfig
		execute: execute

		concurrent:
			all:
				tasks: ("run:#{service.name}" for service in SERVICES)
				options:
					limit: SERVICES.length
					logConcurrentOutput: true
		coffee:
			migrate: 
				expand: true,
				flatten: false,
				cwd: './',
				src: ['./migrations/*.coffee'],
				dest: './',
				ext: '.js'
				options:
					bare:true

		shell:
			migrate:
				command: "./node_modules/east/bin/east migrate --adapter east-mongo --url #{settings.mongo.url}"

		availabletasks:
			tasks:
				options:
					filter: 'exclude',
					tasks: [
						'concurrent'<commit_msg>Don't blow up on missing settings<commit_after>fs = require "fs"
spawn = require("child_process").spawn
exec = require("child_process").exec
rimraf = require "rimraf"
Path = require "path"
semver = require "semver"
knox = require "knox"
crypto = require "crypto"
async = require "async"
settings = require("settings-sharelatex")


SERVICES = [{
	name: "web"
	repo: "https://github.com/sharelatex/web-sharelatex.git"
	version: "master"
}, {
	name: "real-time"
	repo: "https://github.com/sharelatex/real-time-sharelatex.git"
	version: "master"
}, {
	name: "document-updater"
	repo: "https://github.com/sharelatex/document-updater-sharelatex.git"
	version: "master"
}, {
	name: "clsi"
	repo: "https://github.com/sharelatex/clsi-sharelatex.git"
	version: "master"
}, {
	name: "filestore"
	repo: "https://github.com/sharelatex/filestore-sharelatex.git"
	version: "master"
}, {
	name: "track-changes"
	repo: "https://github.com/sharelatex/track-changes-sharelatex.git"
	version: "master"
}, {
	name: "docstore"
	repo: "https://github.com/sharelatex/docstore-sharelatex.git"
	version: "master"
}, {
	name: "chat"
	repo: "https://github.com/sharelatex/chat-sharelatex.git"
	version: "master"
}, {
	name: "tags"
	repo: "https://github.com/sharelatex/tags-sharelatex.git"
	version: "master"
}, {
	name: "spelling"
	repo: "https://github.com/sharelatex/spelling-sharelatex.git"
	version: "master"
}]

module.exports = (grunt) ->
	grunt.loadNpmTasks 'grunt-bunyan'
	grunt.loadNpmTasks 'grunt-execute'
	grunt.loadNpmTasks 'grunt-available-tasks'
	grunt.loadNpmTasks 'grunt-concurrent'
	grunt.loadNpmTasks "grunt-contrib-coffee"
	grunt.loadNpmTasks "grunt-shell"


	execute = {}
	for service in SERVICES
		execute[service.name] =
			src: "#{service.name}/app.js"

	grunt.initConfig
		execute: execute

		concurrent:
			all:
				tasks: ("run:#{service.name}" for service in SERVICES)
				options:
					limit: SERVICES.length
					logConcurrentOutput: true
		coffee:
			migrate: 
				expand: true,
				flatten: false,
				cwd: './',
				src: ['./migrations/*.coffee'],
				dest: './',
				ext: '.js'
				options:
					bare:true

		shell:
			migrate:
				command: "./node_modules/east/bin/east migrate --adapter east-mongo --url #{settings?.mongo?.url}"

		availabletasks:
			tasks:
				options:
					filter: 'exclude',
					tasks: [
						'concurrent'
{'fraction_non_alphanumeric': 0.1650172117039587, 'fraction_numerical': 0.0, 'mean_word_length': 3.935244161358811, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 20, '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': '3777202', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1734, 'n_words': 316}