@ojes94/socket 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ssc-platform.js +37 -0
- package/bin/ssc.js +65 -0
- package/bin/verify-platform.js +6 -0
- package/index.js +130 -0
- package/package.json +2 -2
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import installation from '../src/index.js'
|
|
4
|
+
import { spawn } from 'node:child_process'
|
|
5
|
+
|
|
6
|
+
let exiting = false
|
|
7
|
+
|
|
8
|
+
const child = spawn(installation.bin.ssc, process.argv.slice(2), {
|
|
9
|
+
env: { ...installation.env, ...process.env },
|
|
10
|
+
stdio: 'inherit',
|
|
11
|
+
windowsHide: true
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
child.once('exit', (code) => {
|
|
15
|
+
if (!exiting) {
|
|
16
|
+
exiting = true
|
|
17
|
+
process.exit(code)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
child.once('error', (err) => {
|
|
22
|
+
console.error(err.message)
|
|
23
|
+
if (!exiting) {
|
|
24
|
+
process.exit(1)
|
|
25
|
+
exiting = true
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
process.on('SIGTERM', () => {
|
|
30
|
+
child.kill('SIGTERM')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
process.on('exit', () => {
|
|
34
|
+
child.kill('SIGTERM')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
export default child
|
package/bin/ssc.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { fork } from 'node:child_process'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
import os from 'node:os'
|
|
6
|
+
|
|
7
|
+
const dirname = path.dirname(import.meta.url).replace(`file://${os.platform() === 'win32' ? '/' : ''}`, '')
|
|
8
|
+
|
|
9
|
+
let exiting = false
|
|
10
|
+
|
|
11
|
+
export async function load () {
|
|
12
|
+
const platform = os.platform()
|
|
13
|
+
const arch = os.arch()
|
|
14
|
+
const info = await import(`@ojes94/socket-${platform}-${arch}`)
|
|
15
|
+
return info?.default ?? info ?? null
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function main () {
|
|
19
|
+
const installation = await load()
|
|
20
|
+
const args = process.argv.slice(2)
|
|
21
|
+
const env = {
|
|
22
|
+
...installation.env,
|
|
23
|
+
SOCKET_HOME_API: path.dirname(dirname),
|
|
24
|
+
...process.env
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (typeof installation.firstTimeExperienceSetup === 'function' && !await installation.firstTimeExperienceSetup()) {
|
|
28
|
+
// FTE not completed satisfactorally, or 'setup' was ran externally
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const child = fork(installation.bin['ssc-platform'], args, {
|
|
33
|
+
env,
|
|
34
|
+
stdio: 'inherit',
|
|
35
|
+
windowsHide: true
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
child.once('exit', (code) => {
|
|
39
|
+
if (!exiting) {
|
|
40
|
+
exiting = true
|
|
41
|
+
process.exit(code)
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
child.once('error', (err) => {
|
|
46
|
+
console.error(err.message)
|
|
47
|
+
if (!exiting) {
|
|
48
|
+
exiting = true
|
|
49
|
+
process.exit(1)
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
process.on('SIGTERM', () => {
|
|
54
|
+
child.kill('SIGTERM')
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
process.on('exit', () => {
|
|
58
|
+
child.kill('SIGTERM')
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
main().catch((err) => {
|
|
63
|
+
console.error(err)
|
|
64
|
+
process.exit(1)
|
|
65
|
+
})
|
package/index.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import path from 'node:path'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { spawn } from 'node:child_process'
|
|
6
|
+
|
|
7
|
+
const dirname = path
|
|
8
|
+
.dirname(fileURLToPath(import.meta.url))
|
|
9
|
+
.replace(`file://${os.platform() === 'win32' ? '/' : ''}`, '')
|
|
10
|
+
|
|
11
|
+
export const SOCKET_HOME = path.dirname(dirname)
|
|
12
|
+
export const PREFIX = SOCKET_HOME
|
|
13
|
+
|
|
14
|
+
export const platform = os.platform()
|
|
15
|
+
export const arch = os.arch()
|
|
16
|
+
|
|
17
|
+
export const env = {
|
|
18
|
+
SOCKET_HOME,
|
|
19
|
+
PREFIX
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const bin = {
|
|
23
|
+
'ssc-platform': path.join(env.PREFIX, 'bin', 'ssc-platform.js'),
|
|
24
|
+
ssc: os.platform() === 'win32'
|
|
25
|
+
? path.join(env.PREFIX, 'bin', 'ssc.exe')
|
|
26
|
+
: path.join(env.PREFIX, 'bin', 'ssc')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Modifying this function requires full FTE testing (From fresh install) on all build OS's before signing off (Individual arch testing not required)
|
|
30
|
+
export const firstTimeExperienceSetup = async () => {
|
|
31
|
+
const installPath = path.dirname(path.dirname(bin.ssc))
|
|
32
|
+
if (fs.existsSync(path.join(installPath, '.ssc.env'))) {
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// ssc env doesn't exist, attempt to run setup for target being built.
|
|
37
|
+
// This should also install vc_redist if it hasn't been installed
|
|
38
|
+
const PLATFORM_PARAMETER = '--platform'
|
|
39
|
+
let isSetupCall = false
|
|
40
|
+
let isBuildCall = false
|
|
41
|
+
let isRunCall = false
|
|
42
|
+
|
|
43
|
+
let platform = ''
|
|
44
|
+
const argv = process.argv.slice(2)
|
|
45
|
+
argv.forEach((arg, index) => {
|
|
46
|
+
if (arg === 'setup') {
|
|
47
|
+
isSetupCall = true
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (arg === 'build') {
|
|
51
|
+
isBuildCall = true
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (arg === 'run') {
|
|
55
|
+
isRunCall = true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (arg.indexOf(PLATFORM_PARAMETER + '=') === 0) {
|
|
59
|
+
platform = arg.slice(PLATFORM_PARAMETER.length + 1)
|
|
60
|
+
} else if (arg.indexOf(PLATFORM_PARAMETER) === 0) {
|
|
61
|
+
platform = argv[index + 1]
|
|
62
|
+
}
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
if (platform === 'android-emulator') {
|
|
66
|
+
platform = 'android'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const startInfo = {
|
|
70
|
+
env: { ...process.env },
|
|
71
|
+
cwd: installPath,
|
|
72
|
+
stdio: [process.stdin, process.stdout, process.stderr]
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const spawnArgs = []
|
|
76
|
+
if (argv.length > 0) {
|
|
77
|
+
if (os.platform() === 'win32') {
|
|
78
|
+
spawnArgs.push(
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
'powershell.exe',
|
|
81
|
+
['.\\bin\\install.ps1', `-fte:${platform.length > 0 ? platform : 'all'}`],
|
|
82
|
+
startInfo
|
|
83
|
+
)
|
|
84
|
+
} else if (isSetupCall || isBuildCall || isRunCall) {
|
|
85
|
+
spawnArgs.push(
|
|
86
|
+
// @ts-ignore
|
|
87
|
+
'./bin/functions.sh',
|
|
88
|
+
['--fte', platform],
|
|
89
|
+
startInfo
|
|
90
|
+
)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (spawnArgs.length === 0) {
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (isSetupCall) {
|
|
99
|
+
startInfo.env.VERBOSE = '1'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (isSetupCall || isBuildCall || isRunCall) {
|
|
103
|
+
console.log('# Checking build dependencies...')
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
const child = spawn(...spawnArgs)
|
|
108
|
+
|
|
109
|
+
await new Promise((resolve, reject) => {
|
|
110
|
+
// @ts-ignore
|
|
111
|
+
child.on('close', resolve).on('error', reject)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
// If fte didn't create a configuration file, make an empty one to prevent
|
|
115
|
+
// user being prompted again
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
if (!child.exitCode && !fs.existsSync(path.join(installPath, '.ssc.env'))) {
|
|
118
|
+
fs.writeFileSync(path.join(installPath, '.ssc.env'), '')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return !isSetupCall
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export default {
|
|
125
|
+
platform,
|
|
126
|
+
arch,
|
|
127
|
+
env,
|
|
128
|
+
bin,
|
|
129
|
+
firstTimeExperienceSetup
|
|
130
|
+
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ojes94/socket",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A Cross-Platform, Native Runtime for Desktop and Mobile Apps — Create apps using HTML, CSS, and JavaScript. Written from the ground up to be small and maintainable.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.js",
|
|
7
7
|
"types": "./index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"ssc": "./bin/ssc.js"
|
|
9
|
+
"ssc": "./npm/bin/ssc.js"
|
|
10
10
|
},
|
|
11
11
|
"os": [
|
|
12
12
|
"linux",
|