npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-contensis-sync

v1.0.6

Published

A Gulp plugin that allows you to push local files into your Contensis instance

Downloads

2

Readme

contensis plugin for gulp

Usage

First, install gulp-contensis-sync as a development dependency:

npm install --save-dev gulp-contensis-sync

Then, add it to your gulpfile.js:

var gulpContensisSync = require('gulp-contensis-sync');

gulp.task('sync-contensis', function() {

  // create a new contensisSync using options
  var contensisSync = gulpContensisSync.create({
	"user": "user",
	"password": "pass",
	"cmsUrl": "http://contensis-cms-url",
	"project": "Project Name"
    });

  var options = { simulate: true, prefix: 'atlas'}

  return gulp.src('./public/*.js')
    .pipe(contensisSync.transfer(options))

    // create a cache file to speed up consecutive uploads
    .pipe(contensisSync.cache())

     // Sync Directories, this will delete files at the other end.
    .pipe(contensisSync.sync(options))

     // print updates to console
    .pipe(gulpContensisSync.reporter());
});

// output
// [gulp] [create] file1.js
// [gulp] [create] file2.js
// [gulp] [update] file3.js
// [gulp] [cache]  file3.js
// ...

To run the deploy:

gulp sync-contensis

API

gulpContensisSync.create(Config, cacheOptions)

Create a Contensis Sync Instance.

The Config object is used to create a REST connection to Contensis. The cacheOptions object allows you to define the location of the cached hash digests. By default, they will be saved in your projects root folder in a hidden file called '.contensissync-' + 'name-of-your-project'.

For best practice you should add your contensis credentials to a json file:

{
	"user": "user",
	"password": "pass",
	"cmsUrl": "http://full-cms-url",
	"project": "Project Name"
}

You can then read it in with:

var fs = require('fs')
//Remember to add your contensis-credentials.json to your .gitignore, so no one else can use your details!
var credentials = JSON.parse(fs.readFileSync('../contensis-credentials.json', 'utf8'))
//Now you can create the object using the credentials
var contensisSync = gulpContensisSync.create(credentials);

contensisSync.transfer([options])

Create a through stream, that transfers files to Contensis.

  • options: optional additional transfer options
    • force: bypass cache / skip
    • simulate: debugging option to simulate Contensis upload
    • prefix: The destination path to send the files
    • createOnly: skip file updates
    • submit: Boolean to indicate if you want the content submitted for approved.
    • approve: Boolean to indicate if you want the content pushlished live and approved. You must submit it first though!

Files that go through the stream receive extra properties:

  • info.path: contensis path
  • info.ETag: file ETag (this is the MD5 has of the file, use to determine if changes have occured to the file)
  • info.state: publication state (create, update, delete, cache or skip)

Note: transfer will never delete files remotely. To clean up unused remote files use sync.

contensisSync.cache()

Create a through stream that create or update a cache file using file path and file ETag.

Consecutive runs of transfer and sync will use this file to avoid uploading identical files over and over.

Cache file is save in the current working dir and is named .contensissync-<projectName>. The cache file is flushed to disk every 10 files just to be safe.

Bear inb mind you may not want to use this if there are multiple people working, The sync is intelligent and will only upload changed files regardless of the cache.

contensisSync.sync([prefix], [whitelistedFiles])

create a transform stream that delete old files from Contensis.

  • options: optional additional sync options
    • simulate: debugging option to simulate Contensis upload (if you dot specify this it will default to simulate to prevent disasters)
    • prefix: prefix to sync a specific directory, if this is not provided you could delete an entire project!
  • whitelistedFiles: array that can contain regular expressions or strings that match against filenames that should never be deleted from Contensis.

e.g.

// only directory bar will be synced
// files in folder /foo/bar and file baz.txt will not be removed from Contensis despite not being in your local folder
var options = { simulate: false, prefix: 'atlas'}
gulp.src('./public/*')
  .pipe(contensisSync.transfer(options))
  .pipe(contensisSync.sync(options, [/^foo\/bar/, 'baz.txt']))
  .pipe(gulpContensisSync.reporter());

warning sync will delete files in your Contensis instance that are not on your local folder unless they're whitelisted.

// this will transfer and sync files with the files in your public directory
// note that in Contensis the files in /public/ would end up directly in the root as we have provided no prefix.
var options = { simulate: false, prefix: ''}
gulp.src('./public/*')
  .pipe(contensisSync.transfer(options))
  .pipe(contensisSync.sync(options))
  .pipe(gulpContensisSync.reporter());

// output
// [gulp] [create] file1.js
// [gulp] [update] file2.js
// [gulp] [delete] file3.js
// ...

contensissync.reporter([options])

Create a reporter that logs info.path and info.state (delete, create, update, cache, skip).

Available options:

  • states: list of state to log (default to all)
// this will transfer local files and then sync to Contensis and print created, updated and deleted files
var options = { simulate: false, prefix: 'atlas'}
gulp.src('./public/*')
  .pipe(contensisSync.transfer(options))
  .pipe(contensisSync.sync(options))
  .pipe(gulpContensisSync.reporter({
      states: ['create', 'update', 'delete']
    }));

License

MIT License