nadesiko3 3.3.23 → 3.3.26

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nadesiko3",
3
- "version": "3.3.23",
3
+ "version": "3.3.26",
4
4
  "description": "Japanese Programming Language",
5
5
  "main": "src/index.mjs",
6
6
  "bin": {
package/src/cnako3mod.mts CHANGED
@@ -121,7 +121,7 @@ export class CNako3 extends NakoCompiler {
121
121
  args.mainfile = app.args[0]
122
122
  args.output = app.output
123
123
 
124
- // todo: ESModule 対応の '.mjs' のコードを履く #1217
124
+ // todo: ESModule 対応の '.mjs' のコードを吐くように修正 #1217
125
125
  const ext = '.js'
126
126
  if (/\.(nako|nako3|txt|bak)$/.test(args.mainfile)) {
127
127
  if (!args.output) {
@@ -624,9 +624,14 @@ export class CNako3 extends NakoCompiler {
624
624
  const fileRuntime = fCheckEx(pathRuntimePname, 'runtime')
625
625
  if (fileRuntime) { return fileRuntime }
626
626
 
627
- // ランタイムパス/node_modules/nadesiko3core/src/<plugin>
627
+ // ランタイムと同じ配置 | ランタイムパス/../<plugin>
628
+ const runtimeLib = path.join(pathRuntime, '..', pname)
629
+ const fileLib = fCheckEx(runtimeLib, 'runtimeLib')
630
+ if (fileLib) { return fileLib }
631
+
632
+ // nadesiko3core | ランタイムパス/node_modules/nadesiko3core/src/<plugin>
628
633
  const pathRuntimeSrc2 = path.join(pathRuntime, 'node_modules', 'nadesiko3core', 'src', pname) // cnako3mod.mjs は ランタイム/src に配置されていることが前提
629
- const fileRuntimeSrc2 = fCheckEx(pathRuntimeSrc2, 'runtimeSrcPath2')
634
+ const fileRuntimeSrc2 = fCheckEx(pathRuntimeSrc2, 'nadesiko3core')
630
635
  if (fileRuntimeSrc2) { return fileRuntimeSrc2 }
631
636
 
632
637
  // 環境変数 NAKO_HOMEか?
@@ -21,11 +21,6 @@ const userDir = path.join(homeDir, 'nadesiko3_user')
21
21
  const CNAKO3 = path.resolve(path.join(__dirname, '../../src/cnako3.mjs'))
22
22
  const NODE = process.argv[0]
23
23
 
24
- // ライブラリがあるかチェック
25
- if (!fs.existsSync(path.resolve(rootDir, 'extlib/pure.min.css'))) {
26
- execSync('npm run extlib:install')
27
- }
28
-
29
24
  // サーバ
30
25
  const server = http.createServer(function (req, res) {
31
26
  console.log('[ようこそ]', JSON.stringify(req.url))
@@ -45,7 +40,7 @@ const server = http.createServer(function (req, res) {
45
40
  const q = String(a[1]).split('&')
46
41
  for (const kv of q) {
47
42
  const qq = kv.split('=')
48
- params[qq[0]] = decodeURI(qq[1])
43
+ params[qq[0]] = decodeURIComponent(qq[1])
49
44
  }
50
45
  }
51
46
  // サニタイズ
@@ -67,6 +62,15 @@ const server = http.createServer(function (req, res) {
67
62
  apiRun(res, params)
68
63
  return
69
64
  }
65
+ if (uri === '/get_new_filename') {
66
+ res.writeHead(200, { 'Content-Type': 'text/plaing; charset=utf-8' })
67
+ res.end('"new.nako3"')
68
+ return
69
+ }
70
+ if (uri === '/deletefile') {
71
+ apiDelete(res, params)
72
+ return
73
+ }
70
74
 
71
75
  // ファイルパスを生成
72
76
  let filePath = path.join(rootDir, uri)
@@ -170,6 +174,7 @@ function apiSave (res, params) {
170
174
  res.end('error')
171
175
  }
172
176
  }
177
+
173
178
  function apiRun (res, params) {
174
179
  const fname = params.file
175
180
  const body = params.body
@@ -177,7 +182,13 @@ function apiRun (res, params) {
177
182
  try {
178
183
  fs.writeFileSync(fullpath, body, 'utf-8')
179
184
  const cmd = `"${NODE}" "${CNAKO3}" "${fullpath}"`
180
- const result = execSync(cmd)
185
+ let result = ''
186
+ try {
187
+ result = execSync(cmd)
188
+ result = String(result)
189
+ } catch (err) {
190
+ console.error(err)
191
+ }
181
192
  console.log('[run] file=', fname)
182
193
  console.log('--------------------------------')
183
194
  console.log(result)
@@ -189,3 +200,18 @@ function apiRun (res, params) {
189
200
  res.end('error')
190
201
  }
191
202
  }
203
+
204
+ function apiDelete (res, params) {
205
+ const fname = params.file
206
+ const body = params.body
207
+ const fullpath = path.join(userDir, fname)
208
+ try {
209
+ fs.unlinkSync(fullpath)
210
+ res.writeHead(200, { 'Content-Type': 'text/plaing; charset=utf-8' })
211
+ res.end('"ok"')
212
+ return
213
+ } catch (err) {
214
+ res.writeHead(200, { 'Content-Type': 'text/plaing; charset=utf-8' })
215
+ res.end('error:' + err.message)
216
+ }
217
+ }