@antigenic-oss/paint 0.2.4 → 0.2.6
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/paint.js +98 -4
- package/{next.config.ts → next.config.mjs} +1 -3
- package/package.json +2 -2
package/bin/paint.js
CHANGED
|
@@ -10,6 +10,22 @@ const { spawn, spawnSync } = require('node:child_process')
|
|
|
10
10
|
const ENTRY_REAL_PATH = fs.realpathSync(__filename)
|
|
11
11
|
const APP_ROOT = path.resolve(path.dirname(ENTRY_REAL_PATH), '..')
|
|
12
12
|
const STATE_DIR = path.join(os.homedir(), '.paint')
|
|
13
|
+
const APP_PACKAGE_JSON = path.join(APP_ROOT, 'package.json')
|
|
14
|
+
const APP_VERSION = (() => {
|
|
15
|
+
try {
|
|
16
|
+
const pkg = JSON.parse(fs.readFileSync(APP_PACKAGE_JSON, 'utf8'))
|
|
17
|
+
return typeof pkg.version === 'string' ? pkg.version : 'dev'
|
|
18
|
+
} catch {
|
|
19
|
+
return 'dev'
|
|
20
|
+
}
|
|
21
|
+
})()
|
|
22
|
+
const RUNNING_FROM_NODE_MODULES = APP_ROOT.includes(
|
|
23
|
+
`${path.sep}node_modules${path.sep}`,
|
|
24
|
+
)
|
|
25
|
+
const RUNTIME_SCHEMA_VERSION = 2
|
|
26
|
+
const RUNTIME_ROOT = RUNNING_FROM_NODE_MODULES
|
|
27
|
+
? path.join(STATE_DIR, 'runtime', APP_VERSION)
|
|
28
|
+
: APP_ROOT
|
|
13
29
|
|
|
14
30
|
const APP_STATE_FILE = path.join(STATE_DIR, 'server.json')
|
|
15
31
|
const TERMINAL_STATE_FILE = path.join(STATE_DIR, 'terminal.json')
|
|
@@ -52,6 +68,81 @@ function ensureStateDir() {
|
|
|
52
68
|
fs.mkdirSync(STATE_DIR, { recursive: true })
|
|
53
69
|
}
|
|
54
70
|
|
|
71
|
+
function ensureRuntimeRoot() {
|
|
72
|
+
if (!RUNNING_FROM_NODE_MODULES) return APP_ROOT
|
|
73
|
+
|
|
74
|
+
const stampFile = path.join(RUNTIME_ROOT, '.paint-runtime-stamp.json')
|
|
75
|
+
let needsRefresh = true
|
|
76
|
+
|
|
77
|
+
if (fs.existsSync(stampFile)) {
|
|
78
|
+
try {
|
|
79
|
+
const stamp = JSON.parse(fs.readFileSync(stampFile, 'utf8'))
|
|
80
|
+
const hasConfigMjs = fs.existsSync(path.join(RUNTIME_ROOT, 'next.config.mjs'))
|
|
81
|
+
const hasLegacyConfigTs = fs.existsSync(
|
|
82
|
+
path.join(RUNTIME_ROOT, 'next.config.ts'),
|
|
83
|
+
)
|
|
84
|
+
needsRefresh =
|
|
85
|
+
stamp?.schemaVersion !== RUNTIME_SCHEMA_VERSION ||
|
|
86
|
+
!hasConfigMjs ||
|
|
87
|
+
hasLegacyConfigTs
|
|
88
|
+
} catch {
|
|
89
|
+
needsRefresh = true
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (!needsRefresh) {
|
|
94
|
+
return RUNTIME_ROOT
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
ensureStateDir()
|
|
98
|
+
fs.mkdirSync(path.dirname(RUNTIME_ROOT), { recursive: true })
|
|
99
|
+
|
|
100
|
+
// Build outside node_modules so Next.js webpack always transpiles TS sources.
|
|
101
|
+
fs.rmSync(RUNTIME_ROOT, { recursive: true, force: true })
|
|
102
|
+
fs.mkdirSync(RUNTIME_ROOT, { recursive: true })
|
|
103
|
+
|
|
104
|
+
const runtimeEntries = [
|
|
105
|
+
'bin',
|
|
106
|
+
'public',
|
|
107
|
+
'src',
|
|
108
|
+
'next-env.d.ts',
|
|
109
|
+
'next.config.mjs',
|
|
110
|
+
'postcss.config.mjs',
|
|
111
|
+
'tsconfig.json',
|
|
112
|
+
'package.json',
|
|
113
|
+
'README.md',
|
|
114
|
+
'LICENSE',
|
|
115
|
+
'NOTICE',
|
|
116
|
+
]
|
|
117
|
+
|
|
118
|
+
for (const entry of runtimeEntries) {
|
|
119
|
+
const src = path.join(APP_ROOT, entry)
|
|
120
|
+
const dst = path.join(RUNTIME_ROOT, entry)
|
|
121
|
+
if (!fs.existsSync(src)) continue
|
|
122
|
+
|
|
123
|
+
fs.cpSync(src, dst, { recursive: true, force: true })
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const runtimeNodeModules = path.join(RUNTIME_ROOT, 'node_modules')
|
|
127
|
+
fs.symlinkSync(path.join(APP_ROOT, 'node_modules'), runtimeNodeModules, 'dir')
|
|
128
|
+
|
|
129
|
+
fs.writeFileSync(
|
|
130
|
+
stampFile,
|
|
131
|
+
JSON.stringify(
|
|
132
|
+
{
|
|
133
|
+
schemaVersion: RUNTIME_SCHEMA_VERSION,
|
|
134
|
+
version: APP_VERSION,
|
|
135
|
+
sourceRoot: APP_ROOT,
|
|
136
|
+
preparedAt: now(),
|
|
137
|
+
},
|
|
138
|
+
null,
|
|
139
|
+
2,
|
|
140
|
+
),
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
return RUNTIME_ROOT
|
|
144
|
+
}
|
|
145
|
+
|
|
55
146
|
function now() {
|
|
56
147
|
return new Date().toISOString()
|
|
57
148
|
}
|
|
@@ -181,12 +272,12 @@ function validatePort(port, flagName) {
|
|
|
181
272
|
}
|
|
182
273
|
|
|
183
274
|
function spawnDetached(command, args, opts) {
|
|
184
|
-
const { env, logFile } = opts
|
|
275
|
+
const { env, logFile, cwd = APP_ROOT } = opts
|
|
185
276
|
const fd = fs.openSync(logFile, 'a')
|
|
186
277
|
fs.writeSync(fd, `\n[${now()}] spawn: ${command} ${args.join(' ')}\n`)
|
|
187
278
|
|
|
188
279
|
const child = spawn(command, args, {
|
|
189
|
-
cwd
|
|
280
|
+
cwd,
|
|
190
281
|
env,
|
|
191
282
|
detached: true,
|
|
192
283
|
stdio: ['ignore', fd, fd],
|
|
@@ -262,8 +353,9 @@ function ensureNextInstalled() {
|
|
|
262
353
|
function ensureBuilt(forceRebuild) {
|
|
263
354
|
ensureStateDir()
|
|
264
355
|
ensureNextInstalled()
|
|
356
|
+
const runtimeRoot = ensureRuntimeRoot()
|
|
265
357
|
|
|
266
|
-
const buildIdPath = path.join(
|
|
358
|
+
const buildIdPath = path.join(runtimeRoot, '.next', 'BUILD_ID')
|
|
267
359
|
if (!forceRebuild && fs.existsSync(buildIdPath)) {
|
|
268
360
|
return
|
|
269
361
|
}
|
|
@@ -274,7 +366,7 @@ function ensureBuilt(forceRebuild) {
|
|
|
274
366
|
// Use webpack for packaged/global runtime builds.
|
|
275
367
|
// Turbopack can fail when the app lives under node_modules.
|
|
276
368
|
const result = spawnSync(process.execPath, [NEXT_BIN, 'build', '--webpack'], {
|
|
277
|
-
cwd:
|
|
369
|
+
cwd: runtimeRoot,
|
|
278
370
|
env: process.env,
|
|
279
371
|
stdio: 'inherit',
|
|
280
372
|
})
|
|
@@ -302,6 +394,7 @@ async function startApp(options) {
|
|
|
302
394
|
|
|
303
395
|
ensureBuilt(options.rebuild)
|
|
304
396
|
ensureStateDir()
|
|
397
|
+
const runtimeRoot = ensureRuntimeRoot()
|
|
305
398
|
|
|
306
399
|
const webChild = spawnDetached(
|
|
307
400
|
process.execPath,
|
|
@@ -314,6 +407,7 @@ async function startApp(options) {
|
|
|
314
407
|
options.host,
|
|
315
408
|
],
|
|
316
409
|
{
|
|
410
|
+
cwd: runtimeRoot,
|
|
317
411
|
env: process.env,
|
|
318
412
|
logFile: WEB_LOG_FILE,
|
|
319
413
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antigenic-oss/paint",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "Visual editor for localhost web projects with a global paint CLI",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/Antigenic-OSS/pAInt",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"public",
|
|
27
27
|
"src",
|
|
28
28
|
"next-env.d.ts",
|
|
29
|
-
"next.config.
|
|
29
|
+
"next.config.mjs",
|
|
30
30
|
"postcss.config.mjs",
|
|
31
31
|
"tsconfig.json",
|
|
32
32
|
"README.md",
|