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

node-matrix-importer

v1.2.0

Published

Generate XML for the "Import Assets from XML Tool" with JavaScript!

Downloads

10

Readme

node-matrix-importer

Generate XML for the "Import Assets from XML Tool" with JavaScript!

Build Status js-standard-style

Motivation

node-matrix-importer aims to provide a utility for both generation and optimization of asset XML manifests as expected by Squiz Matrix' "Import Assets from XML Tool".

Currently the only way of generating an import.xml is either by exporting an asset tree from Squiz Matrix, or writing your own by hand. Whilst the latter isn't unreasonable (it's only XML after all) it's far from practical.

An exported asset tree can potentially consist of hundreds of interwoven typically synchronous operations, as a result the import tool typically gets overlooked as a tool for automation, or even maintenance of Squiz Matrix implementations.

Goals

  • Unlock the true potential of the "Import Assets from XML Tool".
  • Provide programatic API for generating asset import.xml manifests.
  • Optimize import.xml manifests by batching various operations.
  • Parse exported asset trees for local replication, thus enabling offline development.
  • Investigate alternate uses for the "Import Assets from XML Tool". eg. update assets from XML.

Example

var Importer = require('node-matrix-importer')
var xml = Importer()

var rootFolder = xml.createAsset({
  parentId: 1,
  type: 'folder'
})
var mySite = xml.createAsset({
  parentId: rootFolder.id,
  type: 'site'
})

xml.setAttribute({
  assetId: rootFolder.id,
  attribute: 'name',
  value: 'Sites'
})

xml.setAttribute({
  assetId: mySite.id,
  attribute: 'name',
  value: 'My Site'
})

console.log(xml.toString())

API

Importer

node-matrix-importer provides an API for generating XML for the "Import Assets from XML Tool" via require('node-matrix-importer').

var importer = new Importer(opts)

The opts argument accepts an object with the following properties:

  • opts.sortActions: whether Actions should be sorted into an internal collection. Default: false

importer.addPath(opts)

The opts argument accepts an object with the following properties:

  • opts.id
  • opts.path
  • opts.assetId

Internally this is a helper around importer.addAction('add_path', opts);.

For more information on Actions refer to the node-matrix-import-actions module.

importer.createAsset(opts)

The opts argument accepts an object with the following properties:

  • opts.id
  • opts.parentId
  • opts.file
  • opts.type
  • opts.link
  • opts.value
  • opts.dependant
  • opts.exclusive

Internally this is a helper around importer.addAction('create_asset', opts);, or importer.addAction('create_file_asset', opts); if opts.file is set.

Refer to the importer.addAction section for more information.

The returned object will additionally have an action.id propterty; action.id in this case is a String in the form of '#{id}', where id is a unique identifier.

This is useful should you later wish to retrieve the action object via importer.getActionById(action.id).

importer.createLink(opts)

The opts argument accepts an object with the following properties:

  • opts.to
  • opts.from
  • opts.link
  • opts.value
  • opts.dependant
  • opts.exclusive
  • opts.major

Internally this is a helper around importer.addAction('create_link', opts);.

Refer to the importer.addAction section for more information.

importer.setAttribute(opts)

The opts argument accepts an object with the following properties:

  • opts.id
  • opts.assetId
  • opts.attribute
  • opts.value

Internally this is a helper around importer.addAction('set_attribute', opts);.

Refer to the importer.addAction section for more information.

importer.setParseFile(opts)

The opts argument accepts an object with the following properties:

  • opts.id
  • opts.assetId
  • opts.file

Internally this is a helper around importer.addAction('set_design_parse_file', opts);.

Refer to the importer.addAction section for more information.

importer.setMetadataSchema(opts)

The opts argument accepts an object with the following properties:

  • opts.id
  • opts.assetId
  • opts.schemaId
  • opts.granted
  • opts.cascade

Internally this is a helper around importer.addAction('set_metadata_schema', opts);.

Refer to the importer.addAction section for more information.

importer.setMetadataValue(opts)

The opts argument accepts an object with the following properties:

  • opts.id
  • opts.assetId
  • opts.fieldId
  • opts.value

Internally this is a helper around importer.addAction('set_metadata_value', opts);.

Refer to the importer.addAction section for more information.

importer.setPermission(opts)

The opts argument accepts an object with the following properties:

  • opts.assetId
  • opts.permission
  • opts.muteError
  • opts.granted
  • opts.userId

Internally this is a helper around importer.addAction('set_permission', opts);.

Refer to the importer.addAction section for more information.

importer.addAction(type, opts)

The importer.addAction method is responsible for creating and assigning new Actions to the importer internal collection.

The type argument describes the type of action to create, and can be any action type as supported by node-matrix-import-actions. Additionally, the opts argument expects an object as appropriate to the defined action type.

Returns a new Action instance: new Action(type, opts);.

For more information on Actions refer to the node-matrix-import-actions module.

importer.getActionById(id)

The id argument accepts a String in the form of '#{id}' where id corresponds to an Action created with importer.createAsset(type, opts).

Returns the matching Action instance, or undefined if an Action with the supplied id wasn't found.

importer.toString(opts)

node-matrix-importer internally manages a collection of actions created by calling the above methods. At any point you can get a full XML representation of them by calling toString() on your Importer instance.

The opts argument controls the formatting of the output XML.

  • opts.pretty: pretty print XML. Default: true
  • opts.indent: whitespace for indentation (only if opts.pretty = true. Default: ' '
  • opts.newline newline character (only if opts.pretty = true. Default: '\n'

License

MIT