nadesiko3 3.2.27
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/LICENSE +21 -0
- package/README.md +107 -0
- package/bin/cnako3 +10 -0
- package/bin/cnako3.bat +11 -0
- package/bin/nako3server.bat +6 -0
- package/demo/ace_editor.html +90 -0
- package/demo/ace_editor_tabs.html +162 -0
- package/demo/basic.html +71 -0
- package/demo/browsers.html +128 -0
- package/demo/css/basic.css +3 -0
- package/demo/css/common.css +157 -0
- package/demo/css/editor.css +8 -0
- package/demo/css/flow.css +3 -0
- package/demo/css/index.css +3 -0
- package/demo/extlib/ace@1.4.12/ace.js +17 -0
- package/demo/extlib/ace@1.4.12/ext-code_lens.min.js +1 -0
- package/demo/extlib/ace@1.4.12/ext-language_tools.min.js +1 -0
- package/demo/extlib/ace@1.4.12/ext-options.min.js +1 -0
- package/demo/extlib/ace@1.4.12/ext-settings_menu.js +8 -0
- package/demo/extlib/ace@1.4.12/keybinding-vscode.js +8 -0
- package/demo/extlib/ace@1.4.12/theme-monokai.js +8 -0
- package/demo/extlib/ace@1.4.12/theme-xcode.js +8 -0
- package/demo/extlib/chart.js@3.2.1/chart.min.js +13 -0
- package/demo/extlib/pure-min.css +11 -0
- package/demo/flow.html +97 -0
- package/demo/graph.html +53 -0
- package/demo/image/nako.png +0 -0
- package/demo/image/nakopad-icon256.png +0 -0
- package/demo/image/turtle.fla +0 -0
- package/demo/image/turtle.png +0 -0
- package/demo/index.html +134 -0
- package/demo/js/common.js +17 -0
- package/demo/js/turtle3d_test.js +44 -0
- package/demo/js/turtle_test.js +44 -0
- package/demo/runscript.html +47 -0
- package/demo/runscript2.html +33 -0
- package/demo/turtle.html +58 -0
- package/demo/turtle2.html +141 -0
- package/demo/turtle3.html +278 -0
- package/demo/turtle3d.html +58 -0
- package/demo/turtle3d2.html +107 -0
- package/demo/version.html +24 -0
- package/doc/SETUP.md +172 -0
- package/doc/about.md +34 -0
- package/doc/browsers.md +60 -0
- package/doc/docgen.md +21 -0
- package/doc/editor.md +44 -0
- package/doc/files.md +37 -0
- package/doc/plugins.md +195 -0
- package/doc/release.md +78 -0
- package/doc/win32.md +57 -0
- package/package.json +196 -0
- package/release/_hash.txt +65 -0
- package/release/_script-tags.txt +13 -0
- package/release/command.json +1 -0
- package/release/command.json.js +1 -0
- package/release/command_cnako3.json +1 -0
- package/release/command_list.json +1 -0
- package/release/editor.js +2 -0
- package/release/editor.js.LICENSE.txt +32 -0
- package/release/josi.json +48 -0
- package/release/nako_gen_async.js +1 -0
- package/release/nako_gen_async.js.LICENSE.txt +595 -0
- package/release/plugin_caniuse.js +1 -0
- package/release/plugin_caniuse.js.LICENSE.txt +411 -0
- package/release/plugin_csv.js +1 -0
- package/release/plugin_csv.js.LICENSE.txt +367 -0
- package/release/plugin_datetime.js +1 -0
- package/release/plugin_datetime.js.LICENSE.txt +471 -0
- package/release/plugin_kansuji.js +1 -0
- package/release/plugin_kansuji.js.LICENSE.txt +491 -0
- package/release/plugin_markup.js +1 -0
- package/release/plugin_markup.js.LICENSE.txt +363 -0
- package/release/plugin_turtle.js +1 -0
- package/release/plugin_turtle.js.LICENSE.txt +435 -0
- package/release/plugin_webworker.js +1 -0
- package/release/plugin_webworker.js.LICENSE.txt +491 -0
- package/release/version.js +2 -0
- package/release/version.js.LICENSE.txt +32 -0
- package/release/wnako3.js +2 -0
- package/release/wnako3.js.LICENSE.txt +1 -0
- package/release/wnako3webworker.js +1 -0
- package/release/wnako3webworker.js.LICENSE.txt +847 -0
- package/release/yoyakugo.json +30 -0
- package/src/browsers.md +60 -0
- package/src/cnako3.js +466 -0
- package/src/commander_ja.js +154 -0
- package/src/enako3.js +69 -0
- package/src/era.json +22 -0
- package/src/index.js +5 -0
- package/src/nako3.js +836 -0
- package/src/nako3_assert.js +37 -0
- package/src/nako3editorfix.sfd +106 -0
- package/src/nako3editorfix.woff +0 -0
- package/src/nako3server.js +51 -0
- package/src/nako_colors.js +86 -0
- package/src/nako_errors.js +176 -0
- package/src/nako_gen.js +1459 -0
- package/src/nako_gen_async.js +1622 -0
- package/src/nako_global.js +113 -0
- package/src/nako_indent.js +480 -0
- package/src/nako_josi_list.js +46 -0
- package/src/nako_lex_rules.js +259 -0
- package/src/nako_lexer.js +576 -0
- package/src/nako_logger.js +138 -0
- package/src/nako_parser3.js +1768 -0
- package/src/nako_parser_base.js +265 -0
- package/src/nako_parser_const.js +37 -0
- package/src/nako_prepare.js +293 -0
- package/src/nako_reserved_words.js +35 -0
- package/src/nako_source_mapping.js +251 -0
- package/src/nako_test.js +37 -0
- package/src/nako_version.js +8 -0
- package/src/plugin_browser.js +191 -0
- package/src/plugin_browser_ajax.js +352 -0
- package/src/plugin_browser_audio.js +109 -0
- package/src/plugin_browser_canvas.js +462 -0
- package/src/plugin_browser_chart.js +296 -0
- package/src/plugin_browser_color.js +49 -0
- package/src/plugin_browser_crypto.js +26 -0
- package/src/plugin_browser_dialog.js +53 -0
- package/src/plugin_browser_dom_basic.js +322 -0
- package/src/plugin_browser_dom_event.js +193 -0
- package/src/plugin_browser_dom_parts.js +163 -0
- package/src/plugin_browser_geolocation.js +51 -0
- package/src/plugin_browser_hotkey.js +25 -0
- package/src/plugin_browser_html.js +59 -0
- package/src/plugin_browser_in_worker.js +44 -0
- package/src/plugin_browser_location.js +21 -0
- package/src/plugin_browser_speech.js +111 -0
- package/src/plugin_browser_storage.js +121 -0
- package/src/plugin_browser_system.js +12 -0
- package/src/plugin_browser_websocket.js +73 -0
- package/src/plugin_caniuse.js +24 -0
- package/src/plugin_csv.js +57 -0
- package/src/plugin_datetime.js +414 -0
- package/src/plugin_express.js +212 -0
- package/src/plugin_kansuji.js +224 -0
- package/src/plugin_keigo.js +55 -0
- package/src/plugin_markup.js +32 -0
- package/src/plugin_math.js +319 -0
- package/src/plugin_node.js +1018 -0
- package/src/plugin_promise.js +94 -0
- package/src/plugin_system.js +2109 -0
- package/src/plugin_test.js +38 -0
- package/src/plugin_turtle.js +646 -0
- package/src/plugin_webworker.js +334 -0
- package/src/plugin_weykturtle3d.js +1216 -0
- package/src/plugin_worker.js +92 -0
- package/src/repl.nako3 +63 -0
- package/src/turtle-elephant.png +0 -0
- package/src/turtle-panda.png +0 -0
- package/src/turtle64.png +0 -0
- package/src/wnako3.js +162 -0
- package/src/wnako3_editor.css +215 -0
- package/src/wnako3_editor.js +1645 -0
- package/src/wnako3_editor_marker_red.png +0 -0
- package/src/wnako3_editor_marker_red.xcf +0 -0
- package/src/wnako3_editor_marker_yellow.png +0 -0
- package/src/wnako3_editor_marker_yellow.xcf +0 -0
- package/src/wnako3webworker.js +70 -0
- package/test/ace_editor/karma.config.js +94 -0
- package/test/ace_editor/test/.babelrc.json +3 -0
- package/test/ace_editor/test/ace_editor_test.js +178 -0
- package/test/ace_editor/test/html/custom_context.html +140 -0
- package/test/async/async_basic_test.js +124 -0
- package/test/browser/karma.config.js +212 -0
- package/test/browser/test/.babelrc.json +3 -0
- package/test/browser/test/compare_util.js +50 -0
- package/test/browser/test/html/canvas_basic.html +1 -0
- package/test/browser/test/html/div_basic.html +2 -0
- package/test/browser/test/html/event_dom_form.html +4 -0
- package/test/browser/test/html/event_dom_scrolldiv.html +5 -0
- package/test/browser/test/image/canvas_test1.png +0 -0
- package/test/browser/test/image/canvas_test2.png +0 -0
- package/test/browser/test/image/canvas_test3.png +0 -0
- package/test/browser/test/image/canvas_test4.png +0 -0
- package/test/browser/test/image/canvas_test7.png +0 -0
- package/test/browser/test/image/canvas_test8.png +0 -0
- package/test/browser/test/image/canvas_test_blank.png +0 -0
- package/test/browser/test/image/elephant_kana.png +0 -0
- package/test/browser/test/image/panda_kana.png +0 -0
- package/test/browser/test/image/turtle_kana.png +0 -0
- package/test/browser/test/import_plugin_checker.js +24 -0
- package/test/browser/test/plugin_browser_test.js +52 -0
- package/test/browser/test/plugin_browser_test_ajax.js +123 -0
- package/test/browser/test/plugin_browser_test_color.js +18 -0
- package/test/browser/test/plugin_browser_test_dialog.js +72 -0
- package/test/browser/test/plugin_browser_test_dom_event.js +598 -0
- package/test/browser/test/plugin_browser_test_dom_parts.js +125 -0
- package/test/browser/test/plugin_browser_test_system.js +9 -0
- package/test/browser/test/plugin_turtle_test.js +817 -0
- package/test/browser/test/plugin_webworker_test.js +87 -0
- package/test/browser/test/require_test.js +71 -0
- package/test/bundled/karma.config.base.js +117 -0
- package/test/bundled/karma.config.js +86 -0
- package/test/bundled/test/.babelrc.json +3 -0
- package/test/bundled/test/bundled_test.js +69 -0
- package/test/bundled/test/html/custom_context.html +65 -0
- package/test/bundled/test/html/custom_debug.html +66 -0
- package/test/bundled/test4b.cmd +52 -0
- package/test/bundled/test_base/.babelrc.json +3 -0
- package/test/bundled/test_base/_checktool_test.js +25 -0
- package/test/bundled/test_base/basic_ajax_test.js +56 -0
- package/test/bundled/test_base/basic_async_test.js +18 -0
- package/test/bundled/test_base/basic_test.js +153 -0
- package/test/bundled/test_base/calc_test.js +132 -0
- package/test/bundled/test_base/css/browsers_box.css +114 -0
- package/test/bundled/test_base/html/custom_context.html +69 -0
- package/test/bundled/test_base/html/custom_debug.html +71 -0
- package/test/bundled/test_base/js/browsers_box.js +72 -0
- package/test/bundled/test_base/plugin_csv_test.js +37 -0
- package/test/bundled/test_base/plugin_datetime_test.js +115 -0
- package/test/bundled/test_base/plugin_kansuji_test.js +49 -0
- package/test/bundled/test_base/plugin_system_test.js +410 -0
- package/test/bundled/test_base/plugin_webworker_test.js +53 -0
- package/test/bundled/test_base/resources/ok.txt +1 -0
- package/test/bundled/test_base/test_utils.js +191 -0
- package/test/common/array_test.js +40 -0
- package/test/common/basic_test.js +317 -0
- package/test/common/calc_test.js +139 -0
- package/test/common/debug_test.js +16 -0
- package/test/common/error_test.js +16 -0
- package/test/common/flow_test.js +360 -0
- package/test/common/func_call.js +136 -0
- package/test/common/func_test.js +149 -0
- package/test/common/indent_test.js +362 -0
- package/test/common/lex_test.js +146 -0
- package/test/common/literal_test.js +72 -0
- package/test/common/nako_logger_test.js +26 -0
- package/test/common/plugin_browser_test.js +24 -0
- package/test/common/plugin_browser_ut_audio_test.js +88 -0
- package/test/common/plugin_browser_ut_color_test.js +21 -0
- package/test/common/plugin_browser_ut_dialog_test.js +100 -0
- package/test/common/plugin_browser_ut_html_test.js +13 -0
- package/test/common/plugin_browser_ut_system_test.js +10 -0
- package/test/common/plugin_csv_test.js +39 -0
- package/test/common/plugin_datetime_test.js +120 -0
- package/test/common/plugin_kansuji_test.js +59 -0
- package/test/common/plugin_promise_test.js +18 -0
- package/test/common/plugin_system_test.js +451 -0
- package/test/common/prepare_test.js +93 -0
- package/test/common/re_test.js +20 -0
- package/test/common/variable_scope_test.js +105 -0
- package/test/jsconfig.json +19 -0
- package/test/karma.config.js +91 -0
- package/test/node/add_test.nako3 +1 -0
- package/test/node/async_test.js +80 -0
- package/test/node/commander_ja_test.js +82 -0
- package/test/node/error_message_test.js +244 -0
- package/test/node/kai_test.nako3 +6 -0
- package/test/node/node_test.js +43 -0
- package/test/node/plugin_broken.js.txt +3 -0
- package/test/node/plugin_browser_ut_ajax_test.js +355 -0
- package/test/node/plugin_browser_ut_location_test.js +32 -0
- package/test/node/plugin_markup_test.js +44 -0
- package/test/node/plugin_math_test.js +42 -0
- package/test/node/plugin_node_test.js +93 -0
- package/test/node/plugin_test.js +16 -0
- package/test/node/relative_import_test_1.nako3 +1 -0
- package/test/node/relative_import_test_2.nako3 +2 -0
- package/test/node/require_nako3_test.js +59 -0
- package/test/node/requiretest.nako3 +4 -0
- package/test/node/requiretest_indirect.nako3 +1 -0
- package/test/node/requiretest_name.nako3 +5 -0
- package/test/node/runtime_error.nako3 +2 -0
- package/test/node/side_effects_test.js +106 -0
- package/test/node/sjis.txt +5 -0
- package/test/node/syntax_error.nako3 +2 -0
- package/test/node/wnako3_editor_test.js +360 -0
- package/tools/README.md +7 -0
- package/tools/nako3edit/html/edit.html +83 -0
- package/tools/nako3edit/html/edit_plugin.js +6 -0
- package/tools/nako3edit/html/files.html +49 -0
- package/tools/nako3edit/html/nako3edit.css +66 -0
- package/tools/nako3edit/index.nako3 +145 -0
- package/tools/nako3edit/run.js +12 -0
- package/tools/nako3server/html/edit.html +104 -0
- package/tools/nako3server/html/edit_plugin.js +6 -0
- package/tools/nako3server/html/files.html +53 -0
- package/tools/nako3server/html/nako3edit.css +66 -0
- package/tools/nako3server/index.nako3 +129 -0
- package/tools/nako3server/run.js +12 -0
|
@@ -0,0 +1,1018 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* file: plugin_node.js
|
|
4
|
+
* node.js のためのプラグイン
|
|
5
|
+
*/
|
|
6
|
+
const fs = require('fs')
|
|
7
|
+
const fse = require('fs-extra')
|
|
8
|
+
const fetch = require('node-fetch')
|
|
9
|
+
const childProcess = require('child_process')
|
|
10
|
+
const execSync = childProcess.execSync
|
|
11
|
+
const exec = childProcess.exec
|
|
12
|
+
const path = require('path')
|
|
13
|
+
|
|
14
|
+
const PluginNode = {
|
|
15
|
+
'初期化': {
|
|
16
|
+
type: 'func',
|
|
17
|
+
josi: [],
|
|
18
|
+
pure: true,
|
|
19
|
+
fn: function (sys) {
|
|
20
|
+
// ランタイム環境無しで実行する場合
|
|
21
|
+
if (typeof path === 'undefined') {
|
|
22
|
+
/** @param {string} name @param {string} id */
|
|
23
|
+
const tryRequire = (name, id) => {
|
|
24
|
+
try {
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
global[name] = require(id)
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.warn(e.message)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
tryRequire('fs', 'fs')
|
|
32
|
+
tryRequire('fse', 'fs-extra')
|
|
33
|
+
tryRequire('fetch', 'node-fetch')
|
|
34
|
+
tryRequire('childProcess', 'child_process')
|
|
35
|
+
tryRequire('path', 'path')
|
|
36
|
+
if (typeof childProcess !== 'undefined') {
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
global.execSync = childProcess.execSync
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
global.exec = childProcess.exec
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
sys.__getBinPath = (tool) => {
|
|
45
|
+
let fpath = tool
|
|
46
|
+
if (process.platform === 'win32') {
|
|
47
|
+
if (!fileExists(tool)) {
|
|
48
|
+
const nodeDir = path.dirname(process.argv[0])
|
|
49
|
+
const root = path.resolve(path.join(nodeDir, '..'))
|
|
50
|
+
fpath = path.join(root, 'bin', tool + '.exe')
|
|
51
|
+
if (fileExists(fpath)) { return `"${fpath}"` }
|
|
52
|
+
return tool
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return fpath
|
|
57
|
+
}
|
|
58
|
+
sys.__getBokanPath = () => {
|
|
59
|
+
let nakofile
|
|
60
|
+
const cmd = path.basename(process.argv[1])
|
|
61
|
+
if (cmd.indexOf('cnako3') < 0) { nakofile = process.argv[1] } else { nakofile = process.argv[2] }
|
|
62
|
+
|
|
63
|
+
return path.dirname(path.resolve(nakofile))
|
|
64
|
+
}
|
|
65
|
+
sys.__v0['コマンドライン'] = process.argv
|
|
66
|
+
sys.__v0['ナデシコランタイムパス'] = process.argv[0]
|
|
67
|
+
sys.__v0['ナデシコランタイム'] = path.basename(process.argv[0])
|
|
68
|
+
sys.__v0['母艦パス'] = sys.__getBokanPath()
|
|
69
|
+
sys.__v0['AJAX:ONERROR'] = null
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
// @ファイル入出力
|
|
73
|
+
'開': { // @ファイルSを開く // @ひらく
|
|
74
|
+
type: 'func',
|
|
75
|
+
josi: [['を', 'から']],
|
|
76
|
+
pure: true,
|
|
77
|
+
fn: function (s) {
|
|
78
|
+
return fs.readFileSync(s, 'utf-8')
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
'読': { // @ファイルSを開く // @よむ
|
|
82
|
+
type: 'func',
|
|
83
|
+
josi: [['を', 'から']],
|
|
84
|
+
pure: false,
|
|
85
|
+
fn: function (s, sys) {
|
|
86
|
+
return sys.__exec('開', [s])
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
'バイナリ読': { // @ファイルSをバイナリ(Buffer)として開く // @ばいなりよむ
|
|
90
|
+
type: 'func',
|
|
91
|
+
josi: [['を', 'から']],
|
|
92
|
+
pure: true,
|
|
93
|
+
fn: function (s, sys) {
|
|
94
|
+
return fs.readFileSync(s)
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
'保存': { // @データSをファイルFヘ書き込む // @ほぞん
|
|
98
|
+
type: 'func',
|
|
99
|
+
josi: [['を'], ['へ', 'に']],
|
|
100
|
+
pure: true,
|
|
101
|
+
fn: function (s, f) {
|
|
102
|
+
// Buffer?
|
|
103
|
+
if (s instanceof String) { fs.writeFileSync(f, s, 'utf-8') } else { fs.writeFileSync(f, s) }
|
|
104
|
+
},
|
|
105
|
+
return_none: true
|
|
106
|
+
},
|
|
107
|
+
'SJISファイル読': { // @SJIS形式のファイルSを読み込む // @SJISふぁいるよむ
|
|
108
|
+
type: 'func',
|
|
109
|
+
josi: [['を', 'から']],
|
|
110
|
+
pure: true,
|
|
111
|
+
fn: function (s, sys) {
|
|
112
|
+
const iconv = require('iconv-lite')
|
|
113
|
+
iconv.skipDecodeWarning = true
|
|
114
|
+
const buf = fs.readFileSync(s)
|
|
115
|
+
const text = iconv.decode(Buffer.from(buf), 'sjis')
|
|
116
|
+
return text
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
'SJISファイル保存': { // @SをSJIS形式でファイルFへ書き込む // @SJISふぁいるほぞん
|
|
120
|
+
type: 'func',
|
|
121
|
+
josi: [['を'], ['へ', 'に']],
|
|
122
|
+
pure: true,
|
|
123
|
+
fn: function (s, f, sys) {
|
|
124
|
+
const iconv = require('iconv-lite')
|
|
125
|
+
iconv.skipDecodeWarning = true
|
|
126
|
+
const buf = iconv.encode(s, 'Shift_JIS')
|
|
127
|
+
fs.writeFileSync(f, buf)
|
|
128
|
+
},
|
|
129
|
+
return_none: true
|
|
130
|
+
},
|
|
131
|
+
'起動待機': { // @シェルコマンドSを起動し実行終了まで待機する // @きどうたいき
|
|
132
|
+
type: 'func',
|
|
133
|
+
josi: [['を']],
|
|
134
|
+
pure: true,
|
|
135
|
+
fn: function (s) {
|
|
136
|
+
const r = execSync(s)
|
|
137
|
+
return r.toString()
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
'起動': { // @シェルコマンドSを起動 // @きどう
|
|
141
|
+
type: 'func',
|
|
142
|
+
josi: [['を']],
|
|
143
|
+
pure: true,
|
|
144
|
+
fn: function (s) {
|
|
145
|
+
exec(s, (err, stdout, stderr) => {
|
|
146
|
+
if (err) { console.error(stderr) } else
|
|
147
|
+
if (stdout) { console.log(stdout) }
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
'起動時': { // @シェルコマンドSを起動 // @きどうしたとき
|
|
152
|
+
type: 'func',
|
|
153
|
+
josi: [['で'], ['を']],
|
|
154
|
+
pure: true,
|
|
155
|
+
fn: function (callback, s, sys) {
|
|
156
|
+
exec(s, (err, stdout, stderr) => {
|
|
157
|
+
if (err) { throw new Error(stderr) } else { callback(stdout) }
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
'ブラウザ起動': { // @ブラウザでURLを起動 // @ぶらうざきどう
|
|
162
|
+
type: 'func',
|
|
163
|
+
josi: [['を']],
|
|
164
|
+
pure: true,
|
|
165
|
+
fn: function (url) {
|
|
166
|
+
const opener = require('opener')
|
|
167
|
+
opener(url)
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
'ファイル列挙': { // @パスSのファイル名(フォルダ名)一覧を取得する。ワイルドカード可能。「*.jpg;*.png」など複数の拡張子を指定可能。 // @ふぁいるれっきょ
|
|
171
|
+
type: 'func',
|
|
172
|
+
josi: [['の', 'を', 'で']],
|
|
173
|
+
pure: true,
|
|
174
|
+
fn: function (s) {
|
|
175
|
+
if (s.indexOf('*') >= 0) { // ワイルドカードがある場合
|
|
176
|
+
const searchPath = path.dirname(s)
|
|
177
|
+
const mask1 = path.basename(s)
|
|
178
|
+
.replace(/\./g, '\\.')
|
|
179
|
+
.replace(/\*/g, '.*')
|
|
180
|
+
const mask2 = (mask1.indexOf(';') < 0)
|
|
181
|
+
? mask1 + '$'
|
|
182
|
+
: '(' + mask1.replace(/;/g, '|') + ')$'
|
|
183
|
+
const maskRE = new RegExp(mask2, 'i')
|
|
184
|
+
const list = fs.readdirSync(searchPath)
|
|
185
|
+
return list.filter((n) => maskRE.test(n))
|
|
186
|
+
} else { return fs.readdirSync(s) }
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
'全ファイル列挙': { // @パスS以下の全ファイル名を取得する。ワイルドカード可能。「*.jpg;*.png」のように複数の拡張子を指定可能。 // @ぜんふぁいるれっきょ
|
|
190
|
+
type: 'func',
|
|
191
|
+
josi: [['の', 'を', 'で']],
|
|
192
|
+
pure: true,
|
|
193
|
+
fn: function (s) {
|
|
194
|
+
/**
|
|
195
|
+
* @type {string[]}
|
|
196
|
+
*/
|
|
197
|
+
const result = []
|
|
198
|
+
// ワイルドカードの有無を確認
|
|
199
|
+
let mask = '.*'
|
|
200
|
+
let basepath = s
|
|
201
|
+
if (s.indexOf('*') >= 0) {
|
|
202
|
+
basepath = path.dirname(s)
|
|
203
|
+
const mask1 = path.basename(s)
|
|
204
|
+
.replace(/\./g, '\\.')
|
|
205
|
+
.replace(/\*/g, '.*')
|
|
206
|
+
mask = (mask1.indexOf(';') < 0)
|
|
207
|
+
? mask1 + '$'
|
|
208
|
+
: '(' + mask1.replace(/;/g, '|') + ')$'
|
|
209
|
+
}
|
|
210
|
+
basepath = path.resolve(basepath)
|
|
211
|
+
const maskRE = new RegExp(mask, 'i')
|
|
212
|
+
// 再帰関数を定義
|
|
213
|
+
const enumR = (base) => {
|
|
214
|
+
const list = fs.readdirSync(base)
|
|
215
|
+
for (const f of list) {
|
|
216
|
+
if (f === '.' || f === '..') { continue }
|
|
217
|
+
const fullpath = path.join(base, f)
|
|
218
|
+
let st = null
|
|
219
|
+
try {
|
|
220
|
+
st = fs.statSync(fullpath)
|
|
221
|
+
} catch (e) {
|
|
222
|
+
st = null
|
|
223
|
+
}
|
|
224
|
+
if (st == null) { continue }
|
|
225
|
+
if (st.isDirectory()) {
|
|
226
|
+
enumR(fullpath)
|
|
227
|
+
continue
|
|
228
|
+
}
|
|
229
|
+
if (maskRE.test(f)) { result.push(fullpath) }
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// 検索実行
|
|
233
|
+
enumR(basepath)
|
|
234
|
+
return result
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
'存在': { // @ファイルPATHが存在するか確認して返す // @そんざい
|
|
238
|
+
type: 'func',
|
|
239
|
+
josi: [['が', 'の']],
|
|
240
|
+
pure: true,
|
|
241
|
+
fn: function (path) {
|
|
242
|
+
return fileExists(path)
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
'フォルダ存在': { // @ディレクトリPATHが存在するか確認して返す // @ふぉるだそんざい
|
|
246
|
+
type: 'func',
|
|
247
|
+
josi: [['が', 'の']],
|
|
248
|
+
pure: true,
|
|
249
|
+
fn: function (path) {
|
|
250
|
+
return isDir(path)
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
'フォルダ作成': { // @ディレクトリPATHを作成して返す(再帰的に作成) // @ふぉるださくせい
|
|
254
|
+
type: 'func',
|
|
255
|
+
josi: [['の', 'を', 'に', 'へ']],
|
|
256
|
+
pure: true,
|
|
257
|
+
fn: function (path) {
|
|
258
|
+
return fse.mkdirpSync(path)
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
'ファイルコピー': { // @パスAをパスBへファイルコピーする // @ふぁいるこぴー
|
|
262
|
+
type: 'func',
|
|
263
|
+
josi: [['から', 'を'], ['に', 'へ']],
|
|
264
|
+
pure: true,
|
|
265
|
+
fn: function (a, b, sys) {
|
|
266
|
+
return fse.copySync(a, b)
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
'ファイルコピー時': { // @パスAをパスBへファイルコピーしてcallbackを実行 // @ふぁいるこぴーしたとき
|
|
270
|
+
type: 'func',
|
|
271
|
+
josi: [['で'], ['から', 'を'], ['に', 'へ']],
|
|
272
|
+
pure: true,
|
|
273
|
+
fn: function (callback, a, b, sys) {
|
|
274
|
+
return fse.copy(a, b, err => {
|
|
275
|
+
if (err) { throw new Error('ファイルコピー時:' + err) }
|
|
276
|
+
callback()
|
|
277
|
+
})
|
|
278
|
+
},
|
|
279
|
+
return_none: false
|
|
280
|
+
},
|
|
281
|
+
'ファイル移動': { // @パスAをパスBへ移動する // @ふぁいるいどう
|
|
282
|
+
type: 'func',
|
|
283
|
+
josi: [['から', 'を'], ['に', 'へ']],
|
|
284
|
+
pure: true,
|
|
285
|
+
fn: function (a, b, sys) {
|
|
286
|
+
return fse.moveSync(a, b)
|
|
287
|
+
}
|
|
288
|
+
},
|
|
289
|
+
'ファイル移動時': { // @パスAをパスBへ移動してcallbackを実行 // @ふぁいるいどうしたとき
|
|
290
|
+
type: 'func',
|
|
291
|
+
josi: [['で'], ['から', 'を'], ['に', 'へ']],
|
|
292
|
+
pure: true,
|
|
293
|
+
fn: function (callback, a, b, sys) {
|
|
294
|
+
fse.move(a, b, err => {
|
|
295
|
+
if (err) { throw new Error('ファイル移動時:' + err) }
|
|
296
|
+
callback()
|
|
297
|
+
})
|
|
298
|
+
},
|
|
299
|
+
return_none: false
|
|
300
|
+
},
|
|
301
|
+
'ファイル削除': { // @パスPATHを削除する // @ふぁいるさくじょ
|
|
302
|
+
type: 'func',
|
|
303
|
+
josi: [['の', 'を']],
|
|
304
|
+
pure: true,
|
|
305
|
+
fn: function (path, sys) {
|
|
306
|
+
return fse.removeSync(path)
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
'ファイル削除時': { // @パスPATHを削除してcallbackを実行 // @ふぁいるさくじょしたとき
|
|
310
|
+
type: 'func',
|
|
311
|
+
josi: [['で'], ['の', 'を']],
|
|
312
|
+
pure: true,
|
|
313
|
+
fn: function (callback, path, sys) {
|
|
314
|
+
return fse.remove(path, err => {
|
|
315
|
+
if (err) { throw new Error('ファイル削除時:' + err) }
|
|
316
|
+
callback()
|
|
317
|
+
})
|
|
318
|
+
},
|
|
319
|
+
return_none: false
|
|
320
|
+
},
|
|
321
|
+
'ファイル情報取得': { // @パスPATHの情報を調べてオブジェクトで返す // @ふぁいるじょうほうしゅとく
|
|
322
|
+
type: 'func',
|
|
323
|
+
josi: [['の', 'から']],
|
|
324
|
+
pure: true,
|
|
325
|
+
fn: function (path, sys) {
|
|
326
|
+
return fs.statSync(path)
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
'ファイルサイズ取得': { // @パスPATHのファイルサイズを調べて返す // @ふぁいるさいずしゅとく
|
|
330
|
+
type: 'func',
|
|
331
|
+
josi: [['の', 'から']],
|
|
332
|
+
pure: true,
|
|
333
|
+
fn: function (path, sys) {
|
|
334
|
+
const st = fs.statSync(path)
|
|
335
|
+
if (!st) { return -1 }
|
|
336
|
+
return st.size
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
// @パス操作
|
|
340
|
+
'ファイル名抽出': { // @フルパスのファイル名Sからファイル名部分を抽出して返す // @ふぁいるめいちゅうしゅつ
|
|
341
|
+
type: 'func',
|
|
342
|
+
josi: [['から', 'の']],
|
|
343
|
+
pure: true,
|
|
344
|
+
fn: function (s) {
|
|
345
|
+
return path.basename(s)
|
|
346
|
+
}
|
|
347
|
+
},
|
|
348
|
+
'パス抽出': { // @ファイル名Sからパス部分を抽出して返す // @ぱすちゅうしゅつ
|
|
349
|
+
type: 'func',
|
|
350
|
+
josi: [['から', 'の']],
|
|
351
|
+
pure: true,
|
|
352
|
+
fn: function (s) {
|
|
353
|
+
return path.dirname(s)
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
'絶対パス変換': { // @相対パスから絶対パスに変換して返す // @ぜったいぱすへんかん
|
|
357
|
+
type: 'func',
|
|
358
|
+
josi: [['を', 'の']],
|
|
359
|
+
pure: true,
|
|
360
|
+
fn: function (a) {
|
|
361
|
+
return path.resolve(a)
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
'相対パス展開': { // @ファイル名AからパスBを展開して返す // @そうたいぱすてんかい
|
|
365
|
+
type: 'func',
|
|
366
|
+
josi: [['を'], ['で']],
|
|
367
|
+
pure: true,
|
|
368
|
+
fn: function (a, b) {
|
|
369
|
+
return path.resolve(path.join(a, b))
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
// @フォルダ取得
|
|
373
|
+
'カレントディレクトリ取得': { // @カレントディレクトリを返す // @かれんとでぃれくとりしゅとく
|
|
374
|
+
type: 'func',
|
|
375
|
+
josi: [],
|
|
376
|
+
pure: true,
|
|
377
|
+
fn: function () {
|
|
378
|
+
const cwd = process.cwd()
|
|
379
|
+
return path.resolve(cwd)
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
'カレントディレクトリ変更': { // @カレントディレクトリをDIRに変更する // @かれんとでぃれくとりへんこう
|
|
383
|
+
type: 'func',
|
|
384
|
+
josi: [['に', 'へ']],
|
|
385
|
+
pure: true,
|
|
386
|
+
fn: function (dir) {
|
|
387
|
+
process.chdir(dir)
|
|
388
|
+
},
|
|
389
|
+
return_none: true
|
|
390
|
+
},
|
|
391
|
+
'作業フォルダ取得': { // @カレントディレクトリを返す // @さぎょうふぉるだしゅとく
|
|
392
|
+
type: 'func',
|
|
393
|
+
josi: [],
|
|
394
|
+
pure: true,
|
|
395
|
+
fn: function () {
|
|
396
|
+
const cwd = process.cwd()
|
|
397
|
+
return path.resolve(cwd)
|
|
398
|
+
}
|
|
399
|
+
},
|
|
400
|
+
'作業フォルダ変更': { // @カレントディレクトリをDIRに変更する // @さぎょうふぉるだへんこう
|
|
401
|
+
type: 'func',
|
|
402
|
+
josi: [['に', 'へ']],
|
|
403
|
+
pure: true,
|
|
404
|
+
fn: function (dir) {
|
|
405
|
+
process.chdir(dir)
|
|
406
|
+
},
|
|
407
|
+
return_none: true
|
|
408
|
+
},
|
|
409
|
+
'ホームディレクトリ取得': { // @ホームディレクトリを取得して返す // @ほーむでぃれくとりしゅとく
|
|
410
|
+
type: 'func',
|
|
411
|
+
josi: [],
|
|
412
|
+
pure: true,
|
|
413
|
+
fn: function () {
|
|
414
|
+
return process.env[process.platform === 'win32' ? 'USERPROFILE' : 'HOME']
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
'デスクトップ': { // @デスクトップパスを取得して返す // @ですくとっぷ
|
|
418
|
+
type: 'func',
|
|
419
|
+
josi: [],
|
|
420
|
+
pure: false,
|
|
421
|
+
fn: function (sys) {
|
|
422
|
+
const home = sys.__exec('ホームディレクトリ取得', [sys])
|
|
423
|
+
return path.join(home, 'Desktop')
|
|
424
|
+
}
|
|
425
|
+
},
|
|
426
|
+
'マイドキュメント': { // @マイドキュメントのパスを取得して返す // @まいどきゅめんと
|
|
427
|
+
type: 'func',
|
|
428
|
+
josi: [],
|
|
429
|
+
pure: false,
|
|
430
|
+
fn: function (sys) {
|
|
431
|
+
const home = sys.__exec('ホームディレクトリ取得', [sys])
|
|
432
|
+
return path.join(home, 'Documents')
|
|
433
|
+
}
|
|
434
|
+
},
|
|
435
|
+
'母艦パス': { type: 'const', value: '' }, // @ぼかんぱす
|
|
436
|
+
'母艦パス取得': { // @スクリプトのあるディレクトリを返す // @ぼかんぱすしゅとく
|
|
437
|
+
type: 'func',
|
|
438
|
+
josi: [],
|
|
439
|
+
pure: true,
|
|
440
|
+
fn: function (sys) {
|
|
441
|
+
return sys.__getBokanPath()
|
|
442
|
+
}
|
|
443
|
+
},
|
|
444
|
+
// @環境変数
|
|
445
|
+
'環境変数取得': { // @環境変数Sを返す // @かんきょうへんすうしゅとく
|
|
446
|
+
type: 'func',
|
|
447
|
+
josi: [['の']],
|
|
448
|
+
pure: true,
|
|
449
|
+
fn: function (s) {
|
|
450
|
+
return process.env[s]
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
'環境変数一覧取得': { // @環境変数の一覧を返す // @かんきょうへんすういちらんしゅとく
|
|
454
|
+
type: 'func',
|
|
455
|
+
josi: [],
|
|
456
|
+
pure: true,
|
|
457
|
+
fn: function () {
|
|
458
|
+
return process.env
|
|
459
|
+
}
|
|
460
|
+
},
|
|
461
|
+
// @圧縮・解凍
|
|
462
|
+
'圧縮解凍ツールパス': { type: 'const', value: '7z' }, // @あっしゅくかいとうつーるぱす
|
|
463
|
+
'圧縮解凍ツールパス変更': { // @圧縮解凍に使うツールを取得変更する // @あっしゅくかいとうつーるぱすへんこう
|
|
464
|
+
type: 'func',
|
|
465
|
+
josi: [['に', 'へ']],
|
|
466
|
+
pure: true,
|
|
467
|
+
fn: function (v, sys) {
|
|
468
|
+
sys.__v0['圧縮解凍ツールパス'] = v
|
|
469
|
+
},
|
|
470
|
+
return_none: true
|
|
471
|
+
},
|
|
472
|
+
'解凍': { // @(v1非互換)ZIPファイルAをBに解凍(実行には7-zipが必要-https://goo.gl/LmKswH) // @かいとう
|
|
473
|
+
type: 'func',
|
|
474
|
+
josi: [['を', 'から'], ['に', 'へ']],
|
|
475
|
+
pure: true,
|
|
476
|
+
fn: function (a, b, sys) {
|
|
477
|
+
const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス'])
|
|
478
|
+
const cmd = `${tpath} x "${a}" -o"${b}" -y`
|
|
479
|
+
execSync(cmd)
|
|
480
|
+
return true
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
'解凍時': { // @解凍処理を行い、処理が完了したときにcallback処理を実行 // @かいとうしたとき
|
|
484
|
+
type: 'func',
|
|
485
|
+
josi: [['で'], ['を', 'から'], ['に', 'へ']],
|
|
486
|
+
pure: true,
|
|
487
|
+
fn: function (callback, a, b, sys) {
|
|
488
|
+
const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス'])
|
|
489
|
+
const cmd = `${tpath} x "${a}" -o"${b}" -y`
|
|
490
|
+
exec(cmd, (err, stdout, stderr) => {
|
|
491
|
+
if (err) { throw new Error('[エラー]『解凍時』' + err) }
|
|
492
|
+
callback(stdout)
|
|
493
|
+
})
|
|
494
|
+
},
|
|
495
|
+
return_none: false
|
|
496
|
+
},
|
|
497
|
+
'圧縮': { // @(v1非互換)ファイルAをBにZIP圧縮(実行には7-zipが必要-https://goo.gl/LmKswH) // @あっしゅく
|
|
498
|
+
type: 'func',
|
|
499
|
+
josi: [['を', 'から'], ['に', 'へ']],
|
|
500
|
+
pure: true,
|
|
501
|
+
fn: function (a, b, sys) {
|
|
502
|
+
const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス'])
|
|
503
|
+
const cmd = `${tpath} a -r "${b}" "${a}" -y`
|
|
504
|
+
execSync(cmd)
|
|
505
|
+
return true
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
'圧縮時': { // @圧縮処理を行い完了したときにcallback処理を指定 // @あっしゅくしたとき
|
|
509
|
+
type: 'func',
|
|
510
|
+
josi: [['で'], ['を', 'から'], ['に', 'へ']],
|
|
511
|
+
pure: true,
|
|
512
|
+
fn: function (callback, a, b, sys) {
|
|
513
|
+
const tpath = sys.__getBinPath(sys.__v0['圧縮解凍ツールパス'])
|
|
514
|
+
const cmd = `${tpath} a -r "${b}" "${a}" -y`
|
|
515
|
+
exec(cmd, (err, stdout, stderr) => {
|
|
516
|
+
if (err) { throw new Error('[エラー]『圧縮時』' + err) }
|
|
517
|
+
callback(stdout)
|
|
518
|
+
})
|
|
519
|
+
},
|
|
520
|
+
return_none: true
|
|
521
|
+
},
|
|
522
|
+
// @Nodeプロセス
|
|
523
|
+
'終': { // @Nodeでプログラム実行を強制終了する // @おわる
|
|
524
|
+
type: 'func',
|
|
525
|
+
josi: [],
|
|
526
|
+
pure: true,
|
|
527
|
+
fn: function () {
|
|
528
|
+
process.exit()
|
|
529
|
+
},
|
|
530
|
+
return_none: true
|
|
531
|
+
},
|
|
532
|
+
'強制終了時': { // @Nodeでctrl+cでプログラムの実行が終了した時FUNCを実行する。もしFUNCが偽を返すと終了しない。非同期処理のとき動作する(#1010) // @きょうせいしゅうりょうしたとき
|
|
533
|
+
type: 'func',
|
|
534
|
+
josi: [['を']],
|
|
535
|
+
pure: true,
|
|
536
|
+
fn: function (func, sys) {
|
|
537
|
+
if (typeof (func) === 'string') {
|
|
538
|
+
func = sys.__findFunc(func, '強制終了時')
|
|
539
|
+
}
|
|
540
|
+
process.on('SIGINT', (signal) => {
|
|
541
|
+
const flag = func(sys)
|
|
542
|
+
if (flag) { process.exit() }
|
|
543
|
+
})
|
|
544
|
+
},
|
|
545
|
+
return_none: true
|
|
546
|
+
},
|
|
547
|
+
'終了': { // @Nodeでプログラム実行を強制終了する // @しゅうりょう
|
|
548
|
+
type: 'func',
|
|
549
|
+
josi: [],
|
|
550
|
+
pure: false,
|
|
551
|
+
fn: function (sys) {
|
|
552
|
+
sys.__exec('終', [])
|
|
553
|
+
},
|
|
554
|
+
return_none: true
|
|
555
|
+
},
|
|
556
|
+
'秒待': { // @NodeでN秒待つ // @びょうまつ
|
|
557
|
+
type: 'func',
|
|
558
|
+
josi: [['']],
|
|
559
|
+
pure: true,
|
|
560
|
+
fn: function (sec, sys) {
|
|
561
|
+
const msleep = (n) => {
|
|
562
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, n) // eslint-disable-line no-undef
|
|
563
|
+
}
|
|
564
|
+
msleep(sec * 1000)
|
|
565
|
+
},
|
|
566
|
+
return_none: true
|
|
567
|
+
},
|
|
568
|
+
'OS取得': { // @OSプラットフォームを返す(darwin/win32/linux) // @OSしゅとく
|
|
569
|
+
type: 'func',
|
|
570
|
+
josi: [],
|
|
571
|
+
pure: true,
|
|
572
|
+
fn: function (sys) {
|
|
573
|
+
return process.platform
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
'OSアーキテクチャ取得': { // @OSアーキテクチャを返す // @OSあーきてくちゃしゅとく
|
|
577
|
+
type: 'func',
|
|
578
|
+
josi: [],
|
|
579
|
+
pure: true,
|
|
580
|
+
fn: function (sys) {
|
|
581
|
+
return process.arch
|
|
582
|
+
}
|
|
583
|
+
},
|
|
584
|
+
// @クリップボード操作
|
|
585
|
+
'クリップボード': { // @クリップボードを取得設定(『クリップボード←値』で書換が可能) // @くりっぷぼーど
|
|
586
|
+
type: 'func',
|
|
587
|
+
josi: [['を']],
|
|
588
|
+
pure: true,
|
|
589
|
+
fn: function (v, sys) {
|
|
590
|
+
const clipboardy = require('clipboardy')
|
|
591
|
+
// copy
|
|
592
|
+
if (sys && sys.isSetter) { return clipboardy.writeSync(v) }
|
|
593
|
+
// paste
|
|
594
|
+
return clipboardy.readSync()
|
|
595
|
+
}
|
|
596
|
+
},
|
|
597
|
+
// @コマンドラインと標準入出力
|
|
598
|
+
'コマンドライン': { type: 'const', value: '' }, // @こまんどらいん
|
|
599
|
+
'ナデシコランタイム': { type: 'const', value: '' }, // @なでしこらんたいむ
|
|
600
|
+
'ナデシコランタイムパス': { type: 'const', value: '' }, // @なでしこらんたいむぱす
|
|
601
|
+
'標準入力取得時': { // @標準入力を一行取得した時に、無名関数(あるいは、文字列で関数名を指定)F(s)を実行する // @ひょうじゅんにゅうりょくしゅとくしたとき
|
|
602
|
+
type: 'func',
|
|
603
|
+
josi: [['を']],
|
|
604
|
+
pure: true,
|
|
605
|
+
fn: function (callback) {
|
|
606
|
+
const reader = require('readline').createInterface({
|
|
607
|
+
input: process.stdin,
|
|
608
|
+
output: process.stdout
|
|
609
|
+
})
|
|
610
|
+
reader.on('line', function (line) {
|
|
611
|
+
callback(line)
|
|
612
|
+
})
|
|
613
|
+
}
|
|
614
|
+
},
|
|
615
|
+
'尋': { // @標準入力を一行取得する // @たずねる
|
|
616
|
+
type: 'func',
|
|
617
|
+
josi: [['と', 'を']],
|
|
618
|
+
pure: true,
|
|
619
|
+
fn: function (msg, sys) {
|
|
620
|
+
const readlineSync = require('readline-sync')
|
|
621
|
+
const res = readlineSync.question(msg)
|
|
622
|
+
if (res.match(/^[0-9.]+$/)) { return parseFloat(res) }
|
|
623
|
+
return res
|
|
624
|
+
}
|
|
625
|
+
},
|
|
626
|
+
// @テスト
|
|
627
|
+
'ASSERT等': { // @ mochaによるテストで、ASSERTでAとBが正しいことを報告する // @ASSERTひとしい
|
|
628
|
+
type: 'func',
|
|
629
|
+
josi: [['と'], ['が']],
|
|
630
|
+
pure: true,
|
|
631
|
+
fn: function (a, b, sys) {
|
|
632
|
+
const assert = require('assert')
|
|
633
|
+
assert.strictEqual(a, b)
|
|
634
|
+
}
|
|
635
|
+
},
|
|
636
|
+
// @ネットワーク
|
|
637
|
+
'自分IPアドレス取得': { // @ネットワークアダプターからIPアドレス(IPv4)を取得して配列で返す // @じぶんIPあどれすしゅとく
|
|
638
|
+
type: 'func',
|
|
639
|
+
josi: [],
|
|
640
|
+
pure: true,
|
|
641
|
+
fn: function (sys) {
|
|
642
|
+
const os = require('os')
|
|
643
|
+
const nif = os.networkInterfaces()
|
|
644
|
+
/**
|
|
645
|
+
* @type {string[]}
|
|
646
|
+
*/
|
|
647
|
+
const result = []
|
|
648
|
+
for (const dev in nif) {
|
|
649
|
+
nif[dev].forEach((detail) => {
|
|
650
|
+
if (detail.family === 'IPv4') { result.push(detail.address) }
|
|
651
|
+
})
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
return result
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
'自分IPV6アドレス取得': { // @ネットワークアダプターからIPアドレス(IPv6)を取得して配列で返す // @じぶんIPV6あどれすしゅとく
|
|
658
|
+
type: 'func',
|
|
659
|
+
josi: [],
|
|
660
|
+
pure: true,
|
|
661
|
+
fn: function (sys) {
|
|
662
|
+
const os = require('os')
|
|
663
|
+
const nif = os.networkInterfaces()
|
|
664
|
+
const result = []
|
|
665
|
+
for (const dev in nif) {
|
|
666
|
+
nif[dev].forEach((detail) => {
|
|
667
|
+
if (detail.family === 'IPv6') { result.push(detail.address) }
|
|
668
|
+
})
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return result
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
// @Ajax
|
|
675
|
+
'AJAX送信時': { // @非同期通信(Ajax)でURLにデータを送信し、成功するとcallbackが実行される。その際『対象』にデータが代入される。 // @AJAXそうしんしたとき
|
|
676
|
+
type: 'func',
|
|
677
|
+
josi: [['の'], ['まで', 'へ', 'に']],
|
|
678
|
+
pure: true,
|
|
679
|
+
fn: function (callback, url, sys) {
|
|
680
|
+
let options = sys.__v0['AJAXオプション']
|
|
681
|
+
if (options === '') { options = { method: 'GET' } }
|
|
682
|
+
fetch(url, options).then(res => {
|
|
683
|
+
return res.text()
|
|
684
|
+
}).then(text => {
|
|
685
|
+
sys.__v0['対象'] = text
|
|
686
|
+
callback(text)
|
|
687
|
+
}).catch(err => {
|
|
688
|
+
console.log('[fetch.error]', err)
|
|
689
|
+
throw err;
|
|
690
|
+
})
|
|
691
|
+
},
|
|
692
|
+
return_none: true
|
|
693
|
+
},
|
|
694
|
+
'AJAX受信時': { // @非同期通信(Ajax)でURLにデータを送信し、成功するとcallbackが実行される。その際『対象』にデータが代入される。 // @AJAXそうしんしたとき
|
|
695
|
+
type: 'func',
|
|
696
|
+
josi: [['で'], ['から', 'を']],
|
|
697
|
+
pure: true,
|
|
698
|
+
fn: function (callback, url, sys) {
|
|
699
|
+
sys.__exec('AJAX送信時', [callback, url, sys])
|
|
700
|
+
},
|
|
701
|
+
return_none: true
|
|
702
|
+
},
|
|
703
|
+
'GET送信時': { // @非同期通信(Ajax)でURLにデータを送信し、成功するとcallbackが実行される。その際『対象』にデータが代入される。 // @GETそうしんしたとき
|
|
704
|
+
type: 'func',
|
|
705
|
+
josi: [['の'], ['まで', 'へ', 'に']],
|
|
706
|
+
pure: false,
|
|
707
|
+
fn: function (callback, url, sys) {
|
|
708
|
+
sys.__exec('AJAX送信時', [callback, url, sys])
|
|
709
|
+
},
|
|
710
|
+
return_none: true
|
|
711
|
+
},
|
|
712
|
+
'POST送信時': { // @AjaxでURLにPARAMSをPOST送信し『対象』にデータを設定 // @POSTそうしんしたとき
|
|
713
|
+
type: 'func',
|
|
714
|
+
josi: [['の'], ['まで', 'へ', 'に'], ['を']],
|
|
715
|
+
pure: true,
|
|
716
|
+
fn: function (callback, url, params, sys) {
|
|
717
|
+
const flist = []
|
|
718
|
+
for (const key in params) {
|
|
719
|
+
const v = params[key]
|
|
720
|
+
const kv = encodeURIComponent(key) + '=' + encodeURIComponent(v)
|
|
721
|
+
flist.push(kv)
|
|
722
|
+
}
|
|
723
|
+
const bodyData = flist.join('&')
|
|
724
|
+
const options = {
|
|
725
|
+
method: 'POST',
|
|
726
|
+
headers: {
|
|
727
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
728
|
+
},
|
|
729
|
+
body: bodyData
|
|
730
|
+
}
|
|
731
|
+
fetch(url, options).then(res => {
|
|
732
|
+
return res.text()
|
|
733
|
+
}).then(text => {
|
|
734
|
+
sys.__v0['対象'] = text
|
|
735
|
+
callback(text)
|
|
736
|
+
}).catch(err => {
|
|
737
|
+
sys.__v0['AJAX:ONERROR'](err)
|
|
738
|
+
})
|
|
739
|
+
}
|
|
740
|
+
},
|
|
741
|
+
'POSTフォーム送信時': { // @AjaxでURLにPARAMSをフォームとしてPOST送信し『対象』にデータを設定 // @POSTふぉーむそうしんしたとき
|
|
742
|
+
type: 'func',
|
|
743
|
+
josi: [['の'], ['まで', 'へ', 'に'], ['を']],
|
|
744
|
+
pure: true,
|
|
745
|
+
fn: function (callback, url, params, sys) {
|
|
746
|
+
const fd = new FormData()
|
|
747
|
+
for (const key in params) { fd.set(key, params[key]) }
|
|
748
|
+
|
|
749
|
+
const options = {
|
|
750
|
+
method: 'POST',
|
|
751
|
+
headers: {
|
|
752
|
+
'Content-Type': 'multipart/form-data'
|
|
753
|
+
},
|
|
754
|
+
body: fd
|
|
755
|
+
}
|
|
756
|
+
fetch(url, options).then(res => {
|
|
757
|
+
return res.text()
|
|
758
|
+
}).then(text => {
|
|
759
|
+
sys.__v0['対象'] = text
|
|
760
|
+
callback(text)
|
|
761
|
+
}).catch(err => {
|
|
762
|
+
sys.__v0['AJAX:ONERROR'](err)
|
|
763
|
+
})
|
|
764
|
+
}
|
|
765
|
+
},
|
|
766
|
+
'AJAX失敗時': { // @Ajax命令でエラーが起きたとき // @AJAXえらーしっぱいしたとき
|
|
767
|
+
type: 'func',
|
|
768
|
+
josi: [['の']],
|
|
769
|
+
pure: true,
|
|
770
|
+
fn: function (callback, sys) {
|
|
771
|
+
sys.__v0['AJAX:ONERROR'] = callback
|
|
772
|
+
}
|
|
773
|
+
},
|
|
774
|
+
'AJAXオプション': { type: 'const', value: '' }, // @Ajax関連のオプションを指定 // @AJAXおぷしょん
|
|
775
|
+
'AJAXオプション設定': { // @Ajax命令でオプションを設定 // @AJAXおぷしょんせってい
|
|
776
|
+
type: 'func',
|
|
777
|
+
josi: [['に', 'へ', 'と']],
|
|
778
|
+
pure: true,
|
|
779
|
+
fn: function (option, sys) {
|
|
780
|
+
sys.__v0['AJAXオプション'] = option
|
|
781
|
+
},
|
|
782
|
+
return_none: true
|
|
783
|
+
},
|
|
784
|
+
'AJAX保障送信': { // @非同期通信(Ajax)でURLにデータの送信を開始する非同期処理オブジェクト(Promise)を作成する。 // @AJAXほしょうそうしん
|
|
785
|
+
type: 'func',
|
|
786
|
+
josi: [['まで', 'へ', 'に']],
|
|
787
|
+
pure: true,
|
|
788
|
+
fn: function (url, sys) {
|
|
789
|
+
let options = sys.__v0['AJAXオプション']
|
|
790
|
+
if (options === '') { options = { method: 'GET' } }
|
|
791
|
+
return fetch(url, options)
|
|
792
|
+
},
|
|
793
|
+
return_none: false
|
|
794
|
+
},
|
|
795
|
+
'HTTP保障取得': { // @非同期通信(Ajax)でURLにデータの送信を開始する非同期処理オブジェクト(Promise)を作成する。 // @HTTPほしょうしゅとく
|
|
796
|
+
type: 'func',
|
|
797
|
+
josi: [['の', 'から', 'を']],
|
|
798
|
+
pure: true,
|
|
799
|
+
fn: function (url, sys) {
|
|
800
|
+
return sys.__exec('AJAX保障送信', [url, sys])
|
|
801
|
+
},
|
|
802
|
+
return_none: false
|
|
803
|
+
},
|
|
804
|
+
'GET保障送信': { // @非同期通信(Ajax)でURLにデータの送信を開始する非同期処理オブジェクト(Promise)を作成する。 // @GETほしょうそうしん
|
|
805
|
+
type: 'func',
|
|
806
|
+
josi: [['まで', 'へ', 'に']],
|
|
807
|
+
pure: true,
|
|
808
|
+
fn: function (url, sys) {
|
|
809
|
+
return sys.__exec('AJAX保障送信', [url, sys])
|
|
810
|
+
},
|
|
811
|
+
return_none: false
|
|
812
|
+
},
|
|
813
|
+
'POST保障送信': { // @非同期通信(Ajax)でURLにPARAMSをPOST送信を開始する非同期処理オブジェクト(Promise)を作成する。 // @POSTほしょうそうしん
|
|
814
|
+
type: 'func',
|
|
815
|
+
josi: [['まで', 'へ', 'に'], ['を']],
|
|
816
|
+
pure: true,
|
|
817
|
+
fn: function (url, params, sys) {
|
|
818
|
+
const flist = []
|
|
819
|
+
for (const key in params) {
|
|
820
|
+
const v = params[key]
|
|
821
|
+
const kv = encodeURIComponent(key) + '=' + encodeURIComponent(v)
|
|
822
|
+
flist.push(kv)
|
|
823
|
+
}
|
|
824
|
+
const bodyData = flist.join('&')
|
|
825
|
+
const options = {
|
|
826
|
+
method: 'POST',
|
|
827
|
+
headers: {
|
|
828
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
829
|
+
},
|
|
830
|
+
body: bodyData
|
|
831
|
+
}
|
|
832
|
+
return fetch(url, options)
|
|
833
|
+
},
|
|
834
|
+
return_none: false
|
|
835
|
+
},
|
|
836
|
+
'POSTフォーム保障送信': { // @非同期通信(Ajax)でURLにPARAMSをフォームとしてPOST送信を開始する非同期処理オブジェクト(Promise)を作成する。 // @POSTふぉーむほしょうそうしん
|
|
837
|
+
type: 'func',
|
|
838
|
+
josi: [['まで', 'へ', 'に'], ['を']],
|
|
839
|
+
pure: true,
|
|
840
|
+
fn: function (url, params, sys) {
|
|
841
|
+
const fd = new FormData()
|
|
842
|
+
for (const key in params) { fd.set(key, params[key]) }
|
|
843
|
+
|
|
844
|
+
const options = {
|
|
845
|
+
method: 'POST',
|
|
846
|
+
body: fd
|
|
847
|
+
}
|
|
848
|
+
return fetch(url, options)
|
|
849
|
+
},
|
|
850
|
+
return_none: false
|
|
851
|
+
},
|
|
852
|
+
'AJAX内容取得': { // @非同期通信(Ajax)の応答から内容を指定した形式で取り出すための非同期処理オブジェクト(Promise)を返す。 // @AJAXないようしゅとく
|
|
853
|
+
type: 'func',
|
|
854
|
+
josi: [['から'], ['で']],
|
|
855
|
+
pure: true,
|
|
856
|
+
fn: function (res, type, sys) {
|
|
857
|
+
type = type.toString().toUpperCase()
|
|
858
|
+
if (type === 'TEXT' || type === 'テキスト') {
|
|
859
|
+
return res.text()
|
|
860
|
+
} else
|
|
861
|
+
if (type === 'JSON') {
|
|
862
|
+
return res.json()
|
|
863
|
+
} else
|
|
864
|
+
if (type === 'BLOB') {
|
|
865
|
+
return res.blob()
|
|
866
|
+
} else
|
|
867
|
+
if (type === 'ARRAY' || type === '配列') {
|
|
868
|
+
return res.arrayBuffer()
|
|
869
|
+
} else
|
|
870
|
+
if (type === 'BODY' || type === '本体') {
|
|
871
|
+
return res.body
|
|
872
|
+
}
|
|
873
|
+
return res.body()
|
|
874
|
+
},
|
|
875
|
+
return_none: false
|
|
876
|
+
},
|
|
877
|
+
'AJAX受信': { // @「!非同期モード」で非同期通信(Ajax)でURLからデータを受信する。『AJAXオプション』を指定できる。結果は変数『対象』に入る// @AJAXじゅしん
|
|
878
|
+
type: 'func',
|
|
879
|
+
josi: [['から', 'を']],
|
|
880
|
+
pure: true,
|
|
881
|
+
fn: function (url, sys) {
|
|
882
|
+
if (sys.__genMode !== '非同期モード') {
|
|
883
|
+
throw new Error('『AJAX受信』を使うには、プログラムの冒頭で「!非同期モード」と宣言してください。')
|
|
884
|
+
}
|
|
885
|
+
sys.async = true
|
|
886
|
+
let options = sys.__v0['AJAXオプション']
|
|
887
|
+
if (options === '') { options = { method: 'GET' } }
|
|
888
|
+
// fetch 実行
|
|
889
|
+
fetch(url, options).then(res => {
|
|
890
|
+
if (res.ok) { // 成功したとき
|
|
891
|
+
return res.text()
|
|
892
|
+
} else { // 失敗したとき
|
|
893
|
+
throw new Error('status=' + res.status)
|
|
894
|
+
}
|
|
895
|
+
}).then(text => {
|
|
896
|
+
sys.__v0['対象'] = text
|
|
897
|
+
sys.nextAsync(sys)
|
|
898
|
+
}).catch(err => {
|
|
899
|
+
console.error('[AJAX受信のエラー]', err)
|
|
900
|
+
sys.__errorAsync(err, sys)
|
|
901
|
+
})
|
|
902
|
+
},
|
|
903
|
+
return_none: true
|
|
904
|
+
},
|
|
905
|
+
// @文字コード
|
|
906
|
+
'文字コード変換サポート判定': { // @文字コードCODEをサポートしているか確認 // @もじこーどさぽーとはんてい
|
|
907
|
+
type: 'func',
|
|
908
|
+
josi: [['の', 'を']],
|
|
909
|
+
pure: true,
|
|
910
|
+
fn: function (code, sys) {
|
|
911
|
+
const iconv = require('iconv-lite')
|
|
912
|
+
return iconv.encodingExists(code)
|
|
913
|
+
}
|
|
914
|
+
},
|
|
915
|
+
'SJIS変換': { // @(v1非互換)文字列をShift_JISのバイナリバッファに変換 // @SJISへんかん
|
|
916
|
+
type: 'func',
|
|
917
|
+
josi: [['に', 'へ', 'を']],
|
|
918
|
+
pure: true,
|
|
919
|
+
fn: function (str, sys) {
|
|
920
|
+
const iconv = require('iconv-lite')
|
|
921
|
+
iconv.skipDecodeWarning = true
|
|
922
|
+
return iconv.encode(str, 'Shift_JIS')
|
|
923
|
+
}
|
|
924
|
+
},
|
|
925
|
+
'SJIS取得': { // @Shift_JISのバイナリバッファを文字列に変換 // @SJISしゅとく
|
|
926
|
+
type: 'func',
|
|
927
|
+
josi: [['から', 'を', 'で']],
|
|
928
|
+
pure: true,
|
|
929
|
+
fn: function (buf, sys) {
|
|
930
|
+
const iconv = require('iconv-lite')
|
|
931
|
+
iconv.skipDecodeWarning = true
|
|
932
|
+
return iconv.decode(Buffer.from(buf), 'sjis')
|
|
933
|
+
}
|
|
934
|
+
},
|
|
935
|
+
'エンコーディング変換': { // @文字列SをCODEへ変換してバイナリバッファを返す // @ えんこーでぃんぐへんかん
|
|
936
|
+
type: 'func',
|
|
937
|
+
josi: [['を'], ['へ', 'で']],
|
|
938
|
+
pure: true,
|
|
939
|
+
fn: function (s, code, sys) {
|
|
940
|
+
const iconv = require('iconv-lite')
|
|
941
|
+
iconv.skipDecodeWarning = true
|
|
942
|
+
return iconv.encode(s, code)
|
|
943
|
+
}
|
|
944
|
+
},
|
|
945
|
+
'エンコーディング取得': { // @バイナリバッファBUFをCODEから変換して返す // @えんこーでぃんぐしゅとく
|
|
946
|
+
type: 'func',
|
|
947
|
+
josi: [['を'], ['から', 'で']],
|
|
948
|
+
pure: true,
|
|
949
|
+
fn: function (buf, code, sys) {
|
|
950
|
+
const iconv = require('iconv-lite')
|
|
951
|
+
iconv.skipDecodeWarning = true
|
|
952
|
+
return iconv.decode(Buffer.from(buf), code)
|
|
953
|
+
}
|
|
954
|
+
},
|
|
955
|
+
// @マウスとキーボード操作
|
|
956
|
+
'キー送信': { // @Sのキーを送信 // @きーそうしん
|
|
957
|
+
type: 'func',
|
|
958
|
+
josi: [['を', 'の']],
|
|
959
|
+
pure: true,
|
|
960
|
+
fn: function (s, sys) {
|
|
961
|
+
const keys = require('sendkeys-js')
|
|
962
|
+
keys.sendKeys(s)
|
|
963
|
+
},
|
|
964
|
+
return_none: true
|
|
965
|
+
},
|
|
966
|
+
'窓アクティブ': { // @Sの窓をアクティブにする // @まどあくてぃぶ
|
|
967
|
+
type: 'func',
|
|
968
|
+
josi: [['を', 'の']],
|
|
969
|
+
pure: true,
|
|
970
|
+
fn: function (s, sys) {
|
|
971
|
+
const keys = require('sendkeys-js')
|
|
972
|
+
keys.activate(s)
|
|
973
|
+
},
|
|
974
|
+
return_none: true
|
|
975
|
+
},
|
|
976
|
+
// @ハッシュ関数
|
|
977
|
+
'ハッシュ関数一覧取得': { // @利用可能なハッシュ関数の一覧を返す // @ はっしゅかんすういちらんしゅとく
|
|
978
|
+
type: 'func',
|
|
979
|
+
josi: [],
|
|
980
|
+
pure: true,
|
|
981
|
+
fn: function (sys) {
|
|
982
|
+
const crypto = require('crypto')
|
|
983
|
+
return crypto.getHashes()
|
|
984
|
+
}
|
|
985
|
+
},
|
|
986
|
+
'ハッシュ値計算': { // @データSをアルゴリズムALG(sha256/sha512/md5)のエンコーディングENC(hex/base64)でハッシュ値を計算して返す // @ はっしゅちけいさん
|
|
987
|
+
type: 'func',
|
|
988
|
+
josi: [['を'], ['の'], ['で']],
|
|
989
|
+
pure: true,
|
|
990
|
+
fn: function (s, alg, enc, sys) {
|
|
991
|
+
const crypto = require('crypto')
|
|
992
|
+
const hashsum = crypto.createHash(alg)
|
|
993
|
+
hashsum.update(s)
|
|
994
|
+
return hashsum.digest(enc)
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
// ローカル関数
|
|
1000
|
+
function fileExists (f) {
|
|
1001
|
+
try {
|
|
1002
|
+
fs.statSync(f)
|
|
1003
|
+
return true
|
|
1004
|
+
} catch (err) {
|
|
1005
|
+
return false
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
function isDir (f) {
|
|
1010
|
+
try {
|
|
1011
|
+
const st = fs.statSync(f)
|
|
1012
|
+
return st.isDirectory()
|
|
1013
|
+
} catch (err) {
|
|
1014
|
+
return false
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
module.exports = PluginNode
|