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');