<commit_before>'use strict'

module.exports = ->
	# gets argv
	[_, _, index, opts] = process.argv
	opts = JSON.parse opts
	{platform, onlyLocal, allowedRemoteModules} = opts
	allowedRemoteModules ?= []
	process.argv.splice 2, Infinity

	extras = opts.extras or {}

	EMULATORS =
		browser: browserEnv = ->
			###
			Provide necessary standard browser globals
			###
			global.window =
				document: {}
				isFake: true
				addEventListener: ->
				Image: ->
				HTMLCanvasElement: if extras.game then (->) else null
				console:
					log: ->
				navigator: {}
			global.location = pathname: ''
			global.navigator = userAgent: ''
			global.innerWidth = 1024
			global.innerHeight = 600
			global.scrollX = 0
			global.scrollY = 0
			global.screen = {}
			global.document =
				body:
					appendChild: ->
				createElement: ->
					classList:
						add: ->
					appendChild: ->
					insertBefore: ->
					style: {}
					children: [
						{
							childNodes: []
							width:
								baseVal: 0
							height:
								baseVal: 0
						}
					]
					removeChild: ->
					getBoundingClientRect: -> {}
					addEventListener: ->
					setAttribute: ->
					getAttribute: ->
					innerHTML: ''
					cloneNode: ->
						global.document.createElement()
				createElementNS: ->
					width: baseVal: value: null
					height: baseVal: value: null
					style: {}
					classList:
						add: ->
					transform:
						baseVal:
							appendItem: ->
					setAttribute: ->
					appendChild: ->
					setAttributeNS: ->
					createSVGTransform: ->
						setTranslate: ->
						setScale: ->
					childNodes: [
						{
							transform:
								baseVal:
									appendItem: ->
							childNodes: []
							setAttribute: ->
						}
					]
					children: []
				getElementById: ->
				addEventListener: ->
				querySelector: ->
			global.history =
				pushState: ->
			global.requestAnimationFrame = ->
			global.Image = global.document.createElement

		node: ->
			global.option = ->
			global.task = ->
			global.requestAnimationFrame = ->

		qt: ->
			###
			Provide necessary standard qt globals
			###
			SIGNAL =
				connect: ->
				disconnect: ->

			global.Font = {}
			global.Qt =
				include: ->
				createQmlObject: ->
					font: {}
					onClicked: SIGNAL
					onPressed: SIGNAL
					onReleased: SIGNAL
					onEntered: SIGNAL
					onExited: SIGNAL
					onPositionChanged: SIGNAL
					onWheel: SIGNAL
					contentXChanged: SIGNAL
					contentYChanged: SIGNAL
					fontChanged: SIGNAL
					linkActivated: SIGNAL
					drag:
						onActiveChanged: SIGNAL
					Drag: {}
					createObject: -> global.Qt.createQmlObject()
				binding: ->
				rgba: ->
				hsla: ->
				platform: {}
				locale: ->
					name: ''
			global.Screen = {}
			global.__stylesBody =
				children: []
			global.__stylesWindow =
				items: []
				width: 900
				height: 600
				widthChanged: SIGNAL
				heightChanged: SIGNAL
				screen:
					orientationChanged:
						connect: ->
			global.qmlUtils =
				createBinding: ->
			global.__stylesHatchery = {}
			global.__stylesMouseArea =
				onPressed:
					connect: ->
				onPositionChanged:
					connect: ->
				onReleased:
					connect: ->
			global.requestAnimationFrame = ->

		android: ->
			global.requestAnimationFrame = ->
			global.android = {}
			global._neft =
				http:
					request: -> 0
					onResponse: ->
				renderer:
					transferData: ->
					onUpdateView: ->

		ios: ->
			browserEnv()
			global._neft =
				platform: 'ios'

	NODE_MODULES =
		fs: true
		path: true
		vm: true
		http: true
		https: true
		zlib: true
		util: true # TODO
		events: true # TODO
		rethinkdb: true
		'coffee-script': true
		child_process: true
		stream: true
		groundskeeper: true
		'uglify-js': true
		pegjs: true
		url: true
		mmmagic: true
		'node-static': true
		mysql: true
		'js-yaml': true
		mkdirp: true

	fs = require 'fs'
	pathUtils = require 'path'
	yaml = require 'js-yaml'
	require 'coffee-script/register'

	try
		CoffeeCache = require 'coffee-cash'
		CoffeeCache.setCacheDirectory '/tmp/cache/coffee'
		CoffeeCache.register()

	modules = []
	paths = {}

	# Get index to require and their base path
	base = pathUtils.dirname index

	EMULATORS[platform]()

	require.extensions['.pegjs'] = require.extensions['.txt'] = (module, filename) ->
		module.exports = fs.readFileSync filename, 'utf8'
	require.extensions['.yaml'] = (module, filename) ->
		module.exports = yaml.safeLoad fs.readFileSync filename, 'utf8'

	if opts.neftFilePath
		Neft = require opts.neftFilePath<commit_msg>Fake environments global improved; new node modules added<commit_after>'use strict'

module.exports = ->
	# gets argv
	[_, _, index, opts] = process.argv
	opts = JSON.parse opts
	{platform, onlyLocal, allowedRemoteModules} = opts
	allowedRemoteModules ?= []
	process.argv.splice 2, Infinity

	extras = opts.extras or {}

	EMULATORS =
		browser: browserEnv = ->
			###
			Provide necessary standard browser globals
			###
			global.window = global
			global.document = {}
			global.isFake = true
			global.addEventListener = ->
			global.Image = ->
			global.HTMLCanvasElement = if extras.game then (->) else null
			global.console =
				log: ->
			global.navigator = {}
			global.location = pathname: ''
			global.navigator = userAgent: ''
			global.innerWidth = 1024
			global.innerHeight = 600
			global.scrollX = 0
			global.scrollY = 0
			global.screen = {}
			global.document =
				body:
					appendChild: ->
				createElement: ->
					classList:
						add: ->
					appendChild: ->
					insertBefore: ->
					style: {}
					children: [
						{
							childNodes: []
							width:
								baseVal: 0
							height:
								baseVal: 0
						}
					]
					removeChild: ->
					getBoundingClientRect: -> {}
					addEventListener: ->
					setAttribute: ->
					getAttribute: ->
					innerHTML: ''
					cloneNode: ->
						global.document.createElement()
					getContext: ->
				createElementNS: ->
					width: baseVal: value: null
					height: baseVal: value: null
					style: {}
					classList:
						add: ->
					transform:
						baseVal:
							appendItem: ->
					setAttribute: ->
					appendChild: ->
					setAttributeNS: ->
					createSVGTransform: ->
						setTranslate: ->
						setScale: ->
					childNodes: [
						{
							transform:
								baseVal:
									appendItem: ->
							childNodes: []
							setAttribute: ->
						}
					]
					children: []
				getElementById: ->
				addEventListener: ->
				querySelector: ->
				createTextNode: ->
					{}
			global.history =
				pushState: ->
			global.requestAnimationFrame = ->
			global.Image = global.document.createElement

		node: ->
			global.option = ->
			global.task = ->
			global.requestAnimationFrame = ->

		qt: ->
			###
			Provide necessary standard qt globals
			###
			SIGNAL =
				connect: ->
				disconnect: ->

			global.Font = {}
			global.Qt =
				include: ->
				createQmlObject: ->
					font: {}
					onClicked: SIGNAL
					onPressed: SIGNAL
					onReleased: SIGNAL
					onEntered: SIGNAL
					onExited: SIGNAL
					onPositionChanged: SIGNAL
					onWheel: SIGNAL
					contentXChanged: SIGNAL
					contentYChanged: SIGNAL
					fontChanged: SIGNAL
					linkActivated: SIGNAL
					drag:
						onActiveChanged: SIGNAL
					Drag: {}
					createObject: -> global.Qt.createQmlObject()
				binding: ->
				rgba: ->
				hsla: ->
				platform: {}
				locale: ->
					name: ''
			global.Screen = {}
			global.__stylesBody =
				children: []
			global.__stylesWindow =
				items: []
				width: 900
				height: 600
				widthChanged: SIGNAL
				heightChanged: SIGNAL
				screen:
					orientationChanged:
						connect: ->
			global.qmlUtils =
				createBinding: ->
			global.__stylesHatchery = {}
			global.__stylesMouseArea =
				onPressed:
					connect: ->
				onPositionChanged:
					connect: ->
				onReleased:
					connect: ->
			global.requestAnimationFrame = ->

		android: ->
			global.requestAnimationFrame = ->
			global.android = {}
			global.setImmediate = ->
			global._neft =
				http:
					request: -> 0
					onResponse: ->
				renderer:
					transferData: ->
					onUpdateView: ->

		ios: ->
			browserEnv()
			global.MutationObserver = ->
				observe: ->
			global._neft =
				platform: 'ios'

	NODE_MODULES =
		fs: true
		path: true
		vm: true
		http: true
		https: true
		zlib: true
		util: true # TODO
		events: true # TODO
		rethinkdb: true
		'coffee-script': true
		child_process: true
		stream: true
		groundskeeper: true
		'uglify-js': true
		pegjs: true
		url: true
		mmmagic: true
		'node-static': true
		mysql: true
		'js-yaml': true
		mkdirp: true
		'form-data': true
		qs: true

	fs = require 'fs'
	pathUtils = require 'path'
	yaml = require 'js-yaml'
	require 'coffee-script/register'

	try
		CoffeeCache = require 'coffee-cash'
		CoffeeCache.setCacheDirectory '/tmp/cache/coffee'
		CoffeeCache.register()

	modules = []
	paths = {}

	# Get index to require and their base path
	base = pathUtils.dirname index

	EMULATORS[platform]()

	require.extensions['.pegjs'] = require.extensions['.txt'] = (module, filename) ->
		module.exports = fs.readFileSync filename, 'utf8'
	require.extensions['.yaml'] = (module, filename) ->
		module.exports = yaml.safeLoad fs.readFileSync filename, 'utf8'

	if opts.neftFilePath
		Neft = require opts.neftFilePath
{'fraction_non_alphanumeric': 0.11841108345058989, 'fraction_numerical': 0.004545946531009849, 'mean_word_length': 2.302358827734096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 132, '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': '2587882', 'n_tokens_mistral': 4092, 'n_tokens_neox': 2882, 'n_words': 640}