How sdc-alibaba/sui-mobile works
Project Type and Purpose
• This is an open-source, lightweight mobile UI component library (SUI Mobile) for building hybrid or web-based mobile apps.
• It combines CSS (LESS) themes and JavaScript modules (built on Zepto, FastClick, iScroll, etc.) to provide pre-built UI widgets (tabs, modals, forms, pickers, etc.).
• It also includes full documentation, demos, examples, and a test suite.
High-Level File Structure Analysis
• Root: build configs (Gruntfile.js), package.json, lint settings, CONTRIBUTING.md, develop.md.
• src layers:
• less/ – all UI component styles in .less (accordion.less, buttons.less, etc.).
• js/ – component scripts and utilities (router.js, modal.js, pull-to-refresh.js, util.js, zepto-adapter.js).
• dist/ – compiled/minified outputs ready for CDN or npm (dist/css/*.css, dist/js/*.js).
• docs/ – Jekyll-style documentation site (layouts, includes, demos, examples, assets).
• js/tests/ – browser-based unit tests (via PhantomJS).
• examples/ – standalone HTML/CSS/JS demos showing integration.
README Insights
• Emphasizes design inspiration (Framework7, Ratchet, Ionic) and CDN distribution.
• Invitation for issues/PRs; link to develop.md for contribution guidelines.
Main Components
a. Source Modules
• LESS source (UI component styles)
• JS source (widget logic + utilities + adapters)
b. Build System & Pipeline
• Grunt tasks: compile LESS → CSS, lint JS, concatenate/minify JS, generate dist artifacts.
• NPM scripts / package.json references.
c. Distribution Artifact
• dist/css/sm.css, sm-extend.css
• dist/js/sm.js, sm-extend.js, sm-city-picker.js
• Published to GitHub Pages / CDN / npm registry
d. Documentation Site
• Jekyll engine (_config.yml, _layouts, _includes, .md pages) → static site in docs/
• Assets: docs/assets/css, js, img
• Demos: docs/demos, docs/examples
e. Example Integrations
• Standalone HTML + CSS + bundled JS examples in docs/examples/baichuan
f. Testing
• js/tests/unit using PhantomJS (unit tests for JS components)
Interactions and Data Flows
• Developer edits source (less/ or js/) → triggers Grunt → outputs dist/
• dist/ artifacts feed into:
• Documentation demos (docs/assets or via CDN)
• Example pages (docs/examples)
• NPM/npm publish & CDN distribution
• Jekyll build uses docs/ source + dist artifacts to produce the live docs site
• Test runner pulls JS source (or dist) to validate widget behavior
• External services: GitHub for code & issues, npm registry, Alibaba CDN, Travis CI (if present)
Architectural Patterns and Principles
• Modular front-end architecture: one folder per UI component (both LESS & JS).
• Build → dist separation: clean separation of source vs. distributable.
• Documentation as first-class citizen: Jekyll templating for reusability of components in docs.
• Extensibility points: “extend” variants (sm-extend.css/js), plug-in hooks in router, pull-to-refresh.
Essential Elements to Capture
• Source modules separated by technology (LESS vs. JS)
• Build configuration (Gruntfile.js) and its tasks
• Output artifacts and their destinations (CDN, docs, npm)
• Documentation and demo generation path
• Testing harness for maintaining quality
• External dependencies (Zepto, FastClick, iScroll)