Have you ever wondered about the yeoman and the genererator-csui-extension? And whats going up in the somewhat bumpy installation and generation of a project dir? This are the Yeoman & generator-csui-extension secrets.
Yeoman & generator-csui-extension secrets: Lets unveil this secrets
First, recap the installation steps from scratch:
- Download and install node.js Version 11.15.0 (In you try a newer version, you will be rewarded by the famous primordials not defined error on starting yo, see this post )
- Set npm (part of node.js) to npm version 3 globally (npm install -g npm@3 (I am using 3.3.10)
- Install the grunt cli globally (npm install -g grunt-cli@1)
- Optional path: Unpacking the sdk and setting up the sampes)
- Unpack the SDK in a folder (p.ex. sdk)
- go inside this folder
- Use npm to install all requirements (npm install)
- Then you can start the internal webserver (Default under post 7777) by npm start and browse to sample-index.html inthis dir. Here you will get a listing of certain samples.
- The doc folder contains a very basic documentation of the smartUI SDK
- But for practical work, you need to gererate at least one project folder. This is a complete structure, containing the actual sdk and a place to build your own packages. So lets generate a project folder named project
- Preparation, only to do once
- unpack the gererator-csui-extension to a dedicated folder (p.ex. generator)
- While not(!) in this folder, install yeoman globally (npm install -g yo@1)
- go inside the folder generator
- link this as an extension to npm (npm link)
- Lets generate the project folder
- make the folder named project
- go inside the folder named project. Its empty
- Start yo to execute the csui-extension (yo csui-extension)
- you need to define the name of your oscrippt module and the requirejs base name. Then its doing a lot.
- Now your project is really full. You can optionally add a demo widget (yo csui-extension:widget)
- Now, build the project (grunt)
- Preparation, only to do once
Ok, now the project folder project is operable. Lets take a close look on the generator.
(Remark: The versions mentioned are the working versions in my dev machines. Other, newer versions may work, but this is not guaranteed.)
Close Look at the Generator
When you do a npm link, a symbolic link is is build from the folder to [roaming dir]\npm\node_modules\generator-csui-extension.
So the extension folder is used as input for the yo execution.
Our Generator source folder looks like
The app folder here is interesting
First lets take a look on the rest of the templates folder
Here we see, we have the same structure as lib…. in the sdk. SO the complete SDK is copied fron the generator folder to the project dir unter lib. There is no need to use the sdk folder (except for docs and samples)
A closer look at index.js (Excerpt). This file is executed during “yo csui-extension”.
Here you see, the whole structure is copied directly from the templates folder to the destination project. All contents in this templates folder are later in the project folder.
A closer look at package.js
The package.json contains as always the definition of this generator extension like, name, description and depedencies of this extension.
Areas for Customizations are at this areas (for example):
- Custom gruntfiles, which shoulkd apprear in all new generated project folders
- A different setup for the linters which should apprear in all new generated project folders
- Added libraries
- Added documentation structures
How to do this
Simply modify the generatot folder, add your customizations and modifications. You can save this folder as .zip to distribute internal standards.