Skip to content

debitoor/nocms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOCMS

"NO, You don't need a CMS" is what you are going to tell your boss the next time he comes running waving his arms and yelling incomprehensibly about some new microsite for his wife's pony he wants to make in drupal, wordpress or any of the 1 billion other "let's stuff all your content in a mysql database and front it with some 10 year old php scripts" things that pop up in your facebook feed disguised as content.

Build Status NPM Version

Install

$ npm install nocms --save

Plugins by @debitoor

CLI Usage

Compile

Compiles all resources in the input directory and writes them to the output directory.

$ nocms compile --in-dir ./src/ --out-dir ./compiled/

Server

Runs a webserver on the port given and compiles resources in the input directory and writes them to the output directory before serving them to the user.

$ nocms server --in-dir ./src/ --out-dir ./compiled/ --port 1234

NOCMS is multithreaded and spins of one worker instance for each cpu as reported by os.cpus().

Plugins

A Plugin is any module that exports an activate function that when invoked registers one or more providers.

export function activate (pluginActivationContext)

Plugins installed in node_modules will be activated automatically.

pluginActivationContext

The plugin activation context gives plugins access to provider registration and to IO functions bound to the input and output directories.

  • findFiles
  • readFile
  • registerResourceProvider
  • watchFiles
  • writeFile

findFiles

Finds files relative to the input directory. Returns a Promise that resolves with an Array of file paths relative to the input directory.

async function findFiles (pattern, options)

Parameters:

  • pattern: Glob pattern,
  • options: Glob options

readFile

Asynchronously reads the contents of a file relative to the input directory. Returns a Promise that resolves with the contents of the file, a String or a Buffer.

async function readFile (file, options)

Parameters:

  • file: File path relative to the input directory
  • options: Same as when calling fs.readFile

registerResourceProvider

Registers a resource provider with NOCMS. See Resource Provider.

function registerResourceProvider (resourceProvider)

Parameters:

  • resourceProvider: An instance of a resource provider

watchFiles

Watches files relative to the input directory. Returns a chokidar instance.

function watchFiles (pattern, options)

Parameters:

  • pattern: Glob pattern
  • options: Chokidar options

writeFile

Asynchronously writes a file to the output directory. Automatically creates any missing parts of the file path before writing the file. Returns a promise.

async function writeFile (file, data, options) {}

Parameters:

  • file: file path relative to the output directory.
  • data: String or Buffer
  • options: Same as fs.writeFile

Example:

let html = '<html></html>';
await writeFile('index.html', html, 'utf8');

Resource Provider

Resource Providers are responsible for collecting meta data for, and compiling resources. A resource provider has two functions:

getResources

Asynchronously provides an Array of resource objects. A resource must as a minimum have an id field.

async function getResources ()

compileResource

Asynchronously compiles a resource object and writes the result to the file system. Returns a Promise that resolves with undefined.

async function compileResource (resource, resourceCompilationContext)

Parameters:

  • resource: a resource object
  • resourceCompilationContext: a resource compilation context.

Resource Compilation Context

The resource compilation context is an object with two fields.

  • resourceMap: a id/resource map of all resources from all resource providers
  • resourceTree: a resource tree of all resources from all resource providers

The resource compilation context can be used to provide resource meta data to templates during compilation.

Config

Configurations can be written in a .nocmsrc file at the root of the project, and will be served as json to plugins.

Develop

Bootstrap

Run lerna bootstrap

$ npm run bootstrap

Build

$ npm run build

Test

$ npm test

The end to end tests (rather integration than e2e) are in the root of the project in example-sites and make use of lerna to link the local modules, so if they are built, they are immediately tested as the newest version, as they are a symlink.

The expected rendered HTML/CSS/JS will be compared to the actually produced output.

License

MIT License

Copyright (c) 2017 Debitoor

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.