-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
111 lines (107 loc) · 2.4 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
var EventEmitter = require('events')
var toObject = require('util').toObject
var currentLocale = (function currentLocale() {
// NSLocale.currentLocale() only returns the language that is supported by the host application
var languageCode = String(NSLocale.preferredLanguages()[0]).split('-')[0]
if (!languageCode) {
return undefined
}
var countryCode = String(NSLocale.currentLocale().localeIdentifier()).split(
'_'
)[1]
if (!countryCode) {
return languageCode
}
return languageCode + '-' + countryCode
})()
var processShim = new EventEmitter()
Object.defineProperties(processShim, {
title: {
enumerable: true,
get() {
return String(__command.name())
},
},
version: {
enumerable: true,
get() {
var pluginBundle = __command.pluginBundle()
return pluginBundle ? String(pluginBundle.version()) : '0.0.0'
},
},
versions: {
enumerable: true,
get() {
var v = {
plugin: this.version,
}
if (typeof BCSketchInfo !== 'undefined') {
v.sketch = String(BCSketchInfo.shared().metadata().appVersion)
} else {
v.sketch = String(MSApplicationMetadata.metadata().appVersion)
}
return v
},
},
arch: {
enumerable: true,
value: 'x64',
},
platform: {
enumerable: true,
value: 'darwin',
},
cwd: {
enumerable: true,
value: function () {
var pluginBundle = __command.pluginBundle()
return pluginBundle ? String(pluginBundle.url().path()) : '/tmp'
},
},
env: {
enumerable: true,
get() {
var env = toObject(NSProcessInfo.processInfo().environment())
var pluginBundle = __command.pluginBundle()
env.command = __command
if (pluginBundle) {
env.plugin = pluginBundle
}
if (currentLocale) {
env.LANG = currentLocale
}
return env
},
},
pid: {
enumerable: true,
get() {
return String(__command.identifier)
},
},
execPath: {
enumerable: true,
value: String(NSBundle.mainBundle().executablePath()),
},
type: {
enumerable: true,
value: 'sketch',
},
nextTick: {
enumerable: true,
get() {
return setImmediate
},
},
argv: {
enumerable: true,
get() {
return [
this.execPath,
this.cwd(),
typeof context !== 'undefined' ? context : undefined,
]
},
},
})
module.exports = processShim