@lmjs/cli 2.7.0 → 2.8.0

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/dist/lib/fcs.js CHANGED
@@ -7,5 +7,5 @@ var _vcData = {
7
7
  };
8
8
  `;try{let _indexJsSrc=_hasOwnDeps?_npmBundle.buildEntryWithImports(projectPath+path.sep+"src"+path.sep+"index.js",projectPath):String(indexJs);if(_split)vt+=_split.manifestJs;vt+=_compiledScripts+"\n"+compileProjectScript(_indexJsSrc,"index")}catch(e){spinner.fail("Error compiling index.js: "+(e&&e.message?e.message:e));spinner.fail("Build Failed! Fix index.js and try again.");return}indexCode=v1CompatIndexHtml(indexCode);spinner.succeed("Gathering Required Resources").start("Signing & Securing App..");let vaultApis=await _vault.resolveVaultApis(projectPath);let effectiveApis=(config.apis||[]).concat(vaultApis);let baasEntry=(config.apis||[]).find(a=>a&&typeof a.baseURL==="string"&&a.baseURL.indexOf("beaapis.com")>-1);let beajsAppId=baasEntry&&baasEntry.headers&&baasEntry.headers["X-BEA-Application-ID"];let beajsAuth=baasEntry&&baasEntry.headers&&baasEntry.headers["X-BEA-Authorization"];const keyUnset=v=>!v||/^YOUR_/i.test(String(v).trim());let token_="";if(!baasEntry||keyUnset(beajsAppId)||keyUnset(beajsAuth)){spinner.warn("No Roxyon BaaS keys in config.json, so this build has no backend token. The app works as a static site; to use the Roxyon BaaS (data, auth, files), add your app's keys from https://console.roxyon.com to config.json's apis[] and build again.");spinner.start("Signing & Securing App..")}else{let beajsRawRes;try{beajsRawRes=await API.req("https://www.beaapis.com/1/beajs",{data:{apis:JSON.stringify(effectiveApis)}},{"X-BEA-Application-ID":beajsAppId,"X-BEA-Authorization":beajsAuth},"POST",void 0,true)}catch(e){spinner.fail("Error getting a unique token for production! "+(e&&e.message?e.message:e));spinner.fail("Build Failed! Try again later.");return}if(!beajsRawRes.ok){spinner.fail("Error getting a unique token for production! HTTP "+beajsRawRes.status+(beajsRawRes.status===401||beajsRawRes.status===403?" (the Roxyon BaaS keys in config.json were rejected: check them in https://console.roxyon.com)":""));spinner.fail("Build Failed!");return}let r={};try{r=JSON.parse(await beajsRawRes.text())}catch(e){r={}}token_=r.token;if(!token_){spinner.fail("Error getting a unique token for production!");spinner.fail("Build Failed! Try again later.");return}}let _tokenJs=`
9
9
  var _beaTn = "`+token_+`";
10
- `+(token_?"":"var _lmStatic = true;\n");let _runtimeCode=_uncompiledScripts===0?stripDevOnlyRuntime(ownRuntime):ownRuntime;let js_=_runtimePlan?vt:_tokenJs+_runtimeCode+"\n"+vt;spinner.succeed("Signing & Securing App").start("Packing & Cleaning...");rd(dest);spinner.succeed("Packing & Cleaning").start("Writing Files...");let buildPath=`build_serverless`;copyDir(`${__dirname}`+path.sep+`files`+path.sep+buildPath,dest);copyDir(projectPath+path.sep+"src",dest,"_beajsBuild");cd(dest+path.sep+"js");cd(dest+path.sep+"css");cd(dest+path.sep+"images");copyDir(projectPath+path.sep+"src"+path.sep+"js",dest+path.sep+"js","_beajsBuild");copyDir(projectPath+path.sep+"src"+path.sep+"css",dest+path.sep+"css","_beajsBuild");copyDir(projectPath+path.sep+"src"+path.sep+"images",dest+path.sep+"images","_beajsBuild");fs.writeFileSync(dest+path.sep+"js"+path.sep+"lm.js",String(js_));let _dT=new Date().getTime();if(_runtimePlan){let _rtDir=dest+path.sep+"js"+path.sep+"lumenjs"+path.sep+_runtimePlan.version;fs.mkdirSync(_rtDir,{recursive:true});fs.writeFileSync(_rtDir+path.sep+_runtimePlan.file,_runtimePlan.code)}if(_split){for(const rel in _split.files){let _f=dest+path.sep+rel.split("/").join(path.sep);fs.mkdirSync(path.dirname(_f),{recursive:true});fs.writeFileSync(_f,_split.files[rel])}}fs.renameSync(dest+path.sep+"js"+path.sep+"lm.js",dest+path.sep+"js"+path.sep+"app."+_dT+".js");if(!fs.existsSync(dest+path.sep+"css"))fs.mkdirSync(dest+path.sep+"css",{recursive:true});let _cssAppFile="app."+_cdnRt.shortHash(String(beaCSSCode))+".css";let _stylesFile="styles.css";if(_mainCssName){let _copied=dest+path.sep+"css"+path.sep+_mainCssName;if(fs.existsSync(_copied))fs.unlinkSync(_copied);fs.writeFileSync(dest+path.sep+"css"+path.sep+_cssAppFile,String(beaCSSCode))}let _hasStyles=fs.existsSync(dest+path.sep+"css"+path.sep+"styles.css");if(_hasStyles){_stylesFile="styles."+_cdnRt.shortHash(fs.readFileSync(dest+path.sep+"css"+path.sep+"styles.css","utf8"))+".css";fs.renameSync(dest+path.sep+"css"+path.sep+"styles.css",dest+path.sep+"css"+path.sep+_stylesFile)}let _selectedPlugins=selectedProjectPlugins(projectPath);let _pluginsTags="";let _pluginsCssTag="";if(_selectedPlugins.length){let _pluginsJs=await _pluginsBundle.buildSelectedPluginsBundle(_selectedPlugins,projectPath,{minify:true});let _pluginsCss=await _pluginsBundle.buildSelectedCss(_selectedPlugins,projectPath+path.sep+"node_modules");let _pjs="plugins."+_cdnRt.shortHash(String(_pluginsJs))+".js";fs.writeFileSync(dest+path.sep+"js"+path.sep+_pjs,String(_pluginsJs));_pluginsTags+=`
10
+ `+(token_?"":"var _lmStatic = true;\n");let _runtimeCode=_uncompiledScripts===0?stripDevOnlyRuntime(ownRuntime):ownRuntime;let js_=_runtimePlan?vt:_tokenJs+_runtimeCode+"\n"+vt;spinner.succeed("Signing & Securing App").start("Packing & Cleaning...");rd(dest);spinner.succeed("Packing & Cleaning").start("Writing Files...");let buildPath=`build_serverless`;copyDir(`${__dirname}`+path.sep+`files`+path.sep+buildPath,dest);copyDir(projectPath+path.sep+"src",dest,"_beajsBuild");try{const _seo=require("./seo-files.js").writeSeoFiles(projectPath,dest,config);if(!_seo.site)spinner.info('No site address (config.json "domain" or project_info.WebsiteURL): robots.txt has no Sitemap line and no sitemap.xml was made.');spinner.start("Writing Files...")}catch(e){spinner.warn("SEO files were not written: "+(e&&e.message?e.message:e));spinner.start("Writing Files...")}cd(dest+path.sep+"js");cd(dest+path.sep+"css");cd(dest+path.sep+"images");copyDir(projectPath+path.sep+"src"+path.sep+"js",dest+path.sep+"js","_beajsBuild");copyDir(projectPath+path.sep+"src"+path.sep+"css",dest+path.sep+"css","_beajsBuild");copyDir(projectPath+path.sep+"src"+path.sep+"images",dest+path.sep+"images","_beajsBuild");fs.writeFileSync(dest+path.sep+"js"+path.sep+"lm.js",String(js_));let _dT=new Date().getTime();if(_runtimePlan){let _rtDir=dest+path.sep+"js"+path.sep+"lumenjs"+path.sep+_runtimePlan.version;fs.mkdirSync(_rtDir,{recursive:true});fs.writeFileSync(_rtDir+path.sep+_runtimePlan.file,_runtimePlan.code)}if(_split){for(const rel in _split.files){let _f=dest+path.sep+rel.split("/").join(path.sep);fs.mkdirSync(path.dirname(_f),{recursive:true});fs.writeFileSync(_f,_split.files[rel])}}fs.renameSync(dest+path.sep+"js"+path.sep+"lm.js",dest+path.sep+"js"+path.sep+"app."+_dT+".js");if(!fs.existsSync(dest+path.sep+"css"))fs.mkdirSync(dest+path.sep+"css",{recursive:true});let _cssAppFile="app."+_cdnRt.shortHash(String(beaCSSCode))+".css";let _stylesFile="styles.css";if(_mainCssName){let _copied=dest+path.sep+"css"+path.sep+_mainCssName;if(fs.existsSync(_copied))fs.unlinkSync(_copied);fs.writeFileSync(dest+path.sep+"css"+path.sep+_cssAppFile,String(beaCSSCode))}let _hasStyles=fs.existsSync(dest+path.sep+"css"+path.sep+"styles.css");if(_hasStyles){_stylesFile="styles."+_cdnRt.shortHash(fs.readFileSync(dest+path.sep+"css"+path.sep+"styles.css","utf8"))+".css";fs.renameSync(dest+path.sep+"css"+path.sep+"styles.css",dest+path.sep+"css"+path.sep+_stylesFile)}let _selectedPlugins=selectedProjectPlugins(projectPath);let _pluginsTags="";let _pluginsCssTag="";if(_selectedPlugins.length){let _pluginsJs=await _pluginsBundle.buildSelectedPluginsBundle(_selectedPlugins,projectPath,{minify:true});let _pluginsCss=await _pluginsBundle.buildSelectedCss(_selectedPlugins,projectPath+path.sep+"node_modules");let _pjs="plugins."+_cdnRt.shortHash(String(_pluginsJs))+".js";fs.writeFileSync(dest+path.sep+"js"+path.sep+_pjs,String(_pluginsJs));_pluginsTags+=`
11
11
  <script src="/js/`+_pjs+`" type="text/javascript"><\/script>`;if(_pluginsCss&&_pluginsCss.trim()!=""){let _pcss="plugins."+_cdnRt.shortHash(String(_pluginsCss))+".css";fs.writeFileSync(dest+path.sep+"css"+path.sep+_pcss,String(_pluginsCss));_pluginsCssTag=`<link href="/css/`+_pcss+`" rel="stylesheet" type="text/css" />`}}if(_split&&_split.routes){indexCode=String(indexCode).split("</head>").join(" "+_cdnRt.routePreload(_split.routes)+"\n</head>")}if(_runtimePlan){const _lmTag=/<script\b[^>]*\bsrc=["']\/?js\/lm\.js["'][^>]*>\s*<\/script>/i;if(_lmTag.test(indexCode)){const _tags=_cdnRt.runtimeTags(_runtimePlan,_tokenJs,"/js/app."+_dT+".js");indexCode=String(indexCode).replace(_lmTag,()=>_tags).split("</head>").join(" "+_cdnRt.preconnectTag()+"\n</head>")}else{fs.writeFileSync(dest+path.sep+"js"+path.sep+"app."+_dT+".js",_tokenJs+_runtimeCode+"\n"+vt);fs.rmSync(dest+path.sep+"js"+path.sep+"lumenjs",{recursive:true,force:true});_runtimePlan=null}}let _indexOut=String(indexCode).split("/js/lm.js").join("/js/app."+_dT+".js").split("/css/styles.css").join("/css/"+_stylesFile).split("/css/"+(_mainCssName||"mobius.css")).join(_mainCssName?"/css/"+_cssAppFile:"/css/mobius.css").split("</head>").join(_pluginsTags+"\n</head>");if(_pluginsCssTag)_indexOut=placePluginsCss(_indexOut,_pluginsCssTag);fs.writeFileSync(dest+path.sep+"index.html",_indexOut);if(cmds.indexOf("--deploy")>=0){spinner.succeed("Writing Files").start("Uploading To Server..");const _config={user:config.ftp.username,password:config.ftp.password,host:config.ftp.host,port:config.ftp.port,localRoot:dest,remoteRoot:config.ftp.remotePath,include:["*","**/*",".*"],exclude:config.ftp.ignore,deleteRemote:false,forcePasv:true,sftp:config.ftp.protocol=="sftp"?true:false};_fD.deploy(_config,function(err,res){if(err){console.log(err)}else{spinner.succeed("Finished Uploading To Server");spinner.succeed("Done")}});_fD.on("uploading",function(data){spinner.start(parseFloat((data.transferredFileCount*100/data.totalFilesCount).toFixed(2))+"% Uploading "+data.filename+" ")})}else spinner.succeed("Writing Files").succeed("Done")})}function clear(isSoft){process.stdout.write(isSoft?"\x1B[H\x1B[2J":"\x1B[2J\x1B[3J\x1B[H\x1Bc")}function startServer(){clear();if(!process.env.LM_COPILOT_TOKEN)process.env.LM_COPILOT_TOKEN=require("crypto").randomBytes(24).toString("hex");if(!process.env.LM_COPILOT_AUTO)process.env.LM_COPILOT_AUTO=process.stdout.isTTY&&!process.env.CI?"1":"0";nodemon({script:path.join(__dirname.toString(),"app.js"),ext:"view,js,css,json,layout,html",watch:["src/","config.json"],ignore:["src/views/**","src/layouts/**"]});nodemon.on("restart",files2=>{console.log(files2)})}
@@ -1,4 +1,2 @@
1
- Sitemap: https://www.lumenjs.com/sitemap.xml
2
-
3
1
  User-agent: *
4
- Disallow:
2
+ Allow: /
@@ -0,0 +1,200 @@
1
+ <?php
2
+ // LumenJS: the page search engines and link previews get (WhatsApp, Facebook, LinkedIn, X, Telegram, Google, Bing...).
3
+ // Written by `lm build` when the project has no seo.php of its own. On Roxyon hosting the router sends known crawlers
4
+ // here (Domains.SiteOptions.seo_prerender); visitors get index.html. Settings: seo.json next to this file (made by the
5
+ // build from config.json's project_info, the views and the project's own src/seo.json). A route can read its item
6
+ // from Roxyon Base with the site's publishable key (public read rules only), cached a few minutes.
7
+ declare(strict_types=1);
8
+
9
+ $cfg = json_decode((string) @file_get_contents(__DIR__ . '/seo.json'), true);
10
+ $cfg = is_array($cfg) ? $cfg : [];
11
+ $host = preg_replace('/[^a-z0-9.:-]/', '', strtolower((string) ($_SERVER['HTTP_HOST'] ?? 'localhost')));
12
+ $site = rtrim((string) ($cfg['site'] ?? ''), '/') ?: 'https://' . $host;
13
+ $abs = fn (string $u): string => $u === '' ? '' : (preg_match('#^https?://#i', $u) ? $u : $site . '/' . ltrim($u, '/'));
14
+ $name = (string) ($cfg['name'] ?? $host);
15
+ $route = trim((string) ($_GET['__nodes'] ?? ''), '/');
16
+ $parts = $route === '' ? [] : explode('/', $route);
17
+
18
+ /** The route pattern that matches ("product/:id" style), with its params. */
19
+ $match = null;
20
+ $params = [];
21
+ foreach ((array) ($cfg['routes'] ?? []) as $pattern => $r) {
22
+ $pp = trim((string) $pattern, '/');
23
+ $segs = $pp === '' ? [] : explode('/', $pp);
24
+ if (count($segs) !== count($parts)) {
25
+ continue;
26
+ }
27
+ $ok = true;
28
+ $p = [];
29
+ foreach ($segs as $i => $s) {
30
+ if ($s !== '' && $s[0] === ':') {
31
+ $p[substr($s, 1)] = rawurldecode($parts[$i]);
32
+ } elseif (strcasecmp($s, $parts[$i]) !== 0) {
33
+ $ok = false;
34
+ break;
35
+ }
36
+ }
37
+ if ($ok) {
38
+ $match = is_array($r) ? $r : [];
39
+ $params = $p;
40
+ break;
41
+ }
42
+ }
43
+
44
+ function seo_tmp(): string
45
+ {
46
+ $d = dirname(__DIR__) . '/tmp/lm-seo';
47
+ if (!is_dir($d)) {
48
+ @mkdir($d, 0700, true);
49
+ }
50
+ return is_dir($d) && is_writable($d) ? $d : sys_get_temp_dir();
51
+ }
52
+
53
+ function seo_http(string $method, string $url, array $headers, string $origin, ?string $body = null): ?array
54
+ {
55
+ $headers[] = 'Origin: ' . $origin;
56
+ $headers[] = 'X-BEA-Installation-ID: lm-seo';
57
+ $ctx = stream_context_create(['http' => ['method' => $method, 'header' => implode("\r\n", $headers), 'content' => $body ?? '', 'timeout' => 4, 'ignore_errors' => true]]);
58
+ $out = @file_get_contents($url, false, $ctx);
59
+ $d = $out === false ? null : json_decode($out, true);
60
+ return is_array($d) ? $d : null;
61
+ }
62
+
63
+ /** One record for a route that names a Base class: {key, class, field?, base?}; null when not found or not public. */
64
+ function seo_record(array $b, string $value, string $origin): ?array
65
+ {
66
+ $key = (string) ($b['key'] ?? '');
67
+ $class = preg_replace('/[^A-Za-z0-9_]/', '', (string) ($b['class'] ?? ''));
68
+ $field = preg_replace('/[^A-Za-z0-9_]/', '', (string) ($b['field'] ?? 'objectId'));
69
+ $api = rtrim((string) ($b['base'] ?? 'https://www.beaapis.com/2'), '/');
70
+ if ($key === '' || $class === '' || !preg_match('/^[\p{L}\p{N}_.\- ]{1,120}$/u', $value)) {
71
+ return null;
72
+ }
73
+ $f = seo_tmp() . '/r-' . md5($class . '|' . $field . '|' . $value) . '.json';
74
+ if (is_file($f) && filemtime($f) > time() - 300) {
75
+ $c = json_decode((string) @file_get_contents($f), true);
76
+ return is_array($c) && $c ? $c : null;
77
+ }
78
+ $tf = seo_tmp() . '/token-' . md5($key) . '.json';
79
+ $row = null;
80
+ foreach ([false, true] as $fresh) {
81
+ $tok = null;
82
+ if (!$fresh && is_file($tf)) {
83
+ $t = json_decode((string) @file_get_contents($tf), true);
84
+ if (is_array($t) && ($t['until'] ?? 0) > time()) {
85
+ $tok = (string) ($t['token'] ?? '');
86
+ }
87
+ }
88
+ if (!$tok) {
89
+ $d = seo_http('POST', $api . '/auth/public', ['Content-Type: application/json'], $origin, (string) json_encode(['key' => $key]));
90
+ if (empty($d['access_token'])) {
91
+ break;
92
+ }
93
+ $tok = (string) $d['access_token'];
94
+ @file_put_contents($tf, json_encode(['token' => $tok, 'until' => time() + min(3600, (int) ($d['expires_in'] ?? 3600)) - 60]), LOCK_EX);
95
+ @chmod($tf, 0600);
96
+ }
97
+ $q = http_build_query(['limit' => 1, 'media' => 'images', 'where' => json_encode([$field => $value])]);
98
+ $d = seo_http('GET', $api . '/records/' . $class . '?' . $q, ['Authorization: Bearer ' . $tok], $origin);
99
+ if (is_array($d) && !empty($d['ok'])) {
100
+ $row = $d['results'][0] ?? null;
101
+ break;
102
+ }
103
+ }
104
+ @file_put_contents($f, json_encode($row ?: []), LOCK_EX);
105
+ return is_array($row) && $row ? $row : null;
106
+ }
107
+
108
+ /** A record's first photo (product photos first), at 1200 px. */
109
+ function seo_photo(array $row): string
110
+ {
111
+ $all = [];
112
+ foreach ((array) ($row['images'] ?? []) as $g) {
113
+ foreach ((array) $g as $p) {
114
+ if (is_array($p) && !empty($p['dir']) && !empty($p['image'])) {
115
+ $all[] = $p;
116
+ }
117
+ }
118
+ }
119
+ if (!$all) {
120
+ return '';
121
+ }
122
+ usort($all, fn ($a, $b) => (int) !preg_match('/^product/i', (string) ($a['title'] ?? '')) <=> (int) !preg_match('/^product/i', (string) ($b['title'] ?? '')));
123
+ return $all[0]['dir'] . preg_replace('/(\.[a-z0-9]+)$/i', '(1200xa)$1', (string) $all[0]['image']);
124
+ }
125
+
126
+ $fill = function (string $tpl, array $vars): string {
127
+ return trim(preg_replace_callback('/\{(\w+)\}/', fn ($m) => (string) ($vars[$m[1]] ?? ''), $tpl));
128
+ };
129
+ $text = fn ($v): string => trim(preg_replace('/\s+/', ' ', strip_tags(html_entity_decode(is_array($v) ? (string) ($v['en'] ?? reset($v) ?: '') : (string) $v))));
130
+
131
+ $title = (string) ($cfg['title'] ?? $name);
132
+ $desc = (string) ($cfg['description'] ?? '');
133
+ $image = $abs((string) ($cfg['image'] ?? ''));
134
+ $type = 'website';
135
+ $status = 200;
136
+ $body = '';
137
+ if ($match !== null) {
138
+ $vars = $params;
139
+ if (!empty($match['base']) && is_array($match['base'])) {
140
+ $param = (string) ($match['base']['param'] ?? (array_key_first($params) ?? ''));
141
+ $row = $param !== '' && isset($params[$param]) ? seo_record($match['base'], (string) $params[$param], $site) : null;
142
+ if ($row === null) {
143
+ $status = 404;
144
+ } else {
145
+ foreach ($row as $k => $v) {
146
+ if (is_scalar($v) || (is_array($v) && isset($v['en']))) {
147
+ $vars[$k] = $text($v);
148
+ }
149
+ }
150
+ $photo = seo_photo($row);
151
+ if ($photo !== '') {
152
+ $image = $photo;
153
+ }
154
+ }
155
+ }
156
+ if ($status === 200) {
157
+ $title = $fill((string) ($match['title'] ?? $title), $vars) ?: $title;
158
+ $desc = mb_substr($fill((string) ($match['description'] ?? $desc), $vars) ?: $desc, 0, 300);
159
+ if (!empty($match['image']) && !preg_match('/\{/', (string) $match['image'])) {
160
+ $image = $abs((string) $match['image']);
161
+ }
162
+ $type = (string) ($match['type'] ?? $type);
163
+ $body = $fill((string) ($match['body'] ?? ''), $vars);
164
+ }
165
+ } elseif ($route !== '') {
166
+ $status = 404;
167
+ }
168
+ $url = $site . '/' . ($route === '' ? '' : implode('/', array_map('rawurlencode', $parts)));
169
+ http_response_code($status);
170
+ header('Content-Type: text/html; charset=utf-8');
171
+ header('Cache-Control: public, max-age=300');
172
+ $h = fn ($s) => htmlspecialchars((string) $s, ENT_QUOTES | ENT_HTML5, 'UTF-8');
173
+ $lang = preg_replace('/[^a-z-]/', '', strtolower((string) ($cfg['lang'] ?? 'en'))) ?: 'en';
174
+ $links = array_filter(array_keys((array) ($cfg['routes'] ?? [])), fn ($p) => strpos((string) $p, ':') === false);
175
+ ?><!DOCTYPE html>
176
+ <html lang="<?= $h($lang) ?>"<?= in_array($lang, ['ar', 'fa', 'he', 'ur'], true) ? ' dir="rtl"' : '' ?>>
177
+ <head>
178
+ <meta charset="utf-8">
179
+ <title><?= $h($title) ?></title>
180
+ <meta name="description" content="<?= $h($desc) ?>">
181
+ <link rel="canonical" href="<?= $h($url) ?>">
182
+ <meta property="og:site_name" content="<?= $h($name) ?>">
183
+ <meta property="og:type" content="<?= $h($type) ?>">
184
+ <meta property="og:url" content="<?= $h($url) ?>">
185
+ <meta property="og:title" content="<?= $h($title) ?>">
186
+ <meta property="og:description" content="<?= $h($desc) ?>">
187
+ <?php if ($image !== ''): ?><meta property="og:image" content="<?= $h($image) ?>">
188
+ <?php endif; ?>
189
+ <meta name="twitter:card" content="<?= $image !== '' ? 'summary_large_image' : 'summary' ?>">
190
+ <script type="application/ld+json"><?= json_encode(['@context' => 'https://schema.org', '@type' => $type === 'product' ? 'Product' : 'WebPage', 'name' => $title, 'description' => $desc, 'url' => $url] + ($image !== '' ? ['image' => $image] : []), JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG) ?></script>
191
+ </head>
192
+ <body>
193
+ <h1><?= $h($title) ?></h1>
194
+ <?php if ($desc !== ''): ?><p><?= $h($desc) ?></p>
195
+ <?php endif; ?><?php if ($body !== ''): ?><p><?= $h($body) ?></p>
196
+ <?php endif; ?><?php if ($image !== ''): ?><p><img src="<?= $h($image) ?>" alt="<?= $h($title) ?>"></p>
197
+ <?php endif; ?>
198
+ <nav><?php foreach ($links as $p): ?><a href="<?= $h($site . '/' . ltrim((string) $p, '/')) ?>"><?= $h(((array) $cfg['routes'][$p])['label'] ?? ($p === '' ? $name : ucwords(str_replace(['-', '_'], ' ', (string) $p)))) ?></a> <?php endforeach; ?></nav>
199
+ </body>
200
+ </html>
@@ -0,0 +1,3 @@
1
+ "use strict";const fs=require("fs");const path=require("path");const SKIP_VIEW=/^(_|404|index$|layout|header|footer|nav)|(\s|copy|_bu|_old|backup|\.bak|test)/i;function siteUrl(config,seo){const pick=[seo&&seo.site,config&&config.site,config&&config.domain,config&&config.project_info&&config.project_info.WebsiteURL];for(const v of pick){if(typeof v!=="string"||!v.trim())continue;const s=/^https?:\/\//i.test(v.trim())?v.trim():"https://"+v.trim();try{const u=new URL(s);if(/^[a-z0-9.-]+\.[a-z]{2,}$/i.test(u.hostname))return u.origin}catch(e){}}return""}function pageRoutes(projectPath){const dir=path.join(projectPath,"src","views");if(!fs.existsSync(dir))return[];const out=[];for(const f of fs.readdirSync(dir)){if(!f.endsWith(".view"))continue;const name=f.slice(0,-5);if(SKIP_VIEW.test(name)||!/^[a-z0-9][a-z0-9_-]*$/i.test(name))continue;out.push(name==="home"?"":name)}return[...new Set(out)].sort((a,b)=>a===""?-1:b===""?1:a.localeCompare(b))}function readJson(file){try{const j=JSON.parse(fs.readFileSync(file,"utf8"));return j&&typeof j==="object"?j:null}catch(e){return null}}const words=s=>String(s).replace(/[-_]+/g," ").replace(/\b\w/g,c=>c.toUpperCase());const xml=s=>String(s).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;");function writeSeoFiles(projectPath,dest,config){const src=f=>path.join(projectPath,"src",f);const own=readJson(src("seo.json"))||{};const info=config&&config.project_info||{};const site=siteUrl(config,own);const routes=pageRoutes(projectPath);const name=own.name||info.Title||(site?new URL(site).hostname:"");const done={site,robots:false,sitemap:false,seo:false,pages:routes.length};if(!fs.existsSync(src("robots.txt"))){fs.writeFileSync(path.join(dest,"robots.txt"),"User-agent: *\nAllow: /\n"+(site?`
2
+ Sitemap: ${site}/sitemap.xml
3
+ `:""));done.robots=true}if(!fs.existsSync(src("sitemap.xml"))){const target=path.join(dest,"sitemap.xml");const fixed=Object.keys(own.routes||{}).map(r=>r.replace(/^\/+|\/+$/g,"")).filter(r=>!r.includes(":"));const all=[...new Set([...routes,...fixed])];if(site){const day=new Date().toISOString().slice(0,10);fs.writeFileSync(target,'<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n'+all.map(r=>` <url><loc>${xml(site+"/"+r)}</loc><lastmod>${day}</lastmod></url>`).join("\n")+"\n</urlset>\n");done.sitemap=true}else if(fs.existsSync(target)){fs.unlinkSync(target)}}if(!fs.existsSync(src("seo.php"))){const defaults={};for(const r of routes){defaults[r]={title:r===""?info.Title||name:`${words(r)} | ${name}`}}const meta=info.MetaTags||{};const seo={site,name,title:own.title||info.Title||name,description:own.description||info.Description||"",image:own.image||meta["og:image"]||meta.image||"",lang:own.lang||"en",routes:Object.assign(defaults,own.routes||{})};fs.copyFileSync(path.join(__dirname,"files","seo","seo.php"),path.join(dest,"seo.php"));fs.writeFileSync(path.join(dest,"seo.json"),JSON.stringify(seo,null,2)+"\n");done.seo=true}return done}module.exports={writeSeoFiles,siteUrl,pageRoutes};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmjs/cli",
3
- "version": "2.7.0",
3
+ "version": "2.8.0",
4
4
  "description": "Command line interface for LumenJS — scaffold, develop, and build LumenJS applications. LumenJS is a tiny, fast reactive JavaScript framework for building web applications and interfaces with standard HTML, CSS, and JavaScript.",
5
5
  "bin": {
6
6
  "lm": "./dist/bin/commands.js",
@@ -52,7 +52,7 @@
52
52
  "ora": "^6.1.2",
53
53
  "semver": "^7.3.7",
54
54
  "ws": "^8.8.1",
55
- "@lmjs/core": "2.7.0"
55
+ "@lmjs/core": "2.8.0"
56
56
  },
57
57
  "engines": {
58
58
  "node": ">=18.0.0"