1.0.0-beta.1 • Published 4 months ago

@specifyapp/node-utils v1.0.0-beta.1

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

Specify Node utils

Overview

This package aims to provide NodeJS utilities for the Specify SDK.

Getting Started

Prerequisites

  • Javascript ESM compatible runtime (browser or NodeJS)
  • Optional Typescript >= 4.9

Installation

npm install @specifyapp/node-utils @specifyapp/sdk

File System Helper

The createSpecifyFileSystemHelper function allows you to write the files generated by the Specify Pipe Engine API to disk.

import {createSpecifyClient} from '@specifyapp/sdk';
import {createSpecifyFileSystemHelper} from '@specifyapp/node-utils';

const specifyClient = createSpecifyClient();

await specifyClient.authenticate('your-personal-access-token');

const repositoryTokenTree = await specifyClient.getRepositoryTokenTreeByName('your-repository');

const pipeEngineRuleResponseBody = await repositoryTokenTree.transformWithRemoteParsers([
  {
    name: 'to-css-custom-properties',
    output: {type: 'file', filePath: 'tokens.css'},
  },
]);

const fileSystemHelper = createSpecifyFileSystemHelper({
  pipeEngineRuleResponseBody
});

const writtenFiles = await fileSystemHelper.writeToDisk('./public');

console.log(writtenFiles); // ['public/tokens.css']

Manipulate the files before writing them to disk

The mapFiles method allows you to manipulate the files before writing them to disk. Any post-process like minification, formatting, etc. can be done here.

const writtenFiles = await fileSystemHelper
  .mapFiles(file => {
    if (file.path === 'colors.css' && file.content.type === 'text') {
      return {
        ...file,
        content: {
          type: 'text',
          text: file.content.text.replaceAll(';', ' !important;'),
        },
      };
    }
  })
  .writeToDisk('./public');
1.0.0-beta.2

4 months ago

1.0.0-beta.1

4 months ago