0.0.5 • Published 3 years ago

lvd-fluentui-component-scaffolding v0.0.5

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
3 years ago

FluentUI Component Scaffolding

NPM

This is a nodejs application to generate the basic structure of a React component built using the FluentUI library, including the scripts and configuration requried for publishing it to the npm package repository. This tool uses a built-in template directory, collects some additional data, such as package name, library name, package author and creates:

  • the basic directory structure;
  • build scripts, package.json, webpack configuration files, license file and a standard .gitignore;
  • empty component file;
  • empty stylesheet files;
  • basic structure of a demo application to feature the component.

It also runs npm install after the package structure has been created.

Installing

npm install --g lvd-fluentui-component-scaffolding

Usage

Navigate to the root directory where your component will be created and run:

npm exec create-fluentui-component

You will then be prompted for additional information, which is further detailed below.

Demo

Below you can find a screen capture of running this tool with the following arguments:

  • --create-root
  • --skip-deps
  • --git-clone-repo="[repo-url]"
  • --git-push

Sample run

Command line arguments

ArgumentTypeDescription
--versionbooleanShow version number
--from-manifest, --fmbooleanRead package information from a manifest file named component-manifest.json in the base destination directory. Defaults to false.
--create-root, --crbooleanCreate root component directory. Defaults to false, that is use current working directory as root.
--skip-deps, --sdbooleanDo not run npm install afer the component package has been created. Defaults to false.
--skip-vscode, --svsbooleanDo not create the .code-workspace VS Code workspace file, even if it is included in the template. Defaults to false.
--git-clone-repo, --gcrbooleanClone the specified directory before creating the component package. Will fail if directory is not empty. Defaults to null.
--git-commit, --gcmbooleanPerform a git commit after creating the component package. You will be prompted for an optional commit message. Defaults to false.
--git-push, --gcmbooleanPerform a git commit and push after creating the component package. If this flag is specified, the git-commit flag is not required. Defaults to false.
--git-name, --gnmbooleanConfigure git operations to use this author name. Defaults to null.
--git-email, --gembooleanConfigure git operations to use this author email. Defaults to null.
--git-username, --gurbooleanConfigure git operations to use this username when logging on. Defaults to null.
--git-token, --gtkbooleanConfigure git operations to use this token as password when logging on. Defaults to null.
--log-directory, --ldstringSpecify log directory name. Defaults to package_builder_logs.
--worskpace-directory, --ldstringSpecify workspace directory name. Defaults to workspace.
--additional-dirs, --ldstring[]Specify additional directories to be created alongside the workspace directory. Defaults to []. Example: --additonal-dirs dira dirb dirb/dirb1 dirc.
--helpbooleanShow help

Required user input

The following parameters are collected from user input:

ParameterDescriptionMandatoryDefaultValid values
Package nameThe name of the package. The name used in package.json is obtained from this value, converted to lower caseYIf --create-root is not specified, then the default package name is the name of the current directory, if considered valid.letters, numbers and dashes
Package descriptionThe description of the packageN--
Package authorThe author of the packageN--
Libary nameThe name of the root component; also the name used for the library configuratin in the webpack config file.NThe part of the package name following the last dash.letters, numbers and underscores
Library name, dashed formThe name of the root component in dashed form.NDerived from the library name.letters, numbers and dashes

Output structure

The following output structure is all relative to the workspace directory.

The directory structure

The following directory structure is generated within:

DirectoryDescription
demoDemo application root directory
demo/build/appDemo application build output directory
distComponent library build output
docsDocumentation files
srcRoot directory for all component library source files
src/assetsAssets directory (eg. image files)
src/componentsComponent javascript source code
src/cssRoot directory for all stylesheet files
src/css/componentsComponent-related stylesheet files
src/docsDocumentation source files

Support files

The following support files are generated (configuration files, build scripts, license):

FileDescription
LICENSELicense file - BSD 3-clause by default
.gitignoreThe git-ignore file, which, by default, contains entries for node_modules directory and *.tgz files
package.jsonThe package.json file, with a bunch of stuff already added to it, including standard dependencies and dev-dependencies.
README.mdThe readme file file, with the package title and package description added to it.
webpack-app.config.jswebpack configuration file for building the demo application
webpack-dist.config.jswebpack configuration file for building the library itself for distribution via npm packaging
build-all.ps1PowerShell script for building the demo app and the library itself in one sitting
build-app.ps1PowerShell script for building the demo app
build-dist.ps1PowerShell script for building the library itself
${PackageName}.code-workspaceVS Code workspace file. The ${PackageName} placeholder is replaced with the value collected (or derived) from user input.

Component files

The following javascript files are generated for the library-related component:

FileDescription
src/components/${LibraryName}.jsxThe main component file, that contains an empty component class definition. The ${LbraryName} placeholder is replaced with the value collected (or derived) from user input.
src/components/Index.jsThe root export file that will be used as an entry point when building the library itself.

The following javascript files are generated for the demo application-related components:

FileDescription
src/App.jsxThe actual demo application main component
src/Root.jsxSets up the root component structure, including the stuff required for FluentUI apps
src/Index.jsxSets up the who react application lifecycle

Stylesheet files

The following stylesheet files are generated for the library-related component:

FileDescription
src/css/components/${LibraryNameDashed}.cssThe main component stylesheet file. The ${LibraryNameDashed}.css placeholder is replaced with the value collected (or derived) from user input.
src/css/components/index.cssThe root file that will be used as a stylesheet entry point when building the library itself.

The following stylesheet files are generated for the demo application:

FileDescription
src/css/style.cssThe maine demo app stylesheet file. Contains some standard includes, as well as basic rules.

Demo application

The following files are generated in order to run the built demo application:

FileDescription
demo/index.htmlThe html entry point for the demo application. Either run it directly or deploy it somewhere.

Supported placeholders

The following placeholders are supported for usage both in file names, as well as file contents:

PlaceholderValue
${LibraryName}Library name
${LibraryNameDashed}Library name, dashed form
${PackageName}Package name
${PackageNameLower}Package name, converted to lower case
${PackageDescription}Package description
${PackageAuthor}Package author
${CurrentYear}new Date().getFullYear()
${LogDirectoryName}Log directory name as provided via command line arguments. Defaults to _logs

Generated log files

The tool generates the following log files:

  • [LOG_DIRECTORY_PATH]/error.log - for error events: exceptions, errors coming from the git engine, erros from the npm install stderr output;
  • [LOG_DIRECTORY_PATH]/activity.log - for every other stuff that's being logged - debug messages, warning messages, info messages and so on.

As of version 0.0.5, the [LOG_DIRECTORY_PATH] is located at [USER_HOME]/lvd-fluentui-component-scaffolding/[LOG_DIRECTORY_NAME] where:

  • [USER_HOME] depends on the os;
  • [LOG_DIRECTORY_NAME] defaults as mentioned above, but may be overridden using the --log-directory flag.

Notes

  1. To avoid having npm pack strip the empty directories, a .dummy file is included in each template directory. This does not find its way in the final component package directory.
  2. To avoid having npm pack rename the .gitignore file in the template directory to .npmignore, the file is included using the .ignore name and renamed when when creating the final component package directory.

Changelog

Version 0.0.5

  • Default directory name is now package_builder_logs;
  • Changed logging directory location: logs are now saved globally in [USER_HOME]/lvd-fluentui-component-scaffolding/[LOG_DIRECTORY_NAME] where: - [USER_HOME] depends on the os; - [LOG_DIRECTORY_NAME] defaults as mentioned above, but may be overridden using the --log-directory flag.
  • Changed package structure to include a workspace directory used for the component package itself, to avoid issues when a git clone needs to be performed but, at the same time, the --from-manifest flag is used.
  • Added possibility to create additional directories alongside the package workspace, using the --additional-dirs flag.

Version 0.0.4

  • Fixed an issue with logging throwing .trim() is not a function in certain conditions.
  • Updated package description and home page in package.json.

Version 0.0.3

  • Can now read package information from a manifest file placed in the base target directory (see above). By default it reads from console user input, use --from-manifest to switch to package manifest mode;
  • Added option to skip installing dependencies by automatically running npm install. By default, dependencies are installed, use --skip-deps to skip installation;
  • Added .code-workspace template file in the package template and an option to skip creating it, if desired, by specifying the --skip-vscode flag;
  • Can now clone a git repository before creating component package, by using --git-clone-repo=[repo-url];
  • Can now commit to the previously cloned git repository after component si created, by using the flag --git-commit;
  • Can now push to the previously cloned git repository after component si created, by using the flag --git-push;
  • Basic git configuration can be specified by using the flags: --git-name, --git-email, --git-username and --git-token;
  • Better error handling;
  • More detailed and better formatted output of executed steps;
  • Major refactoring and some bug fixes.

Version 0.0.2

  • Can now specify whether or not to create a root directory for the package. By default it does not, use --create-root flag to create it.

Version 0.0.1

  • First tracked version

Donate

I put some of my free time into developing and maintaining this plugin. If helped you in your projects and you are happy with it, you can...

ko-fi