2034 lines
88 KiB
HTML
2034 lines
88 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="fa" dir="rtl">
|
||
<head>
|
||
<meta charset="UTF-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<title>راهنمای جامع ساخت xCLI برای xFramework</title>
|
||
<style>
|
||
:root{
|
||
--x-primary:#3880ff; --x-primary-shade:#3171e0; --x-primary-tint:#4c8dff;
|
||
--x-secondary:#0cd1e8; --x-tertiary:#7044ff; --x-success:#10dc60;
|
||
--x-warning:#ffce00; --x-danger:#f04141; --x-dark:#222428;
|
||
--x-medium:#989aa2; --x-light:#f4f5f8; --x-light-shade:#d7d8da;
|
||
--x-bg:#0f1115; --x-surface:#ffffff; --x-surface-2:#f7f8fb;
|
||
--x-text:#1d2129; --x-text-2:#4a5568; --x-border:#e2e8f0;
|
||
--shadow-sm:0 1px 2px rgba(15,17,21,.06), 0 1px 3px rgba(15,17,21,.08);
|
||
--shadow-md:0 4px 12px rgba(15,17,21,.08), 0 2px 4px rgba(15,17,21,.06);
|
||
--shadow-lg:0 20px 40px rgba(15,17,21,.12);
|
||
--radius-sm:8px; --radius-md:12px; --radius-lg:20px;
|
||
--code-bg:#0b1020; --code-fg:#e6edf3; --code-accent:#79c0ff;
|
||
--font-fa:Vazirmatn, "Segoe UI", Tahoma, sans-serif;
|
||
--font-mono:"JetBrains Mono","Fira Code",Consolas,"Courier New",monospace;
|
||
}
|
||
*{box-sizing:border-box}
|
||
html,body{margin:0;padding:0;background:var(--x-surface-2);color:var(--x-text);font-family:var(--font-fa);line-height:1.9;font-size:15px}
|
||
a{color:var(--x-primary);text-decoration:none}
|
||
a:hover{text-decoration:underline}
|
||
h1,h2,h3,h4,h5,h6{line-height:1.5;margin:0 0 .6em;color:var(--x-dark)}
|
||
h1{font-size:2.2rem}
|
||
h2{font-size:1.6rem;margin-top:2.2rem;padding-bottom:.4rem;border-bottom:3px solid var(--x-primary);display:inline-block}
|
||
h3{font-size:1.25rem;margin-top:1.6rem;color:var(--x-primary-shade)}
|
||
h4{font-size:1.05rem;color:var(--x-tertiary)}
|
||
p{margin:0 0 1em}
|
||
ul,ol{padding-right:1.4rem;margin:0 0 1.1em}
|
||
li{margin-bottom:.4em}
|
||
hr{border:none;border-top:1px solid var(--x-border);margin:2rem 0}
|
||
code{font-family:var(--font-mono);background:rgba(56,128,255,.10);padding:.1em .4em;border-radius:4px;font-size:.9em;color:var(--x-primary-shade);direction:ltr;display:inline-block}
|
||
pre{font-family:var(--font-mono);background:var(--code-bg);color:var(--code-fg);padding:1.1rem 1.3rem;border-radius:var(--radius-md);overflow-x:auto;direction:ltr;text-align:left;font-size:.85rem;line-height:1.7;box-shadow:var(--shadow-md);margin:1rem 0;border:1px solid rgba(255,255,255,.06)}
|
||
pre code{background:transparent;color:inherit;padding:0;font-size:inherit}
|
||
pre::-webkit-scrollbar{height:8px}
|
||
pre::-webkit-scrollbar-thumb{background:rgba(255,255,255,.2);border-radius:8px}
|
||
|
||
.container{max-width:1180px;margin:0 auto;padding:0 24px}
|
||
|
||
/* Cover */
|
||
.cover{position:relative;overflow:hidden;background:linear-gradient(135deg,#0b1020 0%,#1e2a5a 55%,#3880ff 100%);color:#fff;padding:100px 24px 80px}
|
||
.cover::before{content:"";position:absolute;inset:0;background:radial-gradient(circle at 20% 10%,rgba(121,192,255,.25),transparent 45%),radial-gradient(circle at 80% 90%,rgba(112,68,255,.25),transparent 40%);pointer-events:none}
|
||
.cover .badge{display:inline-block;background:rgba(255,255,255,.14);border:1px solid rgba(255,255,255,.25);padding:6px 16px;border-radius:999px;font-size:.85rem;letter-spacing:.5px;margin-bottom:20px;backdrop-filter:blur(6px)}
|
||
.cover h1{font-size:3rem;margin:0 0 18px;font-weight:800;line-height:1.3;letter-spacing:-.5px}
|
||
.cover h1 span{background:linear-gradient(90deg,#79c0ff,#c4b5fd);-webkit-background-clip:text;background-clip:text;color:transparent}
|
||
.cover .lead{font-size:1.15rem;max-width:820px;opacity:.92;margin:0 0 30px}
|
||
.cover .meta{display:flex;gap:14px;flex-wrap:wrap;font-size:.85rem;opacity:.85}
|
||
.cover .meta span{background:rgba(255,255,255,.10);padding:6px 14px;border-radius:999px;border:1px solid rgba(255,255,255,.15)}
|
||
|
||
/* Layout */
|
||
.layout{display:grid;grid-template-columns:280px 1fr;gap:32px;max-width:1180px;margin:32px auto;padding:0 24px}
|
||
@media(max-width:900px){.layout{grid-template-columns:1fr}.toc{position:relative !important;top:auto !important;max-height:none !important}}
|
||
|
||
/* TOC */
|
||
.toc{position:sticky;top:20px;align-self:start;background:var(--x-surface);border-radius:var(--radius-lg);padding:22px;box-shadow:var(--shadow-sm);max-height:calc(100vh - 40px);overflow:auto;border:1px solid var(--x-border)}
|
||
.toc h3{margin:0 0 14px;font-size:1rem;color:var(--x-primary-shade);display:flex;align-items:center;gap:8px;border:none}
|
||
.toc ol{list-style:none;padding:0;margin:0;counter-reset:toc}
|
||
.toc ol li{counter-increment:toc;margin:0;border-bottom:1px dashed var(--x-border)}
|
||
.toc ol li:last-child{border:none}
|
||
.toc ol li a{display:block;padding:8px 4px;color:var(--x-text-2);font-size:.88rem;transition:.2s}
|
||
.toc ol li a::before{content:counter(toc,decimal-leading-zero);display:inline-block;width:28px;color:var(--x-primary);font-weight:600;font-size:.78rem}
|
||
.toc ol li a:hover{color:var(--x-primary);background:rgba(56,128,255,.06);border-radius:6px;padding-right:8px;text-decoration:none}
|
||
|
||
/* Main */
|
||
main{background:var(--x-surface);border-radius:var(--radius-lg);padding:40px 44px;box-shadow:var(--shadow-sm);border:1px solid var(--x-border);min-width:0}
|
||
@media(max-width:640px){main{padding:24px 18px}}
|
||
section{margin-bottom:3rem;scroll-margin-top:24px}
|
||
|
||
/* Cards */
|
||
.cards{display:grid;grid-template-columns:repeat(auto-fit,minmax(240px,1fr));gap:16px;margin:1.4rem 0}
|
||
.card{padding:20px;border:1px solid var(--x-border);border-radius:var(--radius-md);background:linear-gradient(180deg,var(--x-surface),var(--x-surface-2));transition:.25s}
|
||
.card:hover{transform:translateY(-3px);box-shadow:var(--shadow-md);border-color:var(--x-primary-tint)}
|
||
.card .icon{width:44px;height:44px;border-radius:12px;display:flex;align-items:center;justify-content:center;font-size:1.5rem;margin-bottom:12px;background:linear-gradient(135deg,rgba(56,128,255,.18),rgba(112,68,255,.18));color:var(--x-primary-shade)}
|
||
.card h4{margin:0 0 6px;color:var(--x-dark)}
|
||
.card p{margin:0;color:var(--x-text-2);font-size:.9rem}
|
||
|
||
/* Notes */
|
||
.note{display:flex;gap:14px;padding:16px 18px;border-radius:var(--radius-md);margin:1rem 0;border-right:4px solid;font-size:.92rem}
|
||
.note .emoji{font-size:1.3rem;flex-shrink:0}
|
||
.note.info{background:rgba(56,128,255,.08);border-color:var(--x-primary)}
|
||
.note.success{background:rgba(16,220,96,.10);border-color:var(--x-success)}
|
||
.note.warning{background:rgba(255,206,0,.12);border-color:var(--x-warning)}
|
||
.note.danger{background:rgba(240,65,65,.10);border-color:var(--x-danger)}
|
||
.note strong{color:var(--x-dark)}
|
||
|
||
/* Table */
|
||
table{width:100%;border-collapse:collapse;margin:1rem 0;font-size:.9rem;box-shadow:var(--shadow-sm);border-radius:var(--radius-md);overflow:hidden}
|
||
thead{background:linear-gradient(90deg,var(--x-primary),var(--x-tertiary));color:#fff}
|
||
th,td{padding:11px 14px;text-align:right;border-bottom:1px solid var(--x-border)}
|
||
tbody tr:nth-child(even){background:var(--x-surface-2)}
|
||
tbody tr:hover{background:rgba(56,128,255,.05)}
|
||
td code{font-size:.82em}
|
||
|
||
/* Timeline / Steps */
|
||
.steps{position:relative;padding-right:34px;margin:1.5rem 0}
|
||
.steps::before{content:"";position:absolute;right:12px;top:0;bottom:0;width:3px;background:linear-gradient(to bottom,var(--x-primary),var(--x-tertiary),transparent);border-radius:3px}
|
||
.step{position:relative;margin-bottom:1.6rem}
|
||
.step::before{content:attr(data-step);position:absolute;right:-34px;top:0;width:28px;height:28px;border-radius:50%;background:var(--x-primary);color:#fff;display:flex;align-items:center;justify-content:center;font-size:.8rem;font-weight:700;box-shadow:0 0 0 4px var(--x-surface),0 0 0 6px rgba(56,128,255,.15)}
|
||
.step h4{margin:0 0 4px;color:var(--x-dark)}
|
||
.step p{margin:0;color:var(--x-text-2);font-size:.92rem}
|
||
|
||
/* File tree */
|
||
.tree{font-family:var(--font-mono);direction:ltr;text-align:left;background:var(--code-bg);color:#c9d1d9;padding:18px 22px;border-radius:var(--radius-md);font-size:.82rem;line-height:1.75;overflow-x:auto;border:1px solid rgba(255,255,255,.06)}
|
||
.tree .folder{color:#79c0ff;font-weight:700}
|
||
.tree .file{color:#c9d1d9}
|
||
.tree .comment{color:#6b7e9c;font-style:italic}
|
||
|
||
/* Pill */
|
||
.pills{display:flex;flex-wrap:wrap;gap:8px;margin:.6rem 0 1.2rem}
|
||
.pill{background:rgba(56,128,255,.1);color:var(--x-primary-shade);border:1px solid rgba(56,128,255,.2);padding:4px 12px;border-radius:999px;font-size:.8rem;font-family:var(--font-mono);direction:ltr}
|
||
.pill.tertiary{background:rgba(112,68,255,.1);color:var(--x-tertiary);border-color:rgba(112,68,255,.2)}
|
||
.pill.success{background:rgba(16,220,96,.1);color:#0aa14a;border-color:rgba(16,220,96,.25)}
|
||
|
||
/* Command block */
|
||
.cmd{position:relative;background:var(--code-bg);color:var(--code-fg);border-radius:var(--radius-md);padding:14px 18px;font-family:var(--font-mono);direction:ltr;text-align:left;font-size:.85rem;margin:.8rem 0;border:1px solid rgba(255,255,255,.06);box-shadow:var(--shadow-sm)}
|
||
.cmd::before{content:"$";color:#79c0ff;margin-right:10px;font-weight:700}
|
||
.cmd .c{color:#6b7e9c}
|
||
|
||
/* Footer */
|
||
footer{max-width:1180px;margin:0 auto 40px;padding:32px 24px;text-align:center;color:var(--x-text-2);font-size:.85rem;border-top:1px solid var(--x-border)}
|
||
|
||
/* Anchor headings */
|
||
section h2{position:relative}
|
||
section h2 .hash{margin-right:8px;color:var(--x-primary-tint);opacity:.4;font-size:.85em;font-family:var(--font-mono);text-decoration:none}
|
||
section h2:hover .hash{opacity:1}
|
||
|
||
/* Grid for examples */
|
||
.split{display:grid;grid-template-columns:1fr 1fr;gap:16px;margin:1rem 0}
|
||
@media(max-width:760px){.split{grid-template-columns:1fr}}
|
||
|
||
/* Badge */
|
||
.b{display:inline-block;padding:2px 8px;font-size:.72rem;border-radius:6px;font-weight:600;background:var(--x-primary);color:#fff;margin-left:6px;vertical-align:middle}
|
||
.b.warn{background:var(--x-warning);color:var(--x-dark)}
|
||
.b.success{background:var(--x-success)}
|
||
.b.danger{background:var(--x-danger)}
|
||
.b.tert{background:var(--x-tertiary)}
|
||
|
||
/* Print */
|
||
@media print{
|
||
body{background:#fff}
|
||
.layout{display:block}
|
||
.toc{display:none}
|
||
main{box-shadow:none;border:none;padding:0}
|
||
.cover{padding:60px 20px}
|
||
pre,.tree{background:#f5f5f5 !important;color:#111 !important;box-shadow:none;border:1px solid #ddd}
|
||
}
|
||
</style>
|
||
</head>
|
||
<body>
|
||
|
||
<!-- ===================== COVER ===================== -->
|
||
<header class="cover">
|
||
<div class="container">
|
||
<div class="badge">📘 مستندات فنی و عملیاتی | نسخه ۱.۰</div>
|
||
<h1>راهنمای جامع ساخت <span>xCLI</span><br/>ابزار تولید و مدیریت پروژههای <span>xFramework</span></h1>
|
||
<p class="lead">
|
||
مستندی گامبهگام برای طراحی و پیادهسازی ابزار خط فرمان (CLI) بهمنظور ساخت، تولید و مدیریت
|
||
برنامههای کاربردی مبتنی بر <code>xFramework</code> با الگوگیری کامل از پروژه مرجع <code>xClient</code>.
|
||
</p>
|
||
<div class="meta">
|
||
<span>🅰️ @angular/cli@12.0.4</span>
|
||
<span>⚡ @ionic/cli@6.6.0</span>
|
||
<span>🟢 Node v14.17.3</span>
|
||
<span>📦 xFramework Workspace</span>
|
||
</div>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="layout">
|
||
|
||
<!-- ===================== TOC ===================== -->
|
||
<aside class="toc">
|
||
<h3>📑 فهرست مطالب</h3>
|
||
<ol>
|
||
<li><a href="#intro">معرفی پروژه و ضرورت xCLI</a></li>
|
||
<li><a href="#prerequisites">پیشنیازها و محیط اجرا</a></li>
|
||
<li><a href="#arch">معماری پیشنهادی xCLI</a></li>
|
||
<li><a href="#struct">ساختار پروژه xClient (مرجع)</a></li>
|
||
<li><a href="#bootstrap">پیادهسازی گامبهگام xCLI</a></li>
|
||
<li><a href="#generators">تولیدکنندهها (Generators)</a></li>
|
||
<li><a href="#templates">سیستم قالبها (Templates)</a></li>
|
||
<li><a href="#config">مدیریت پیکربندی و Environments</a></li>
|
||
<li><a href="#plugins">مدیریت افزونهها (Cordova Plugins)</a></li>
|
||
<li><a href="#build">فرآیند ساخت، تست و انتشار</a></li>
|
||
<li><a href="#examples">مثالهای عملی و سناریوها</a></li>
|
||
<li><a href="#appendix">پیوست: جدول کامل دستورات</a></li>
|
||
</ol>
|
||
</aside>
|
||
|
||
<!-- ===================== MAIN ===================== -->
|
||
<main>
|
||
|
||
<!-- =============== 1. INTRO =============== -->
|
||
<section id="intro">
|
||
<h2><a class="hash" href="#intro">#</a>1. معرفی پروژه و ضرورت xCLI</h2>
|
||
|
||
<h3>1.1. xFramework چیست؟</h3>
|
||
<p>
|
||
<code>xFramework</code> مجموعهای از کتابخانههای ماژولار انگولار است که برای ساخت اپلیکیشنهای
|
||
سازمانی (Enterprise) روی پشتهی <strong>Angular + Ionic + Capacitor/Cordova</strong> توسعه یافته است.
|
||
این چارچوب در قالب چند بسته (Package) مستقل ارائه میشود که هر کدام یک لایه از نیازهای نرمافزاری را پوشش میدهند:
|
||
</p>
|
||
|
||
<div class="cards">
|
||
<div class="card">
|
||
<div class="icon">🧩</div>
|
||
<h4>x-framework-core</h4>
|
||
<p>لایه پایه شامل Utilityها، Enumهای سراسری، Type Guardها، ساختار Exceptionها و ابزارهای عمومی.</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">🛠️</div>
|
||
<h4>x-framework-services</h4>
|
||
<p>سرویسهای سراسری مثل XManagerService، TaskManager، SecureStorage، Localization و ThemeManager.</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">🎨</div>
|
||
<h4>x-framework-components</h4>
|
||
<p>مجموعهی بزرگی از کامپوننتهای UI: XCard، XForm، XList، XTabs، XChart، XDataPager، XIDE و...</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">🔐</div>
|
||
<h4>x-framework-identity-sdk</h4>
|
||
<p>SDK احراز هویت، مدیریت توکن، Guardها (AuthGuard)، پروفایل کاربر و سرویسهای حساب کاربری.</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">🚀</div>
|
||
<h4>x-framework-push-service</h4>
|
||
<p>مدیریت SignalR Push، سوکتهای بلادرنگ، WebRTC و زیرساخت ارتباطی پیامرسانی.</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">🗂️</div>
|
||
<h4>xApiSDKHolder</h4>
|
||
<p>تولید SDK از API (بهصورت دستی یا Codegen) برای موجودیتهای دامنه مثل Tags، Files، Webinars و Strings.</p>
|
||
</div>
|
||
</div>
|
||
|
||
<h3>1.2. پروژه xClient چه میکند؟</h3>
|
||
<p>
|
||
<code>xClient</code> در واقع یک اپلیکیشن مرجع (Reference Application) است که تمام قابلیتهای xFramework
|
||
را در قالب یک محصول واقعی (سامانهی آموزشی/محتوایی «ساحر علم») پیادهسازی میکند. مهمترین لایههای این پروژه:
|
||
</p>
|
||
<ul>
|
||
<li><strong>Workspace چند ماژولی:</strong> پوشهی <code>Modules/</code> شامل <code>xApiSDKHolder</code>، <code>xFrameworkComponentsHolder</code> و دیگر Holderهاست که بهصورت کتابخانههای قابل انتشار نگهداری میشوند.</li>
|
||
<li><strong>پروژه اصلی کلاینت:</strong> در پوشهی <code>xClient/</code> که خود از ساختار استاندارد Angular CLI + Ionic استفاده میکند.</li>
|
||
<li><strong>لایه View:</strong> پوشهی <code>src/app/views</code> مجموعهای از <code>V*</code> کامپوننتها (VPage، VDto، VFile، VTag، VWebinar و ...) که به کامپوننتهای xFramework وصل میشوند.</li>
|
||
<li><strong>لایه Page:</strong> پوشهی <code>src/app/pages</code> شامل صفحات با ساختار مشترک (Home، Landing، Files، Tags، Webinars، Account و ...).</li>
|
||
<li><strong>پیکربندی متمرکز:</strong> <code>src/app/config/app.config.ts</code> و <code>x.config.ts</code> بهعنوان Single Source of Truth برای کل تنظیمات.</li>
|
||
<li><strong>Environmentها:</strong> <code>src/environments</code> با دو فایل <code>environment.ts</code> و <code>environment.prod.ts</code>.</li>
|
||
<li><strong>Pluginهای Cordova:</strong> در پوشهی <code>plugins/</code> با type definitionهای TypeScript برای Device، Splashscreen و StatusBar.</li>
|
||
</ul>
|
||
|
||
<h3>1.3. چرا به xCLI نیاز داریم؟</h3>
|
||
<p>
|
||
هر بار که میخواهیم یک پروژهی جدید بر پایهی xFramework بسازیم، باید دهها فایل پیکربندی، چندین ماژول، ساختار View/Page،
|
||
Environment، Theme و Plugin را بهصورت دستی ایجاد کنیم. این کار:
|
||
</p>
|
||
<ul>
|
||
<li>زمانبر و مستعد خطا است.</li>
|
||
<li>باعث ناسازگاری بین پروژهها میشود (عدم رعایت Convention).</li>
|
||
<li>بهروزرسانی نسخهی فریمورک را در چندین پروژه دشوار میکند.</li>
|
||
<li>امکان ارائهی «تجربهی توسعهدهنده» یکپارچه و مستند را نمیدهد.</li>
|
||
</ul>
|
||
|
||
<div class="note info">
|
||
<div class="emoji">💡</div>
|
||
<div>
|
||
<strong>هدف xCLI:</strong> با یک دستور مثل <code>xcli new my-app</code>، پروژهای کاملاً آماده با همان ساختار xClient تولید شود؛
|
||
و با دستوراتی مانند <code>xcli g page</code> یا <code>xcli g view</code> بتوان اجزای جدید را به شکل استاندارد اضافه کرد.
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- =============== 2. PREREQUISITES =============== -->
|
||
<section id="prerequisites">
|
||
<h2><a class="hash" href="#prerequisites">#</a>2. پیشنیازها و محیط اجرا</h2>
|
||
|
||
<p>
|
||
با توجه به محدودیتهای اعلامشده، کل فرآیند باید بر روی نسخههای زیر پایدار بماند. این نسخهها «قفلشده» در نظر گرفته میشوند
|
||
و xCLI باید <strong>در همان بازه</strong> کار کند.
|
||
</p>
|
||
|
||
<table>
|
||
<thead>
|
||
<tr><th>ابزار</th><th>نسخه</th><th>نقش</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td>Node.js</td><td><code>v14.17.3</code></td><td>Runtime اصلی CLI و Angular</td></tr>
|
||
<tr><td>npm</td><td>همراه با Node 14 → <code>6.x</code></td><td>مدیریت پکیجها</td></tr>
|
||
<tr><td>@angular/cli</td><td><code>12.0.4</code></td><td>اسکلتبندی و Build</td></tr>
|
||
<tr><td>@ionic/cli</td><td><code>6.6.0</code></td><td>مدیریت پروژههای Ionic و Cordova</td></tr>
|
||
<tr><td>TypeScript</td><td><code>~4.2.x</code></td><td>همراه Angular 12</td></tr>
|
||
<tr><td>RxJS</td><td><code>~6.6.x</code></td><td>همراه Angular 12</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<h3>2.1. نصب ابزارها</h3>
|
||
<pre><code># نصب نسخههای دقیق و قفلشده (توصیه میشود)
|
||
npm i -g @angular/cli@12.0.4
|
||
npm i -g @ionic/cli@6.6.0
|
||
|
||
# بررسی نسخهها
|
||
node -v # v14.17.3
|
||
ng version # Angular CLI: 12.0.4
|
||
ionic -v # 6.6.0</code></pre>
|
||
|
||
<div class="note warning">
|
||
<div class="emoji">⚠️</div>
|
||
<div>
|
||
<strong>توجه:</strong> Angular 12 بر روی Node 14 و 16 تست شده است. استفاده از Node 18+ باعث خطاهای
|
||
<code>ERR_OSSL_EVP_UNSUPPORTED</code> در Webpack 5 میشود. بنابراین پیشنهاد میشود از <code>nvm</code> یا <code>nvs</code>
|
||
برای مدیریت نسخهی Node استفاده شود.
|
||
</div>
|
||
</div>
|
||
|
||
<h3>2.2. ساختار پوشهی توسعه</h3>
|
||
<p>ساختار پیشنهادی برای مخزن توسعهی xCLI به شکل زیر است:</p>
|
||
|
||
<pre><code>xFrameworkWorkspace/
|
||
├── xCli/ # ← پروژهی CLI (محل ساخت ابزار)
|
||
│ ├── package.json
|
||
│ ├── src/
|
||
│ │ ├── index.ts # نقطهی ورود CLI
|
||
│ │ ├── commands/ # دستورات
|
||
│ │ ├── generators/ # تولیدکنندهها
|
||
│ │ ├── templates/ # قالبها
|
||
│ │ ├── lib/ # ابزارهای مشترک
|
||
│ │ └── config/ # پیکربندی CLI
|
||
│ └── bin/
|
||
│ └── xcli.js # شیم اجرایی (Shebang)
|
||
│
|
||
├── xClient/ # ← پروژهی مرجع
|
||
│ ├── plugins/
|
||
│ ├── src/
|
||
│ │ ├── app/
|
||
│ │ ├── environments/
|
||
│ │ ├── theme/
|
||
│ │ └── ...
|
||
│ └── ...
|
||
│
|
||
└── Modules/ # ← Holderهای کتابخانهای
|
||
├── xApiSDKHolder/
|
||
└── xFrameworkComponentsHolder/</code></pre>
|
||
</section>
|
||
|
||
<!-- =============== 3. ARCH =============== -->
|
||
<section id="arch">
|
||
<h2><a class="hash" href="#arch">#</a>3. معماری پیشنهادی xCLI</h2>
|
||
|
||
<p>
|
||
xCLI باید از الگوی <em>Command + Generator + Template</em> پیروی کند. این معماری مشابه Angular CLI، Nest CLI،
|
||
یا Nx است، ولی سبکتر و متناسب با نیاز xFramework.
|
||
</p>
|
||
|
||
<div class="cards">
|
||
<div class="card">
|
||
<div class="icon">⌨️</div>
|
||
<h4>لایه Commands</h4>
|
||
<p>پارس دستورات ورودی، مدیریت Flagها، نمایش Help و اجرای Generator مناسب.</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">⚙️</div>
|
||
<h4>لایه Generators</h4>
|
||
<p>منطق تولید کد: ساخت فایل، جایگزینی Placeholder، Merge با فایلهای موجود.</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">📁</div>
|
||
<h4>لایه Templates</h4>
|
||
<p>قالبهای متنی با Placeholderهایی مانند <code>__NAME__</code>، <code>__CLASS__</code>، <code>__PATH__</code>.</p>
|
||
</div>
|
||
<div class="card">
|
||
<div class="icon">🧠</div>
|
||
<h4>لایه Schematics</h4>
|
||
<p>اختیاری: استفاده از Schematics برای اجرای دقیقتر تغییرات روی AST فایلهای TypeScript.</p>
|
||
</div>
|
||
</div>
|
||
|
||
<h3>3.1. جریان اجرا</h3>
|
||
<div class="steps">
|
||
<div class="step" data-step="1">
|
||
<h4>ورود کاربر</h4>
|
||
<p><code>xcli g page --name=files --module=files</code> در ترمینال وارد میشود.</p>
|
||
</div>
|
||
<div class="step" data-step="2">
|
||
<h4>پارس دستور</h4>
|
||
<p>لایه Commands با <code>commander</code> یا <code>yargs</code> دستور و Flagها را تجزیه میکند.</p>
|
||
</div>
|
||
<div class="step" data-step="3">
|
||
<h4>اعتبارسنجی</h4>
|
||
<p>بررسی وجود پروژه، نام معتبر، عدم تکرار، تطابق با Convention.</p>
|
||
</div>
|
||
<div class="step" data-step="4">
|
||
<h4>اجرای Generator</h4>
|
||
<p>Generator با استفاده از Template مناسب و جایگزینی Placeholderها، فایلها را ایجاد میکند.</p>
|
||
</div>
|
||
<div class="step" data-step="5">
|
||
<h4>Merge و ثبت</h4>
|
||
<p>ثبت فایلهای جدید در <code>app-routing.module.ts</code>، <code>page.config.ts</code> یا <code>app.config.ts</code>.</p>
|
||
</div>
|
||
<div class="step" data-step="6">
|
||
<h4>گزارش</h4>
|
||
<p>نمایش فایلهای ایجاد/تغییردادهشده و دستور بعدی برای اجرا.</p>
|
||
</div>
|
||
</div>
|
||
|
||
<h3>3.2. وابستگیهای xCLI</h3>
|
||
<table>
|
||
<thead><tr><th>پکیج</th><th>هدف</th></tr></thead>
|
||
<tbody>
|
||
<tr><td><code>commander</code></td><td>پارس زیردستور و Flagها</td></tr>
|
||
<tr><td><code>inquirer</code></td><td>پرسش تعاملی از کاربر (Interactive prompt)</td></tr>
|
||
<tr><td><code>chalk</code></td><td>رنگدهی به خروجی ترمینال</td></tr>
|
||
<tr><td><code>ora</code></td><td>نمایش Spinner حین اجرا</td></tr>
|
||
<tr><td><code>fs-extra</code></td><td>عملیات فایل (copy، ensureDir، writeJson)</td></tr>
|
||
<tr><td><code>handlebars</code></td><td>رندر قالبهای متنی</td></tr>
|
||
<tr><td><code>execa</code></td><td>اجرای دستورات Shell (npm, ng, ionic)</td></tr>
|
||
<tr><td><code>ts-morph</code> <em>(اختیاری)</em></td><td>ویرایش AST فایلهای TypeScript</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<div class="note info">
|
||
<div class="emoji">📌</div>
|
||
<div>
|
||
برای شروع سبک، فقط از <code>commander</code>، <code>inquirer</code>، <code>chalk</code>، <code>ora</code>،
|
||
<code>fs-extra</code> و <code>handlebars</code> استفاده کنید. تغییرات AST را به کمک <code>ts-morph</code> در فاز دوم اضافه نمایید.
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- =============== 4. PROJECT STRUCTURE =============== -->
|
||
<section id="struct">
|
||
<h2><a class="hash" href="#struct">#</a>4. ساختار پروژه xClient (مرجع)</h2>
|
||
|
||
<p>
|
||
برای اینکه xCLI بتواند پروژهی همسان xClient تولید کند، باید ساختار آن را دقیقاً بشناسیم. در ادامه، شاخههای مهم با
|
||
توضیح جایگاه و نقش آورده شدهاند.
|
||
</p>
|
||
|
||
<h3>4.1. نمای کلی</h3>
|
||
<div class="tree">
|
||
<span class="folder">xClient/</span>
|
||
├── <span class="folder">plugins/</span>
|
||
│ ├── <span class="folder">cordova-plugin-device/</span>
|
||
│ │ └── <span class="folder">types/</span><span class="file">index.d.ts</span> <span class="comment"># interface Device</span>
|
||
│ ├── <span class="folder">cordova-plugin-splashscreen/</span>
|
||
│ │ ├── <span class="folder">src/wp/</span>
|
||
│ │ │ ├── <span class="file">SplashScreen.cs</span>
|
||
│ │ │ └── <span class="file">ResolutionHelper.cs</span>
|
||
│ │ └── <span class="folder">types/</span><span class="file">index.d.ts</span>
|
||
│ └── <span class="folder">cordova-plugin-statusbar/</span>
|
||
│ ├── <span class="folder">src/wp/</span><span class="file">StatusBar.cs</span>
|
||
│ └── <span class="folder">types/</span><span class="file">index.d.ts</span>
|
||
│
|
||
├── <span class="folder">src/</span>
|
||
│ ├── <span class="file">index.html</span>
|
||
│ ├── <span class="file">main.ts</span>
|
||
│ ├── <span class="file">polyfills.ts</span>
|
||
│ ├── <span class="file">typings.d.ts</span>
|
||
│ ├── <span class="file">global.d.ts</span>
|
||
│ │
|
||
│ ├── <span class="folder">environments/</span>
|
||
│ │ ├── <span class="file">environment.ts</span>
|
||
│ │ └── <span class="file">environment.prod.ts</span>
|
||
│ │
|
||
│ ├── <span class="folder">theme/</span>
|
||
│ │ └── <span class="file">theme.scss</span> <span class="comment"># Design Tokens + Ionic + XFramework</span>
|
||
│ │
|
||
│ └── <span class="folder">app/</span>
|
||
│ ├── <span class="folder">config/</span>
|
||
│ │ ├── <span class="file">app.config.ts</span> <span class="comment"># xSharedConfig، XCONFIG</span>
|
||
│ │ ├── <span class="file">x.config.ts</span> <span class="comment"># InjectionToken</span>
|
||
│ │ ├── <span class="file">x-api.config.ts</span> <span class="comment"># XApiConfiguration</span>
|
||
│ │ ├── <span class="file">localization.config.ts</span> <span class="comment"># AppResourceIDs</span>
|
||
│ │ ├── <span class="file">page.config.ts</span> <span class="comment"># PageIndex، Pages، NavItems</span>
|
||
│ │ └── <span class="file">audio.config.ts</span>
|
||
│ │
|
||
│ ├── <span class="folder">pages/</span>
|
||
│ │ ├── <span class="folder">home/</span>
|
||
│ │ ├── <span class="folder">landing/</span>
|
||
│ │ ├── <span class="folder">startup/</span>
|
||
│ │ ├── <span class="folder">account/</span>
|
||
│ │ ├── <span class="folder">files/</span>
|
||
│ │ ├── <span class="folder">tags/</span>
|
||
│ │ ├── <span class="folder">webinars/</span>
|
||
│ │ ├── <span class="folder">error/</span>
|
||
│ │ └── <span class="folder">not-authorized/</span>
|
||
│ │
|
||
│ ├── <span class="folder">views/</span>
|
||
│ │ ├── <span class="folder">v-page/</span>
|
||
│ │ ├── <span class="folder">v-page-presenter/</span>
|
||
│ │ ├── <span class="folder">v-dto/</span>
|
||
│ │ ├── <span class="folder">v-query-presenter/</span>
|
||
│ │ ├── <span class="folder">v-paginator/</span>
|
||
│ │ ├── <span class="folder">v-file/</span>
|
||
│ │ ├── <span class="folder">v-media/</span>
|
||
│ │ ├── <span class="folder">v-tag/</span>
|
||
│ │ ├── <span class="folder">v-tags-presenter/</span>
|
||
│ │ ├── <span class="folder">v-files-presenter/</span>
|
||
│ │ ├── <span class="folder">v-webinar/</span>
|
||
│ │ ├── <span class="folder">v-webinar-view/</span>
|
||
│ │ ├── <span class="folder">v-webinar-connect/</span>
|
||
│ │ ├── <span class="folder">v-person/</span>
|
||
│ │ ├── <span class="folder">v-user/</span>
|
||
│ │ ├── <span class="folder">v-friendship/</span>
|
||
│ │ ├── <span class="folder">v-login/</span>
|
||
│ │ ├── <span class="folder">v-register/</span>
|
||
│ │ ├── <span class="folder">v-profile/</span>
|
||
│ │ ├── <span class="folder">v-avatar/</span>
|
||
│ │ ├── <span class="folder">v-video/</span>
|
||
│ │ ├── <span class="folder">v-error/</span>
|
||
│ │ ├── <span class="folder">v-lazy-view/</span>
|
||
│ │ ├── <span class="folder">v-string/</span>
|
||
│ │ ├── <span class="folder">v-resource/</span>
|
||
│ │ ├── <span class="folder">v-locale/</span>
|
||
│ │ ├── <span class="folder">v-reference/</span>
|
||
│ │ ├── <span class="folder">v-tag-input/</span>
|
||
│ │ ├── <span class="folder">v-file-input/</span>
|
||
│ │ ├── <span class="folder">v-icons-presenter/</span>
|
||
│ │ ├── <span class="folder">classes/</span>
|
||
│ │ │ └── <span class="file">v-base.component.ts</span> <span class="comment"># VBaseComponent</span>
|
||
│ │ ├── <span class="folder">constants/</span>
|
||
│ │ │ ├── <span class="file">fab.defaults.ts</span>
|
||
│ │ │ ├── <span class="file">button.defaults.ts</span>
|
||
│ │ │ ├── <span class="file">slide.options.defaults.ts</span>
|
||
│ │ │ └── <span class="file">actionbar.defaults.ts</span>
|
||
│ │ ├── <span class="folder">directives/</span>
|
||
│ │ ├── <span class="folder">typings/</span>
|
||
│ │ ├── <span class="folder">tools/</span>
|
||
│ │ └── <span class="file">views.module.ts</span>
|
||
│ │
|
||
│ ├── <span class="folder">shared/</span>
|
||
│ │ ├── <span class="folder">services/</span>
|
||
│ │ │ ├── <span class="file">shared.service.ts</span> <span class="comment"># SharedService</span>
|
||
│ │ │ ├── <span class="file">x-electron.service.ts</span>
|
||
│ │ │ ├── <span class="file">x-media-devices.service.ts</span>
|
||
│ │ │ ├── <span class="file">x-scrolling-provider.service.ts</span>
|
||
│ │ │ └── <span class="file">x-content-share-service.ts</span>
|
||
│ │ ├── <span class="folder">typings/</span>
|
||
│ │ ├── <span class="file">shared.module.ts</span>
|
||
│ │ └── <span class="file">public-api.ts</span>
|
||
│ │
|
||
│ ├── <span class="file">app-routing.module.ts</span>
|
||
│ ├── <span class="file">app.component.ts</span>
|
||
│ ├── <span class="file">app.component.html</span>
|
||
│ ├── <span class="file">app.component.scss</span>
|
||
│ └── <span class="file">app.module.ts</span>
|
||
│
|
||
└── <span class="file">angular.json</span> / <span class="file">package.json</span> / <span class="file">tsconfig.json</span>
|
||
</div>
|
||
|
||
<h3>4.2. نکات کلیدی ساختاری</h3>
|
||
<ul>
|
||
<li>
|
||
<strong>الگوی Base Component در Views:</strong> تمام کامپوننتهای View از <code>VBaseComponent</code> یا
|
||
<code>VBaseDtoComponent</code> ارث میبرند. این باعث یکپارچگی مدیریت Task، Error و Loading میشود.
|
||
</li>
|
||
<li>
|
||
<strong>الگوی Page / Provider:</strong> صفحات پیچیده (مثل Files، Tags، Webinars) از یک <em>BaseProviderPage</em>
|
||
استفاده میکنند که منطق Query، Add، Update، Delete و Push را از پیش پیادهسازی کرده است.
|
||
</li>
|
||
<li>
|
||
<strong>الگوی Dto:</strong> کامپوننت <code>v-dto</code> بهعنوان Presenter عمومی برای هر Dto عمل میکند
|
||
و با <code>VModelFieldDescriptor</code>ها فیلدها را رندر میکند.
|
||
</li>
|
||
<li>
|
||
<strong>مرکز پیکربندی:</strong> تمام تنظیمات در <code>environment.configurations</code> جمع شده و از طریق
|
||
<code>XCONFIG</code> (که از <code>app.config.ts</code> میآید) در سراسر برنامه در دسترس است.
|
||
</li>
|
||
<li>
|
||
<strong>پوشهی Plugins:</strong> تعریفهای TypeScript پلاگینهای Cordova برای Device، Splashscreen و StatusBar
|
||
بهصورت محلی در پروژه نگهداری میشود تا از پکیجهای <code>@types</code> مستقل باشد.
|
||
</li>
|
||
</ul>
|
||
</section>
|
||
|
||
<!-- =============== 5. BOOTSTRAP =============== -->
|
||
<section id="bootstrap">
|
||
<h2><a class="hash" href="#bootstrap">#</a>5. پیادهسازی گامبهگام xCLI</h2>
|
||
|
||
<p>در این بخش، از صفر تا صد ابزار xCLI ساخته میشود. هر گام با دستور، فایل و قطعهکد همراه است.</p>
|
||
|
||
<h3>گام ۱: ساخت پوشه و مقداردهی اولیه</h3>
|
||
<pre><code>mkdir xCli && cd xCli
|
||
npm init -y
|
||
npm i commander@9 inquirer@8 chalk@4 ora@5 fs-extra@10 handlebars@4 execa@5
|
||
npm i -D typescript@4.2 @types/node@14 @types/fs-extra@9 @types/inquirer@7</code></pre>
|
||
|
||
<div class="note info">
|
||
<div class="emoji">🎯</div>
|
||
<div>
|
||
<strong>چرا این نسخهها؟</strong> <code>commander@9</code>، <code>inquirer@8</code>، <code>chalk@4</code> و <code>ora@5</code>
|
||
با Node 14 سازگارند. نسخههای جدیدتر (مثلاً <code>inquirer@9</code> یا <code>chalk@5</code>) به ESM منتقل شدهاند و
|
||
با CommonJS پروژههای Angular 12 تضاد ایجاد میکنند.
|
||
</div>
|
||
</div>
|
||
|
||
<h3>گام ۲: تنظیم package.json و tsconfig</h3>
|
||
<pre><code>{
|
||
"name": "@xframework/xcli",
|
||
"version": "1.0.0",
|
||
"description": "CLI for generating and managing xFramework applications",
|
||
"main": "dist/index.js",
|
||
"bin": {
|
||
"xcli": "bin/xcli.js"
|
||
},
|
||
"scripts": {
|
||
"build": "tsc -p tsconfig.json",
|
||
"dev": "ts-node src/index.ts",
|
||
"link": "npm run build && npm link"
|
||
},
|
||
"files": [
|
||
"bin",
|
||
"dist",
|
||
"templates"
|
||
],
|
||
"engines": {
|
||
"node": ">=14.17.3 <17"
|
||
}
|
||
}</code></pre>
|
||
|
||
<pre><code>{
|
||
"compilerOptions": {
|
||
"target": "ES2019",
|
||
"module": "CommonJS",
|
||
"moduleResolution": "node",
|
||
"outDir": "dist",
|
||
"rootDir": "src",
|
||
"strict": true,
|
||
"esModuleInterop": true,
|
||
"skipLibCheck": true,
|
||
"resolveJsonModule": true,
|
||
"declaration": true,
|
||
"sourceMap": true
|
||
},
|
||
"include": ["src/**/*.ts"]
|
||
}</code></pre>
|
||
|
||
<h3>گام ۳: Shم اجرایی (bin)</h3>
|
||
<p>فایل <code>bin/xcli.js</code> در واقع یک Loader است که نسخهی کامپایلشده را اجرا میکند:</p>
|
||
<pre><code>#!/usr/bin/env node
|
||
// bin/xcli.js
|
||
require('../dist/index.js');</code></pre>
|
||
|
||
<div class="note warning">
|
||
<div class="emoji">🔐</div>
|
||
<div>
|
||
روی Linux/macOS اجرای <code>chmod +x bin/xcli.js</code> لازم است. npm هنگام <code>npm link</code> این کار را خودکار انجام میدهد.
|
||
</div>
|
||
</div>
|
||
|
||
<h3>گام ۴: نقطهی ورود CLI</h3>
|
||
<p>فایل <code>src/index.ts</code> با <code>commander</code> ساخته میشود:</p>
|
||
<pre><code>// src/index.ts
|
||
import { Command } from 'commander';
|
||
import { registerNewCommand } from './commands/new';
|
||
import { registerGenerateCommand } from './commands/generate';
|
||
import { registerAddCommand } from './commands/add';
|
||
import { registerConfigCommand } from './commands/config';
|
||
import { registerBuildCommand } from './commands/build';
|
||
import { registerDoctorCommand } from './commands/doctor';
|
||
import chalk from 'chalk';
|
||
import { readFileSync } from 'fs';
|
||
import { join } from 'path';
|
||
|
||
const pkg = JSON.parse(
|
||
readFileSync(join(__dirname, '..', 'package.json'), 'utf-8')
|
||
);
|
||
|
||
const program = new Command();
|
||
|
||
program
|
||
.name('xcli')
|
||
.description('CLI for xFramework application scaffolding & management')
|
||
.version(pkg.version, '-v, --version', 'output the current version');
|
||
|
||
// ثبت زیردستورات
|
||
registerNewCommand(program);
|
||
registerGenerateCommand(program);
|
||
registerAddCommand(program);
|
||
registerConfigCommand(program);
|
||
registerBuildCommand(program);
|
||
registerDoctorCommand(program);
|
||
|
||
// دستور پیشفرض
|
||
program
|
||
.command('help [command]')
|
||
.description('display help for xcli or a specific command')
|
||
.action((cmd) => {
|
||
if (cmd) {
|
||
const sub = program.commands.find((c) => c.name() === cmd);
|
||
if (sub) {
|
||
sub.help();
|
||
} else {
|
||
console.log(chalk.red(`Unknown command: ${cmd}`));
|
||
process.exit(1);
|
||
}
|
||
} else {
|
||
program.help();
|
||
}
|
||
});
|
||
|
||
// مدیریت خطاها
|
||
process.on('unhandledRejection', (err: any) => {
|
||
console.error(chalk.red('\n💥 Unexpected error:'), err?.message || err);
|
||
process.exit(1);
|
||
});
|
||
|
||
// پارس آرگومانها
|
||
program.parseAsync(process.argv).catch((err) => {
|
||
console.error(chalk.red(err.message));
|
||
process.exit(1);
|
||
});</code></pre>
|
||
|
||
<h3>گام ۵: کتابخانهی ابزارهای مشترک</h3>
|
||
<p>یک فایل <code>src/lib/logger.ts</code> برای رنگدهی یکنواخت:</p>
|
||
<pre><code>// src/lib/logger.ts
|
||
import chalk from 'chalk';
|
||
|
||
export const logger = {
|
||
info: (msg: string) => console.log(chalk.cyan('ℹ '), msg),
|
||
success: (msg: string) => console.log(chalk.green('✔ '), msg),
|
||
warn: (msg: string) => console.log(chalk.yellow('⚠ '), msg),
|
||
error: (msg: string) => console.log(chalk.red('✖ '), msg),
|
||
title: (msg: string) =>
|
||
console.log('\n' + chalk.bold.blue(`◆ ${msg}`) + '\n'),
|
||
file: (path: string) => console.log(chalk.gray(' CREATE'), chalk.white(path)),
|
||
update: (path: string) =>
|
||
console.log(chalk.gray(' UPDATE'), chalk.yellow(path)),
|
||
};</code></pre>
|
||
|
||
<p>فایل <code>src/lib/fs-utils.ts</code> برای مدیریت فایلها:</p>
|
||
<pre><code>// src/lib/fs-utils.ts
|
||
import * as fs from 'fs-extra';
|
||
import { join, dirname } from 'path';
|
||
import Handlebars from 'handlebars';
|
||
|
||
export async function renderTemplate(
|
||
templateSource: string,
|
||
data: Record<string, any>
|
||
): Promise<string> {
|
||
const template = Handlebars.compile(templateSource, { noEscape: true });
|
||
return template(data);
|
||
}
|
||
|
||
export async function writeRendered(
|
||
targetPath: string,
|
||
content: string,
|
||
overwrite = false
|
||
) {
|
||
if (!overwrite && (await fs.pathExists(targetPath))) {
|
||
throw new Error(`File already exists: ${targetPath}`);
|
||
}
|
||
await fs.ensureDir(dirname(targetPath));
|
||
await fs.writeFile(targetPath, content, 'utf-8');
|
||
}
|
||
|
||
export async function copyTemplate(
|
||
templatesRoot: string,
|
||
relativePath: string,
|
||
targetPath: string,
|
||
data: Record<string, any>,
|
||
extensionsToRender = ['.ts', '.html', '.scss', '.json', '.md', '.xml', '.js']
|
||
) {
|
||
const source = await fs.readFile(join(templatesRoot, relativePath), 'utf-8');
|
||
const ext = '.' + relativePath.split('.').pop();
|
||
const content = extensionsToRender.includes(ext)
|
||
? await renderTemplate(source, data)
|
||
: source;
|
||
await writeRendered(targetPath, content);
|
||
}</code></pre>
|
||
|
||
<h3>گام ۶: دستور <code>xcli new</code></h3>
|
||
<p>این دستور پروژهی جدید xFramework را از صفر ایجاد میکند.</p>
|
||
|
||
<div class="split">
|
||
<div>
|
||
<h4>الف) تعریف دستور</h4>
|
||
<pre><code>// src/commands/new.ts
|
||
import { Command } from 'commander';
|
||
import inquirer from 'inquirer';
|
||
import ora from 'ora';
|
||
import { generateNewProject } from '../generators/new-project';
|
||
import { logger } from '../lib/logger';
|
||
|
||
export function registerNewCommand(program: Command) {
|
||
program
|
||
.command('new [name]')
|
||
.description('Create a new xFramework application')
|
||
.option('-d, --directory <path>', 'Target directory')
|
||
.option('--skip-install', 'Skip npm install')
|
||
.option('--template <type>', 'Project template', 'default')
|
||
.action(async (name, options) => {
|
||
logger.title('Creating xFramework project');
|
||
|
||
// پرسش تعاملی اگر نام داده نشده باشد
|
||
if (!name) {
|
||
const ans = await inquirer.prompt([
|
||
{
|
||
type: 'input',
|
||
name: 'name',
|
||
message: 'Project name:',
|
||
default: 'my-x-app',
|
||
validate: (v) =>
|
||
/^[a-z][a-z0-9-]*$/.test(v) ||
|
||
'lowercase letters, numbers, dash only',
|
||
},
|
||
]);
|
||
name = ans.name;
|
||
}
|
||
|
||
const spinner = ora('Scaffolding project...').start();
|
||
try {
|
||
await generateNewProject({
|
||
name,
|
||
directory: options.directory || `./${name}`,
|
||
template: options.template,
|
||
skipInstall: options.skipInstall,
|
||
onProgress: (msg) => (spinner.text = msg),
|
||
});
|
||
spinner.succeed('Project created successfully');
|
||
logger.info(`cd ${name}`);
|
||
logger.info('npm run start:dev');
|
||
} catch (err: any) {
|
||
spinner.fail(err.message);
|
||
process.exit(1);
|
||
}
|
||
});
|
||
}</code></pre>
|
||
</div>
|
||
<div>
|
||
<h4>ب) منطق تولید پروژه</h4>
|
||
<pre><code>// src/generators/new-project.ts
|
||
import { execa } from 'execa';
|
||
import * as fs from 'fs-extra';
|
||
import { join } from 'path';
|
||
import { logger } from '../lib/logger';
|
||
import { copyTemplate } from '../lib/fs-utils';
|
||
|
||
export interface NewProjectOptions {
|
||
name: string;
|
||
directory: string;
|
||
template: string;
|
||
skipInstall?: boolean;
|
||
onProgress?: (msg: string) => void;
|
||
}
|
||
|
||
export async function generateNewProject(opts: NewProjectOptions) {
|
||
const { name, directory, onProgress, skipInstall } = opts;
|
||
const templatesRoot = join(__dirname, '..', '..', 'templates', opts.template);
|
||
|
||
// 1. ساخت پوشه
|
||
await fs.ensureDir(directory);
|
||
onProgress?.('Creating directory structure...');
|
||
|
||
// 2. تولید با Angular CLI
|
||
onProgress?.('Running ng new...');
|
||
await execa(
|
||
'npx',
|
||
[
|
||
'@angular/cli@12.0.4', 'new', name,
|
||
'--routing', '--style=scss', '--skip-git', '--skip-install',
|
||
'--skip-tests', '--package-manager=npm',
|
||
],
|
||
{ cwd: directory, stdio: 'inherit' }
|
||
);
|
||
|
||
const projectRoot = join(directory, name);
|
||
|
||
// 3. افزودن Ionic
|
||
onProgress?.('Running ionic init...');
|
||
await execa('npx', ['@ionic/cli@6.6.0', 'init', 'x-framework-app', 'angular', '--type=angular-standalone'], {
|
||
cwd: projectRoot,
|
||
stdio: 'inherit',
|
||
});
|
||
|
||
// 4. کپی قالبهای سفارشی (app, views, config, plugins...)
|
||
onProgress?.('Copying xFramework templates...');
|
||
await copyTemplateTree(templatesRoot, projectRoot, {
|
||
__APP_NAME__: name,
|
||
__APP_INSTANCE__: name + 'Client',
|
||
});
|
||
|
||
// 5. نصب پکیجهای xFramework
|
||
onProgress?.('Installing dependencies...');
|
||
const pkgPath = join(projectRoot, 'package.json');
|
||
const pkg = await fs.readJson(pkgPath);
|
||
pkg.dependencies = {
|
||
...pkg.dependencies,
|
||
'x-framework-core': '^1.0.0',
|
||
'x-framework-services': '^1.0.0',
|
||
'x-framework-components': '^1.0.0',
|
||
'x-framework-identity-sdk': '^1.0.0',
|
||
'x-framework-push-service': '^1.0.0',
|
||
'x-saherelm-api-sdk': '^1.0.0',
|
||
};
|
||
await fs.writeJson(pkgPath, pkg, { spaces: 2 });
|
||
|
||
// 6. نصب نهایی
|
||
if (!skipInstall) {
|
||
onProgress?.('npm install...');
|
||
await execa('npm', ['install', '--legacy-peer-deps'], {
|
||
cwd: projectRoot,
|
||
stdio: 'inherit',
|
||
});
|
||
}
|
||
|
||
logger.success(`Project '${name}' generated at ${projectRoot}`);
|
||
}
|
||
|
||
async function copyTemplateTree(
|
||
src: string,
|
||
dest: string,
|
||
context: Record<string, any>
|
||
) {
|
||
const entries = await fs.readdir(src, { withFileTypes: true });
|
||
for (const entry of entries) {
|
||
const srcPath = join(src, entry.name);
|
||
const destPath = join(dest, entry.name);
|
||
if (entry.isDirectory()) {
|
||
await copyTemplateTree(srcPath, destPath, context);
|
||
} else {
|
||
await copyTemplate(src, entry.name, destPath, context);
|
||
}
|
||
}
|
||
}</code></pre>
|
||
</div>
|
||
</div>
|
||
|
||
<h3>گام ۷: دستور <code>xcli g</code> (Generate)</h3>
|
||
<p>ساخت زیردستور برای تولید اجزای مختلف:</p>
|
||
<pre><code>// src/commands/generate.ts
|
||
import { Command } from 'commander';
|
||
import { generatePage } from '../generators/page';
|
||
import { generateView } from '../generators/view';
|
||
import { generateService } from '../generators/service';
|
||
import { generateModule } from '../generators/module';
|
||
import { generateProviderPage } from '../generators/provider-page';
|
||
import { logger } from '../lib/logger';
|
||
|
||
export function registerGenerateCommand(program: Command) {
|
||
const g = program
|
||
.command('generate')
|
||
.alias('g')
|
||
.description('Generate xFramework artifacts');
|
||
|
||
// xcli g page
|
||
g.command('page <name>')
|
||
.description('Generate a Page (src/app/pages/<name>)')
|
||
.option('-m, --module <name>', 'Parent module', 'app')
|
||
.option('--lazy', 'Create lazy-loaded module')
|
||
.option('--provider', 'Extend VQueryPresenterBasePage')
|
||
.action(async (name, opts) => {
|
||
logger.title(`Generating page: ${name}`);
|
||
await generatePage({ name, ...opts });
|
||
});
|
||
|
||
// xcli g view
|
||
g.command('view <name>')
|
||
.description('Generate a View component (src/app/views/v-<name>)')
|
||
.option('--dto', 'Extend VBaseDtoComponent')
|
||
.option('--page', 'Extend VPageComponent')
|
||
.option('--plain', 'Plain Angular component')
|
||
.action(async (name, opts) => {
|
||
logger.title(`Generating view: ${name}`);
|
||
await generateView({ name, ...opts });
|
||
});
|
||
|
||
// xcli g service
|
||
g.command('service <name>')
|
||
.description('Generate a shared service')
|
||
.option('--singleton', 'providedIn: root', true)
|
||
.action(async (name, opts) => {
|
||
logger.title(`Generating service: ${name}`);
|
||
await generateService({ name, ...opts });
|
||
});
|
||
|
||
// xcli g module
|
||
g.command('module <name>')
|
||
.description('Generate an Angular module with routing')
|
||
.option('--lazy', 'Lazy-loaded module')
|
||
.action(async (name, opts) => {
|
||
logger.title(`Generating module: ${name}`);
|
||
await generateModule({ name, ...opts });
|
||
});
|
||
|
||
// xcli g provider-page
|
||
g.command('provider-page <name>')
|
||
.description('Generate a ProviderPage (Explorer/Management)')
|
||
.option('--kind <kind>', 'explorer | management', 'explorer')
|
||
.action(async (name, opts) => {
|
||
logger.title(`Generating provider page: ${name}`);
|
||
await generateProviderPage({ name, ...opts });
|
||
});
|
||
|
||
// اگر هیچ زیردستوری داده نشد، راهنما نشان بده
|
||
g.action(() => g.help());
|
||
}</code></pre>
|
||
|
||
<h3>گام ۸: Generator برای Page</h3>
|
||
<pre><code>// src/generators/page.ts
|
||
import { join } from 'path';
|
||
import * as fs from 'fs-extra';
|
||
import { logger } from '../lib/logger';
|
||
import { copyTemplate } from '../lib/fs-utils';
|
||
import { findProjectRoot, registerRoute } from '../lib/project-utils';
|
||
|
||
export interface GenPageOptions {
|
||
name: string;
|
||
module?: string;
|
||
lazy?: boolean;
|
||
provider?: boolean;
|
||
}
|
||
|
||
export async function generatePage(opts: GenPageOptions) {
|
||
const projectRoot = await findProjectRoot(process.cwd());
|
||
if (!projectRoot) {
|
||
throw new Error('Not inside an xFramework project');
|
||
}
|
||
|
||
const templatesRoot = join(__dirname, '..', '..', 'templates', 'page');
|
||
const pagesRoot = join(projectRoot, 'src', 'app', 'pages');
|
||
|
||
const kebab = toKebab(opts.name);
|
||
const pascal = toPascal(opts.name);
|
||
const targetDir = join(pagesRoot, kebab);
|
||
|
||
if (await fs.pathExists(targetDir)) {
|
||
throw new Error(`Page '${kebab}' already exists`);
|
||
}
|
||
|
||
// فایلهای اصلی
|
||
const data = {
|
||
__NAME__: kebab,
|
||
__CLASS__: pascal,
|
||
__TITLE_RES__: `${kebab}_page_title`,
|
||
__DESC_RES__: `${kebab}_page_description`,
|
||
__BASE_CLASS__: opts.provider ? 'VQueryPresenterBasePage' : 'VPageComponent',
|
||
};
|
||
|
||
await copyTemplate(templatesRoot, 'page.page.ts.hbs', join(targetDir, `${kebab}.page.ts`), data);
|
||
await copyTemplate(templatesRoot, 'page.page.html.hbs', join(targetDir, `${kebab}.page.html`), data);
|
||
await copyTemplate(templatesRoot, 'page.page.scss.hbs', join(targetDir, `${kebab}.page.scss`), data);
|
||
|
||
logger.file(join('src/app/pages', kebab));
|
||
|
||
// ثبت در routing
|
||
await registerRoute(projectRoot, pascal, kebab);
|
||
logger.success(`Page '${pascal}' generated`);
|
||
}
|
||
|
||
function toKebab(s: string) {
|
||
return s.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
||
}
|
||
function toPascal(s: string) {
|
||
return s.replace(/(^|-)([a-z])/g, (_, __, c) => c.toUpperCase());
|
||
}</code></pre>
|
||
|
||
<h3>گام ۹: ثبت Route و اصلاح app-routing</h3>
|
||
<p>با استفاده از <code>ts-morph</code> میتوان آرایهی <code>routes</code> را دستکاری کرد. برای شروع میتوانید یک Placeholder ساده تعریف کنید:</p>
|
||
<pre><code>// src/lib/project-utils.ts
|
||
import { execa } from 'execa';
|
||
import * as fs from 'fs-extra';
|
||
import { join, dirname } from 'path';
|
||
import { Project, SyntaxKind } from 'ts-morph';
|
||
|
||
export async function findProjectRoot(start: string): Promise<string | null> {
|
||
let current = start;
|
||
for (let i = 0; i < 8; i++) {
|
||
const pkgPath = join(current, 'package.json');
|
||
if (await fs.pathExists(pkgPath)) {
|
||
const pkg = await fs.readJson(pkgPath);
|
||
if (pkg.dependencies?.['x-framework-core']) return current;
|
||
}
|
||
const parent = dirname(current);
|
||
if (parent === current) break;
|
||
current = parent;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
export async function registerRoute(
|
||
projectRoot: string,
|
||
className: string,
|
||
routePath: string
|
||
) {
|
||
const routingFile = join(projectRoot, 'src', 'app', 'app-routing.module.ts');
|
||
const project = new Project();
|
||
const source = project.addSourceFileAtPath(routingFile);
|
||
|
||
const routesArray = source.getVariableDeclaration('routes');
|
||
if (!routesArray) throw new Error('routes array not found');
|
||
|
||
const initializer = routesArray.getInitializerIfKindOrThrow(SyntaxKind.ArrayLiteralExpression);
|
||
initializer.addElement((writer) => {
|
||
writer
|
||
.write('{')
|
||
.newLine()
|
||
.write(` component: ${className},`)
|
||
.newLine()
|
||
.write(` path: '${routePath}',`)
|
||
.newLine()
|
||
.write(` canDeactivate: [XCanDeactivateGuard],`)
|
||
.newLine()
|
||
.write('}');
|
||
});
|
||
|
||
source.saveSync();
|
||
}
|
||
</code></pre>
|
||
|
||
<h3>گام ۱۰: دستور <code>xcli add</code> (افزودن وابستگی و پلاگین)</h3>
|
||
<pre><code>// src/commands/add.ts
|
||
import { Command } from 'commander';
|
||
import { execa } from 'execa';
|
||
import ora from 'ora';
|
||
import { logger } from '../lib/logger';
|
||
import { findProjectRoot } from '../lib/project-utils';
|
||
|
||
export function registerAddCommand(program: Command) {
|
||
const add = program.command('add').description('Add dependencies / plugins');
|
||
|
||
// xcli add plugin <name>
|
||
add.command('plugin <name>')
|
||
.description('Add a Cordova plugin (device, splashscreen, statusbar)')
|
||
.action(async (name) => {
|
||
const root = await findProjectRoot(process.cwd());
|
||
if (!root) throw new Error('Not inside an xFramework project');
|
||
|
||
const spinner = ora(`Adding cordova plugin: ${name}`).start();
|
||
try {
|
||
await execa('ionic', ['cordova', 'plugin', 'add', `cordova-plugin-${name}`], {
|
||
cwd: root,
|
||
stdio: 'inherit',
|
||
});
|
||
// کپی type definitions به پوشه plugins
|
||
// (اختیاری، اگر نسخهی محلی نگهداری میکنید)
|
||
spinner.succeed();
|
||
} catch (err: any) {
|
||
spinner.fail(err.message);
|
||
}
|
||
});
|
||
|
||
// xcli add x-framework-xxx
|
||
add.command('package <name>')
|
||
.description('Add an xFramework package to the project')
|
||
.action(async (name) => {
|
||
const root = await findProjectRoot(process.cwd());
|
||
if (!root) throw new Error('Not inside an xFramework project');
|
||
|
||
const spinner = ora(`Installing ${name}`).start();
|
||
try {
|
||
await execa('npm', ['install', name, '--legacy-peer-deps'], {
|
||
cwd: root,
|
||
stdio: 'inherit',
|
||
});
|
||
spinner.succeed();
|
||
} catch (err: any) {
|
||
spinner.fail(err.message);
|
||
}
|
||
});
|
||
}</code></pre>
|
||
|
||
<h3>گام ۱۱: دستور <code>xcli doctor</code></h3>
|
||
<p>یک ابزار تشخیصی که محیط را بررسی میکند:</p>
|
||
<pre><code>// src/commands/doctor.ts
|
||
import { Command } from 'commander';
|
||
import { execa } from 'execa';
|
||
import { logger } from '../lib/logger';
|
||
import chalk from 'chalk';
|
||
|
||
const REQUIRED_NODE = '14.17.3';
|
||
const REQUIRED_ANGULAR = '12.0.4';
|
||
const REQUIRED_IONIC = '6.6.0';
|
||
|
||
export function registerDoctorCommand(program: Command) {
|
||
program.command('doctor')
|
||
.description('Verify environment compatibility')
|
||
.action(async () => {
|
||
logger.title('Environment Check');
|
||
|
||
const checks = await Promise.all([
|
||
runVersion('node', ['-v']),
|
||
runVersion('npm', ['-v']),
|
||
runVersion('ng', ['version']),
|
||
runVersion('ionic', ['-v']),
|
||
]);
|
||
|
||
const [node, npm, ng, ionic] = checks;
|
||
|
||
printCheck('Node.js', node, REQUIRED_NODE);
|
||
printCheck('npm', npm, null);
|
||
printCheck('@angular/cli', ng, REQUIRED_ANGULAR);
|
||
printCheck('@ionic/cli', ionic, REQUIRED_IONIC);
|
||
|
||
const nodeOk = node.startsWith('v14');
|
||
const ngOk = ng.startsWith('12');
|
||
const ionicOk = ionic.startsWith('6');
|
||
|
||
if (nodeOk && ngOk && ionicOk) {
|
||
logger.success('All checks passed ✅');
|
||
} else {
|
||
logger.warn('Some checks failed — see above');
|
||
process.exit(1);
|
||
}
|
||
});
|
||
}
|
||
|
||
async function runVersion(cmd: string, args: string[]) {
|
||
try {
|
||
const { stdout } = await execa(cmd, args);
|
||
return stdout.split('\n')[0].trim();
|
||
} catch {
|
||
return 'not installed';
|
||
}
|
||
}
|
||
|
||
function printCheck(name: string, found: string, expected: string | null) {
|
||
const ok = !expected || found.includes(expected);
|
||
const icon = ok ? chalk.green('✔') : chalk.red('✖');
|
||
console.log(`${icon} ${name.padEnd(20)} ${found}${expected ? chalk.gray(` (expected ${expected})`) : ''}`);
|
||
}</code></pre>
|
||
</section>
|
||
|
||
<!-- =============== 6. GENERATORS =============== -->
|
||
<section id="generators">
|
||
<h2><a class="hash" href="#generators">#</a>6. تولیدکنندهها (Generators)</h2>
|
||
|
||
<p>هر Generator باید بتواند مستقیم اجرا شود و همچنین توسط Command فراخوانی شود. جدول زیر لیست کامل Generatorها را نشان میدهد:</p>
|
||
|
||
<table>
|
||
<thead>
|
||
<tr><th>Generator</th><th>خروجی</th><th>پایه</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td><code>g new <app></code></td><td>پروژهی کامل</td><td>Angular + Ionic + xFramework</td></tr>
|
||
<tr><td><code>g page <name></code></td><td>صفحه</td><td><code>VPageComponent</code></td></tr>
|
||
<tr><td><code>g page --provider</code></td><td>صفحه با Query</td><td><code>VQueryPresenterBasePage</code></td></tr>
|
||
<tr><td><code>g provider-page</code></td><td>Explorer/Management</td><td>Base</td></tr>
|
||
<tr><td><code>g view <name></code></td><td>کامپوننت View</td><td><code>VBaseDtoComponent</code></td></tr>
|
||
<tr><td><code>g service <name></code></td><td>سرویس</td><td><code>XBaseService</code></td></tr>
|
||
<tr><td><code>g module <name></code></td><td>ماژول Routing</td><td><code>RouterModule.forChild</code></td></tr>
|
||
<tr><td><code>g dto <name></code></td><td>Dto + type guard</td><td><code>XBaseDto</code></td></tr>
|
||
<tr><td><code>g enum <name></code></td><td>Enum با isValueInEnum</td><td>—</td></tr>
|
||
<tr><td><code>g config <name></code></td><td>Config با InjectionToken</td><td>—</td></tr>
|
||
<tr><td><code>g pipe <name></code></td><td>Pure Pipe</td><td>—</td></tr>
|
||
<tr><td><code>g directive <name></code></td><td>Attribute Directive</td><td>—</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<h3>6.1. کتابخانهی کمکی برای Conventionها</h3>
|
||
<pre><code>// src/lib/naming.ts
|
||
export const toKebab = (s: string) =>
|
||
s.replace(/([a-z0-9])([A-Z])/g, '$1-$2').replace(/\s+/g, '-').toLowerCase();
|
||
|
||
export const toPascal = (s: string) =>
|
||
toKebab(s).split('-').map(w => w.charAt(0).toUpperCase() + w.slice(1)).join('');
|
||
|
||
export const toCamel = (s: string) =>
|
||
toPascal(s).replace(/^./, (c) => c.toLowerCase());
|
||
|
||
export const toSnake = (s: string) =>
|
||
toKebab(s).replace(/-/g, '_');</code></pre>
|
||
|
||
<h3>6.2. الگوی Generator استاندارد</h3>
|
||
<p>هر Generator جدید باید این الگو را رعایت کند:</p>
|
||
<ol>
|
||
<li>یافتن ریشهی پروژه با <code>findProjectRoot</code>.</li>
|
||
<li>اعتبارسنجی نام و عدم تکرار.</li>
|
||
<li>تولید فایلها با <code>copyTemplate</code>.</li>
|
||
<li>Merge با فایلهای موجود (Routing، Module، PageIndex).</li>
|
||
<li>نمایش گزارش با <code>logger</code>.</li>
|
||
<li>در صورت خطا، خروج با کد 1 و پیام روشن.</li>
|
||
</ol>
|
||
</section>
|
||
|
||
<!-- =============== 7. TEMPLATES =============== -->
|
||
<section id="templates">
|
||
<h2><a class="hash" href="#templates">#</a>7. سیستم قالبها (Templates)</h2>
|
||
|
||
<p>قالبها فایلهای <code>.hbs</code> هستند که با Handlebars رندر میشوند. نامگذاری متغیرها با <code>__NAME__</code> انجام میشود (نه <code>{{name}}</code>) تا از تضاد با دستورات خود Handlebars جلوگیری شود.</p>
|
||
|
||
<h3>7.1. قالب Page</h3>
|
||
<pre><code>{{! templates/page/page.page.ts.hbs }}
|
||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||
import { XSideType } from 'x-framework-components';
|
||
import { VPageComponent } from 'src/app/views/v-page/v-page.component';
|
||
|
||
@Component({
|
||
selector: 'app-__NAME__',
|
||
templateUrl: './__NAME__.page.html',
|
||
styleUrls: ['./__NAME__.page.scss'],
|
||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||
})
|
||
// tslint:disable-next-line:component-class-suffix
|
||
export class __CLASS__Page extends VPageComponent {
|
||
//
|
||
//#region Props ...
|
||
hasSide = true;
|
||
toolbarShowSubTitle = true;
|
||
showToolbarEndSlot = true;
|
||
showToolbarContent = false;
|
||
titleRes = this.AppResourceIDs.__TITLE_RES__;
|
||
toolbarSubTitle = this.resourceProvider(this.titleRes);
|
||
|
||
/**
|
||
* use this for Menu always Visible ...
|
||
*/
|
||
toggleMenuWhen = '';
|
||
sideType = XSideType.Overlay;
|
||
//#endregion
|
||
}</code></pre>
|
||
|
||
<pre><code>{{! templates/page/page.page.html.hbs }}
|
||
<!-- -->
|
||
<!-- Page Presenter -->
|
||
<!-- -->
|
||
<v-page-presenter
|
||
[loading]="loading"
|
||
[containerBase]="this"
|
||
[uiDisabled]="uiDisabled"
|
||
[contentTemplate]="contentTemplate"
|
||
></v-page-presenter>
|
||
|
||
<!-- -->
|
||
<!-- Page Content -->
|
||
<!-- -->
|
||
<ng-template #contentTemplate>
|
||
<!-- TODO: Add content -->
|
||
</ng-template></code></pre>
|
||
|
||
<h3>7.2. قالب View (VBaseDto)</h3>
|
||
<pre><code>{{! templates/view/view.component.ts.hbs }}
|
||
import {
|
||
Component,
|
||
ChangeDetectionStrategy,
|
||
} from '@angular/core';
|
||
import {
|
||
getFieldNames,
|
||
XExceptionIDs,
|
||
isNullOrUndefined,
|
||
isNullOrEmptyString,
|
||
} from 'x-framework-core';
|
||
import {
|
||
X__CLASS__Dto,
|
||
default__CLASS__Dto,
|
||
prepare__CLASS__DtoFields,
|
||
} from 'x-saherelm-api-sdk';
|
||
import {
|
||
VBaseDtoComponent,
|
||
VModelFieldDescriptor,
|
||
VModelValidationResult,
|
||
} from '../../v-dto/v-dto.typings';
|
||
|
||
@Component({
|
||
selector: 'v-__NAME__',
|
||
templateUrl: './v-__NAME__.component.html',
|
||
styleUrls: ['./v-__NAME__.component.scss'],
|
||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||
})
|
||
export class V__CLASS__Component extends VBaseDtoComponent<X__CLASS__Dto> {
|
||
readonly defaultModel: X__CLASS__Dto = { ...default__CLASS__Dto };
|
||
readonly FieldNames = getFieldNames(this.defaultModel);
|
||
|
||
defaultFieldDescriptors: VModelFieldDescriptor<any>[] = [
|
||
// TODO: Add field descriptors
|
||
];
|
||
|
||
validate(
|
||
model?: Partial<X__CLASS__Dto>
|
||
): VModelValidationResult<X__CLASS__Dto> {
|
||
// TODO: Implement validation
|
||
const normalized = this.normalize(model);
|
||
return {
|
||
isValid: true,
|
||
normalized,
|
||
isValidForAdd: true,
|
||
isValidForUpdate: true,
|
||
validationErrors: [],
|
||
};
|
||
}
|
||
|
||
prepare(model?: X__CLASS__Dto): X__CLASS__Dto {
|
||
return prepare__CLASS__DtoFields(model);
|
||
}
|
||
}</code></pre>
|
||
|
||
<h3>7.3. قالب ProviderPage (Explorer / Management)</h3>
|
||
<p>این قالب دقیقاً بازتاب ساختار <code>FilesBaseProviderPage</code> و <code>TagsBaseProviderPage</code> است که در xClient دیدیم:</p>
|
||
|
||
<pre><code>{{! templates/provider-page/base.provider.page.ts.hbs }}
|
||
import {
|
||
Component,
|
||
ViewChild,
|
||
TemplateRef,
|
||
ChangeDetectionStrategy,
|
||
} from '@angular/core';
|
||
import { Observable, Subject } from 'rxjs';
|
||
import { nameof, getFieldNames, isNullOrUndefined } from 'x-framework-core';
|
||
import { X__CLASS__Dto, default__CLASS__Dto } from 'x-saherelm-api-sdk';
|
||
import { XQueryDto, XQueryResultDto } from 'x-framework-identity-sdk';
|
||
import { VQueryPresenterBasePage } from 'src/app/views/v-query-presenter/v-query-presenter.base.page';
|
||
import { VBaseDtoActionModel, VBaseDtoPresentType } from 'src/app/views/v-dto/v-dto.typings';
|
||
import { XListItem } from 'x-framework-components';
|
||
|
||
@Component({
|
||
template: '',
|
||
changeDetection: ChangeDetectionStrategy.OnPush,
|
||
})
|
||
export abstract class __CLASS__BaseProviderPage extends VQueryPresenterBasePage {
|
||
//
|
||
modelIdentifier: string = nameof<X__CLASS__Dto>('id');
|
||
listTabCardTitle = this.AppResourceIDs.__NAME__s;
|
||
|
||
//
|
||
queryPresenterActionProvider = new Subject<any>();
|
||
listItemActionProvider = new Subject<VBaseDtoActionModel>();
|
||
|
||
//
|
||
query: XQueryDto = {
|
||
page: 1,
|
||
filter: '',
|
||
pageSize: this.config.defaultPageSize,
|
||
sortBy: nameof<X__CLASS__Dto>('id'),
|
||
};
|
||
dtoQueryResult: XQueryResultDto<X__CLASS__Dto> = undefined;
|
||
hasQueryResultError = false;
|
||
|
||
// Templates
|
||
@ViewChild('itemTemplate') itemTemplate!: TemplateRef<any>;
|
||
@ViewChild('listItemTemplate') listItemTemplate!: TemplateRef<any>;
|
||
@ViewChild('addItemTemplate') addItemTemplate!: TemplateRef<any>;
|
||
@ViewChild('updateItemTemplate') updateItemTemplate!: TemplateRef<any>;
|
||
@ViewChild('detailsItemTemplate') detailsItemTemplate!: TemplateRef<any>;
|
||
|
||
abstract getModelTask(identifier: string): Observable<any>;
|
||
abstract queryModelTask(query: XQueryDto): Observable<XQueryResultDto<any>>;
|
||
|
||
async handleGetQueryResult(query: XQueryDto): Promise<XQueryResultDto<any>> {
|
||
// TODO: implement
|
||
return undefined as any;
|
||
}
|
||
async validateAndPrepareListItems(items: XListItem<any>[]) {
|
||
return items;
|
||
}
|
||
async requestFillingItems(exists: any[], recieved: any[]) {
|
||
return undefined as any;
|
||
}
|
||
async doItemActions(info: { id: string; data: any }) {
|
||
// TODO
|
||
}
|
||
async handleCustomError(error?: string) {
|
||
// TODO
|
||
}
|
||
}</code></pre>
|
||
|
||
<h3>7.4. قالب Service</h3>
|
||
<pre><code>{{! templates/service/service.ts.hbs }}
|
||
import { Inject, Injectable } from '@angular/core';
|
||
import { XBaseService } from 'x-framework-core';
|
||
import { XManagerService } from 'x-framework-services';
|
||
import { X_CONFIG } from 'src/app/config/x.config';
|
||
import { XConfig } from 'src/app/config/app.config';
|
||
|
||
@Injectable({
|
||
providedIn: 'root',
|
||
})
|
||
export class X__CLASS__Service extends XBaseService {
|
||
constructor(
|
||
@Inject(X_CONFIG) public config: XConfig,
|
||
public managerService: XManagerService
|
||
) {
|
||
super(config);
|
||
}
|
||
|
||
// TODO: Add methods
|
||
}</code></pre>
|
||
|
||
<h3>7.5. قالب Module با Lazy Loading</h3>
|
||
<pre><code>{{! templates/module/module.ts.hbs }}
|
||
import { NgModule } from '@angular/core';
|
||
import { RouterModule } from '@angular/router';
|
||
import { AuthGuard } from 'x-framework-identity-sdk';
|
||
import { XCanDeactivateGuard } from 'x-framework-core';
|
||
import { BaseRoutes } from 'src/app/config/page.config';
|
||
import { ViewsModule } from 'src/app/views/views.module';
|
||
|
||
@NgModule({
|
||
declarations: [],
|
||
imports: [
|
||
ViewsModule,
|
||
RouterModule.forChild([
|
||
{
|
||
pathMatch: 'full',
|
||
path: BaseRoutes.Default,
|
||
redirectTo: '__NAME__',
|
||
},
|
||
{
|
||
path: '__NAME__',
|
||
canActivate: [AuthGuard],
|
||
canDeactivate: [XCanDeactivateGuard],
|
||
loadChildren: () =>
|
||
import('./pages/__NAME__/__NAME__.module').then(
|
||
(m) => m.__CLASS__PageModule
|
||
),
|
||
},
|
||
]),
|
||
],
|
||
exports: [ViewsModule, RouterModule],
|
||
})
|
||
export class __CLASS__PageModule {}</code></pre>
|
||
|
||
<div class="note success">
|
||
<div class="emoji">✅</div>
|
||
<div>
|
||
<strong>قرارداد قالبها:</strong> هر فایل قالب باید در پوشهی مخصوص خود نگهداری شود (page، view، service، provider-page، module، …)
|
||
و نام فایل قالب با نام فایل خروجی یکسان باشد، فقط پسوند <code>.hbs</code> اضافه شده باشد.
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- =============== 8. CONFIG =============== -->
|
||
<section id="config">
|
||
<h2><a class="hash" href="#config">#</a>8. مدیریت پیکربندی و Environments</h2>
|
||
|
||
<p>
|
||
در xClient پیکربندی از طریق فایلهای <code>app.config.ts</code>، <code>x.config.ts</code> و
|
||
<code>environment.ts</code> انجام میشود. xCLI باید بتواند این پیکربندی را در زمان ساخت پروژه و در زمان اجرا (با
|
||
دستور <code>xcli config set</code>) مدیریت کند.
|
||
</p>
|
||
|
||
<h3>8.1. ساختار پیشنهادی پیکربندی</h3>
|
||
<pre><code>// src/app/config/app.config.ts (خلاصه)
|
||
import { XFrameworkCoreConfig } from 'x-framework-core';
|
||
import { XFrameworkServicesConfig } from 'x-framework-services';
|
||
import { XFrameworkComponentsConfig } from 'x-framework-components';
|
||
import { XFrameworkIdentitySDKConfig } from 'x-framework-identity-sdk';
|
||
import { XFrameworkPushServiceConfig } from 'x-framework-push-service';
|
||
import { XSaherElmApiSDKConfig } from 'x-saherelm-api-sdk';
|
||
|
||
export type XConfig = XFrameworkCoreConfig
|
||
& XFrameworkServicesConfig
|
||
& XFrameworkComponentsConfig
|
||
& XFrameworkIdentitySDKConfig
|
||
& XFrameworkPushServiceConfig
|
||
& XSaherElmApiSDKConfig
|
||
& AppConfig;
|
||
|
||
export const xFrameworkCoreSharedConfig = { /* ... */ };
|
||
export const xFrameworkServicesSharedConfig = { /* ... */ };
|
||
export const xFrameworkComponentsSharedConfig = { /* ... */ };
|
||
export const xFrameworkIdentitySDKSharedConfig = { /* ... */ };
|
||
export const xFrameworkPushServiceSharedConfig = { /* ... */ };
|
||
export const xSaherElmApiSDKSharedConfig = { /* ... */ };
|
||
export const xAppSharedConfig = { /* ... */ };
|
||
|
||
export const xSharedConfig = {
|
||
...xFrameworkCoreSharedConfig,
|
||
...xFrameworkServicesSharedConfig,
|
||
...xFrameworkComponentsSharedConfig,
|
||
...xFrameworkIdentitySDKSharedConfig,
|
||
...xFrameworkPushServiceSharedConfig,
|
||
...xSaherElmApiSDKSharedConfig,
|
||
...xAppSharedConfig,
|
||
};</code></pre>
|
||
|
||
<h3>8.2. دستور <code>xcli config</code></h3>
|
||
<pre><code>// src/commands/config.ts
|
||
import { Command } from 'commander';
|
||
import inquirer from 'inquirer';
|
||
import * as fs from 'fs-extra';
|
||
import { join } from 'path';
|
||
import { findProjectRoot } from '../lib/project-utils';
|
||
import { logger } from '../lib/logger';
|
||
|
||
export function registerConfigCommand(program: Command) {
|
||
const cfg = program.command('config')
|
||
.description('Manage project configuration');
|
||
|
||
// xcli config show
|
||
cfg.command('show')
|
||
.description('Show current environment configuration')
|
||
.action(async () => {
|
||
const root = await findProjectRoot(process.cwd());
|
||
const envFile = join(root!, 'src', 'environments', 'environment.ts');
|
||
console.log(await fs.readFile(envFile, 'utf-8'));
|
||
});
|
||
|
||
// xcli config set <key> <value>
|
||
cfg.command('set <key> <value>')
|
||
.description('Set a configuration value (dot-notation)')
|
||
.option('--prod', 'Apply to production environment')
|
||
.action(async (key, value, opts) => {
|
||
const root = await findProjectRoot(process.cwd());
|
||
const envFile = join(
|
||
root!,
|
||
'src',
|
||
'environments',
|
||
opts.prod ? 'environment.prod.ts' : 'environment.ts'
|
||
);
|
||
// Update with ts-morph or simple regex
|
||
// ... (پیادهسازی با ts-morph ترجیح داده میشود)
|
||
logger.success(`Set ${key} = ${value} in ${envFile}`);
|
||
});
|
||
|
||
// xcli config locales
|
||
cfg.command('locales')
|
||
.description('List available locales')
|
||
.action(async () => {
|
||
// خواندن از localization.config.ts
|
||
});
|
||
|
||
cfg.action(() => cfg.help());
|
||
}</code></pre>
|
||
|
||
<h3>8.3. دستور <code>xcli env</code></h3>
|
||
<p>مدیریت Environment:</p>
|
||
<pre><code>xcli env add staging
|
||
xcli env list
|
||
xcli env remove staging
|
||
xcli env switch staging</code></pre>
|
||
<p>پیادهسازی این دستور به ایجاد فایل جدید <code>environment.staging.ts</code> و بهروزرسانی <code>angular.json</code> در بخش <code>fileReplacements</code> منجر میشود.</p>
|
||
</section>
|
||
|
||
<!-- =============== 9. PLUGINS =============== -->
|
||
<section id="plugins">
|
||
<h2><a class="hash" href="#plugins">#</a>9. مدیریت افزونهها (Cordova Plugins)</h2>
|
||
|
||
<p>
|
||
در xClient سه پلاگین Cordova بهصورت محلی نگهداری میشود:
|
||
<code>cordova-plugin-device</code>، <code>cordova-plugin-splashscreen</code> و <code>cordova-plugin-statusbar</code>.
|
||
xCLI باید بتواند این پلاگینها را با Type Definitionهای آماده اضافه کند.
|
||
</p>
|
||
|
||
<h3>9.1. ساختار پوشهی پلاگینها</h3>
|
||
<pre><code>plugins/
|
||
└── cordova-plugin-<name>/
|
||
├── types/
|
||
│ └── index.d.ts ← Type Definitions
|
||
└── src/
|
||
└── wp/ ← پیادهسازی Windows Phone (اختیاری)</code></pre>
|
||
|
||
<h3>9.2. قالب Type Definition برای Device</h3>
|
||
<pre><code>// templates/plugins/device/index.d.ts.hbs
|
||
// Type definitions for Apache Cordova Device plugin
|
||
|
||
interface Device {
|
||
cordova: string;
|
||
available: boolean;
|
||
model: string;
|
||
platform: string;
|
||
uuid: string;
|
||
version: string;
|
||
manufacturer: string;
|
||
isVirtual: boolean;
|
||
serial: string;
|
||
}
|
||
|
||
declare var device: Device;</code></pre>
|
||
|
||
<h3>9.3. دستور <code>xcli add plugin</code></h3>
|
||
<p>این دستور باید سه کار انجام دهد:</p>
|
||
<ol>
|
||
<li>اجرای <code>ionic cordova plugin add cordova-plugin-<name></code>.</li>
|
||
<li>کپی پوشهی <code>types/</code> به <code>plugins/cordova-plugin-<name>/types/</code>.</li>
|
||
<li>افزودن ارجاع در <code>tsconfig.json</code> (بخش <code>include</code> یا <code>files</code>) اگر لازم شد.</li>
|
||
</ol>
|
||
<pre><code>// src/commands/add-plugin.ts
|
||
import { Command } from 'commander';
|
||
import { execa } from 'execa';
|
||
import * as fs from 'fs-extra';
|
||
import { join } from 'path';
|
||
import ora from 'ora';
|
||
import { findProjectRoot } from '../lib/project-utils';
|
||
|
||
export async function addCordovaPlugin(name: string) {
|
||
const root = await findProjectRoot(process.cwd());
|
||
if (!root) throw new Error('Not inside an xFramework project');
|
||
|
||
const spinner = ora(`Adding cordova plugin: ${name}`).start();
|
||
try {
|
||
// 1) اجرای ionic
|
||
await execa('ionic', ['cordova', 'plugin', 'add', `cordova-plugin-${name}`], {
|
||
cwd: root,
|
||
stdio: 'inherit',
|
||
});
|
||
|
||
// 2) کپی Type Definitions از قالبها
|
||
const templateDir = join(__dirname, '..', '..', 'templates', 'plugins', name);
|
||
const targetDir = join(root, 'plugins', `cordova-plugin-${name}`);
|
||
if (await fs.pathExists(templateDir)) {
|
||
await fs.copy(templateDir, targetDir);
|
||
}
|
||
|
||
spinner.succeed(`Plugin ${name} added`);
|
||
} catch (err: any) {
|
||
spinner.fail(err.message);
|
||
throw err;
|
||
}
|
||
}</code></pre>
|
||
|
||
<h3>9.4. قالبهای پلاگین در xCLI</h3>
|
||
<pre><code>templates/plugins/
|
||
├── device/
|
||
│ └── types/index.d.ts
|
||
├── splashscreen/
|
||
│ └── types/index.d.ts
|
||
└── statusbar/
|
||
└── types/index.d.ts</code></pre>
|
||
|
||
<div class="note info">
|
||
<div class="emoji">💡</div>
|
||
<div>
|
||
اگر پروژه به Cordova وابسته نیست (مثلاً وب/الکترون)، دستور <code>xcli add plugin</code> باید هشدار دهد و از ادامه امتناع کند.
|
||
از فلگ <code>--force</code> برای عبور از این بررسی استفاده کنید.
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- =============== 10. BUILD =============== -->
|
||
<section id="build">
|
||
<h2><a class="hash" href="#build">#</a>10. فرآیند ساخت، تست و انتشار</h2>
|
||
|
||
<h3>10.1. دستور <code>xcli build</code></h3>
|
||
<p>دستور Build پوششی روی <code>ng build</code> و <code>ionic build</code> است با گزینههای پرکاربرد:</p>
|
||
<pre><code>// src/commands/build.ts
|
||
import { Command } from 'commander';
|
||
import { execa } from 'execa';
|
||
import ora from 'ora';
|
||
import { findProjectRoot } from '../lib/project-utils';
|
||
|
||
export function registerBuildCommand(program: Command) {
|
||
program.command('build')
|
||
.description('Build the application')
|
||
.option('-c, --configuration <cfg>', 'Angular configuration', 'production')
|
||
.option('--prod', 'Shorthand for --configuration=production')
|
||
.option('--base-href <href>', 'Base href')
|
||
.option('--deploy-url <url>', 'Deploy URL')
|
||
.option('--source-map', 'Generate source maps')
|
||
.action(async (opts) => {
|
||
const root = await findProjectRoot(process.cwd());
|
||
if (!root) throw new Error('Not inside an xFramework project');
|
||
|
||
const cfg = opts.prod ? 'production' : opts.configuration;
|
||
const args = ['build', '--configuration', cfg];
|
||
|
||
if (opts.baseHref) args.push('--base-href', opts.baseHref);
|
||
if (opts.deployUrl) args.push('--deploy-url', opts.deployUrl);
|
||
if (opts.sourceMap) args.push('--source-map');
|
||
|
||
const spinner = ora(`Building (${cfg})...`).start();
|
||
try {
|
||
await execa('ng', args, { cwd: root, stdio: 'inherit' });
|
||
spinner.succeed('Build completed');
|
||
} catch (err: any) {
|
||
spinner.fail(err.message);
|
||
}
|
||
});
|
||
|
||
program.command('serve')
|
||
.description('Start dev server')
|
||
.option('--port <port>', 'Dev port', '4200')
|
||
.option('--host <host>', 'Dev host', 'localhost')
|
||
.action(async (opts) => {
|
||
const root = await findProjectRoot(process.cwd());
|
||
await execa(
|
||
'ng',
|
||
['serve', '--port', opts.port, '--host', opts.host],
|
||
{ cwd: root!, stdio: 'inherit' }
|
||
);
|
||
});
|
||
}</code></pre>
|
||
|
||
<h3>10.2. تست</h3>
|
||
<p>دستور <code>xcli test</code> پوشش نازکی روی <code>ng test</code> است با گزینههای Coverage و Watch:</p>
|
||
<pre><code>xcli test --coverage
|
||
xcli test --watch=false --browsers=ChromeHeadless</code></pre>
|
||
|
||
<h3>10.3. انتشار xCLI روی npm</h3>
|
||
<p>پس از تست محلی با <code>npm link</code>، میتوان پکیج را روی رجیستری شرکت یا npm عمومی منتشر کرد:</p>
|
||
<pre><code>npm run build
|
||
npm version patch
|
||
npm publish --access public</code></pre>
|
||
|
||
<div class="note warning">
|
||
<div class="emoji">⚠️</div>
|
||
<div>
|
||
حتماً قبل از <code>npm publish</code>، فایل <code>.npmignore</code> بسازید تا <code>src/</code>، <code>node_modules/</code> و
|
||
<code>tsconfig.json</code> منتشر نشوند. فقط <code>bin/</code>، <code>dist/</code> و <code>templates/</code> باید منتشر شوند.
|
||
</div>
|
||
</div>
|
||
|
||
<h3>10.4. نمونهی .npmignore</h3>
|
||
<pre><code>src/
|
||
node_modules/
|
||
*.log
|
||
tsconfig.json
|
||
*.tsbuildinfo
|
||
.DS_Store
|
||
.vscode/
|
||
.idea/
|
||
test/
|
||
coverage/
|
||
</code></pre>
|
||
</section>
|
||
|
||
<!-- =============== 11. EXAMPLES =============== -->
|
||
<section id="examples">
|
||
<h2><a class="hash" href="#examples">#</a>11. مثالهای عملی و سناریوها</h2>
|
||
|
||
<h3>11.1. ساخت پروژهی جدید</h3>
|
||
<div class="cmd">xcli new my-x-app</div>
|
||
<p>خروجی مورد انتظار:</p>
|
||
<pre><code>◆ Creating xFramework project
|
||
|
||
✔ Project created successfully
|
||
|
||
ℹ cd my-x-app
|
||
ℹ npm run start:dev</code></pre>
|
||
|
||
<h3>11.2. افزودن صفحه به پروژه</h3>
|
||
<div class="cmd">cd my-x-app
|
||
xcli g page files --module=files --provider</div>
|
||
<p>فایلهای تولیدشده:</p>
|
||
<pre><code>src/app/pages/files/
|
||
├── files.page.ts
|
||
├── files.page.html
|
||
└── files.page.scss
|
||
|
||
✔ src/app/app-routing.module.ts updated</code></pre>
|
||
|
||
<h3>11.3. افزودن View با Dto</h3>
|
||
<div class="cmd">xcli g view article --dto</div>
|
||
<p>خروجی:</p>
|
||
<pre><code>src/app/views/v-article/
|
||
├── v-article.component.ts
|
||
├── v-article.component.html
|
||
└── v-article.component.scss
|
||
|
||
✔ View 'VArticleComponent' generated</code></pre>
|
||
|
||
<h3>11.4. افزودن پلاگین StatusBar</h3>
|
||
<div class="cmd">xcli add plugin statusbar</div>
|
||
<p>نتیجه:</p>
|
||
<pre><code>✔ Plugin statusbar added
|
||
|
||
plugins/
|
||
└── cordova-plugin-statusbar/
|
||
└── types/
|
||
└── index.d.ts</code></pre>
|
||
|
||
<h3>11.5. بررسی محیط</h3>
|
||
<div class="cmd">xcli doctor</div>
|
||
<pre><code>◆ Environment Check
|
||
|
||
✔ Node.js v14.17.3 (expected 14.17.3)
|
||
✔ npm 6.14.13
|
||
✔ @angular/cli 12.0.4 (expected 12.0.4)
|
||
✔ @ionic/cli 6.6.0 (expected 6.6.0)
|
||
|
||
✔ All checks passed ✅</code></pre>
|
||
|
||
<h3>11.6. Build پروژه</h3>
|
||
<div class="cmd">xcli build --prod --base-href=/app/</div>
|
||
|
||
<h3>11.7. سناریوی کامل</h3>
|
||
<div class="steps">
|
||
<div class="step" data-step="1">
|
||
<h4>ساخت پروژه</h4>
|
||
<code>xcli new saherelm-admin</code>
|
||
</div>
|
||
<div class="step" data-step="2">
|
||
<h4>افزودن پلاگینها</h4>
|
||
<code>xcli add plugin device</code>
|
||
<code>xcli add plugin splashscreen</code>
|
||
<code>xcli add plugin statusbar</code>
|
||
</div>
|
||
<div class="step" data-step="3">
|
||
<h4>افزودن پکیجهای xFramework</h4>
|
||
<code>xcli add package x-saherelm-api-sdk</code>
|
||
</div>
|
||
<div class="step" data-step="4">
|
||
<h4>تولید صفحات</h4>
|
||
<code>xcli g page dashboard</code>
|
||
<code>xcli g page users --provider</code>
|
||
<code>xcli g page reports --provider</code>
|
||
</div>
|
||
<div class="step" data-step="5">
|
||
<h4>تولید Viewها</h4>
|
||
<code>xcli g view user --dto</code>
|
||
<code>xcli g view report --dto</code>
|
||
</div>
|
||
<div class="step" data-step="6">
|
||
<h4>Build</h4>
|
||
<code>xcli build --prod</code>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- =============== 12. APPENDIX =============== -->
|
||
<section id="appendix">
|
||
<h2><a class="hash" href="#appendix">#</a>12. پیوست: جدول کامل دستورات</h2>
|
||
|
||
<table>
|
||
<thead>
|
||
<tr><th>دستور</th><th>توضیح</th></tr>
|
||
</thead>
|
||
<tbody>
|
||
<tr><td><code>xcli new [name]</code></td><td>ساخت پروژهی جدید</td></tr>
|
||
<tr><td><code>xcli g page <name></code></td><td>تولید صفحه</td></tr>
|
||
<tr><td><code>xcli g page <name> --provider</code></td><td>تولید صفحه با منطق Query</td></tr>
|
||
<tr><td><code>xcli g provider-page <name></code></td><td>تولید Provider Page (Explorer/Management)</td></tr>
|
||
<tr><td><code>xcli g view <name></code></td><td>تولید View Component</td></tr>
|
||
<tr><td><code>xcli g service <name></code></td><td>تولید سرویس</td></tr>
|
||
<tr><td><code>xcli g module <name></code></td><td>تولید ماژول با Routing</td></tr>
|
||
<tr><td><code>xcli g dto <name></code></td><td>تولید Dto و Type Guard</td></tr>
|
||
<tr><td><code>xcli g enum <name></code></td><td>تولید Enum با Helper</td></tr>
|
||
<tr><td><code>xcli g config <name></code></td><td>تولید Config و Token</td></tr>
|
||
<tr><td><code>xcli g pipe <name></code></td><td>تولید Pipe</td></tr>
|
||
<tr><td><code>xcli g directive <name></code></td><td>تولید Directive</td></tr>
|
||
<tr><td><code>xcli add plugin <name></code></td><td>افزودن پلاگین Cordova</td></tr>
|
||
<tr><td><code>xcli add package <name></code></td><td>افزودن پکیج npm</td></tr>
|
||
<tr><td><code>xcli build</code></td><td>ساخت پروژه</td></tr>
|
||
<tr><td><code>xcli serve</code></td><td>اجرای سرور توسعه</td></tr>
|
||
<tr><td><code>xcli test</code></td><td>اجرای تستها</td></tr>
|
||
<tr><td><code>xcli config show</code></td><td>نمایش پیکربندی فعلی</td></tr>
|
||
<tr><td><code>xcli config set <key> <value></code></td><td>تنظیم مقدار پیکربندی</td></tr>
|
||
<tr><td><code>xcli env add <name></code></td><td>افزودن Environment جدید</td></tr>
|
||
<tr><td><code>xcli env list</code></td><td>لیست Environmentها</td></tr>
|
||
<tr><td><code>xcli env switch <name></code></td><td>تغییر Environment فعال</td></tr>
|
||
<tr><td><code>xcli doctor</code></td><td>بررسی سلامت محیط</td></tr>
|
||
<tr><td><code>xcli help [cmd]</code></td><td>نمایش راهنمای دستورات</td></tr>
|
||
</tbody>
|
||
</table>
|
||
|
||
<hr/>
|
||
|
||
<h3>12.1. ساختار نهایی پوشهی xCLI</h3>
|
||
<div class="tree">
|
||
<span class="folder">xCli/</span>
|
||
├── <span class="folder">bin/</span>
|
||
│ └── <span class="file">xcli.js</span>
|
||
├── <span class="folder">src/</span>
|
||
│ ├── <span class="file">index.ts</span>
|
||
│ ├── <span class="folder">commands/</span>
|
||
│ │ ├── <span class="file">new.ts</span>
|
||
│ │ ├── <span class="file">generate.ts</span>
|
||
│ │ ├── <span class="file">add.ts</span>
|
||
│ │ ├── <span class="file">config.ts</span>
|
||
│ │ ├── <span class="file">build.ts</span>
|
||
│ │ └── <span class="file">doctor.ts</span>
|
||
│ ├── <span class="folder">generators/</span>
|
||
│ │ ├── <span class="file">new-project.ts</span>
|
||
│ │ ├── <span class="file">page.ts</span>
|
||
│ │ ├── <span class="file">provider-page.ts</span>
|
||
│ │ ├── <span class="file">view.ts</span>
|
||
│ │ ├── <span class="file">service.ts</span>
|
||
│ │ ├── <span class="file">module.ts</span>
|
||
│ │ ├── <span class="file">dto.ts</span>
|
||
│ │ └── <span class="file">... .ts</span>
|
||
│ ├── <span class="folder">lib/</span>
|
||
│ │ ├── <span class="file">logger.ts</span>
|
||
│ │ ├── <span class="file">fs-utils.ts</span>
|
||
│ │ ├── <span class="file">naming.ts</span>
|
||
│ │ └── <span class="file">project-utils.ts</span>
|
||
│ └── <span class="folder">config/</span>
|
||
│ └── <span class="file">xcli.config.ts</span>
|
||
├── <span class="folder">templates/</span>
|
||
│ ├── <span class="folder">default/</span> <span class="comment"># قالب پیشفرض پروژه</span>
|
||
│ ├── <span class="folder">page/</span>
|
||
│ ├── <span class="folder">view/</span>
|
||
│ ├── <span class="folder">service/</span>
|
||
│ ├── <span class="folder">module/</span>
|
||
│ ├── <span class="folder">provider-page/</span>
|
||
│ └── <span class="folder">plugins/</span>
|
||
│ ├── <span class="folder">device/</span>
|
||
│ ├── <span class="folder">splashscreen/</span>
|
||
│ └── <span class="folder">statusbar/</span>
|
||
├── <span class="file">package.json</span>
|
||
├── <span class="file">tsconfig.json</span>
|
||
└── <span class="file">.npmignore</span>
|
||
</div>
|
||
|
||
<hr/>
|
||
|
||
<h3>12.2. راهنمای پیادهسازی سریع (Quick Start)</h3>
|
||
<pre><code># 1) کلون / ساخت پروژه xCli
|
||
mkdir xCli && cd xCli
|
||
npm init -y
|
||
|
||
# 2) نصب وابستگیها
|
||
npm i commander@9 inquirer@8 chalk@4 ora@5 fs-extra@10 handlebars@4 execa@5
|
||
npm i -D typescript@4.2 @types/node@14 @types/fs-extra@9
|
||
|
||
# 3) ساخت فایلهای بالا (index, commands, generators, templates)
|
||
# ...
|
||
|
||
# 4) Build
|
||
npm run build
|
||
|
||
# 5) Link
|
||
npm link
|
||
|
||
# 6) تست
|
||
xcli new demo-app
|
||
cd demo-app
|
||
xcli g page dashboard --provider
|
||
xcli add plugin device
|
||
xcli doctor
|
||
xcli build --prod</code></pre>
|
||
|
||
<div class="note success">
|
||
<div class="emoji">🎉</div>
|
||
<div>
|
||
در پایان این مستند، شما یک ابزار CLI کامل بهنام <code>xcli</code> خواهید داشت که قادر است پروژههای xFramework را
|
||
با همان ساختار <code>xClient</code> بسازد، صفحات و Viewها و سرویسها را استاندارد تولید کند، پلاگینهای Cordova را اضافه کند،
|
||
پیکربندی را مدیریت کند و فرآیند Build/Test را پوشش دهد.
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
</main>
|
||
</div>
|
||
|
||
<footer>
|
||
📘 مستندات فنی xCLI — تولید شده بر اساس تحلیل پروژه <code>xClient</code> و جستجو در منابع xFramework
|
||
<br/>
|
||
<small>محدودیت نسخهها: @angular/cli@12.0.4 · @ionic/cli@6.6.0 · Node v14.17.3</small>
|
||
</footer>
|
||
|
||
</body>
|
||
</html> |