Version 0.2.0 #1

Merged
vilor merged 3 commits from dev into master 2 years ago
  1. 22
      .drone.yml
  2. 35
      README.md
  3. 2
      package.json
  4. 59
      src/loader.js

22
.drone.yml

@ -0,0 +1,22 @@
kind: pipeline
type: docker
name: production
when:
event: [ push ]
branch: [ master ]
trigger:
branch:
- master
steps:
- name: publish
image: plugins/npm
settings:
username: vilor
password:
from_secret: npm_password
email:
from_secret: npm_email
token:
from_secret: npm_token

35
README.md

@ -1,5 +1,6 @@
sxml-loader sxml-loader
=========== ===========
[![Build Status](http://drone.vilor.one/api/badges/vilor/sxml-loader/status.svg)](http://drone.vilor.one/vilor/sxml-loader)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
<div align="center"> <div align="center">
@ -11,18 +12,9 @@ sxml-loader
Scheme XML loader for webpack. Scheme XML loader for webpack.
**NOTE**:
At the moment, the _sxml-loader_ only works with
[Chicken Scheme](http://call-cc.org/) and its
[sxml-serializer](http://wiki.call-cc.org/eggref/5/sxml-serializer)
egg, so you need to install them in order to use the _sxml-loader_.
Usage Usage
----- -----
**SXML**: _See the full example in the [example](example) directory._
```scm
'(h1 "Hello")
```
**webpack.config.js**: **webpack.config.js**:
```js ```js
@ -40,6 +32,29 @@ module.exports = {
} }
``` ```
By default SXML will be processed by _Chicken Scheme_
with _sxml-serializer_ egg. You can use a different interpreter
by setting the loader options.
GNU Guile example:
```js
// ...
use: [
'html-loader',
{
loader: 'sxml-loader',
options: {
interpreter: 'guile',
flags: ['-c'], // "eval" flag (in Guile case "-c") should be last.
// SXML_LOADER_CONTENT will be replaced with processing SXML markup.
expr: '(use-modules (sxml simple))(sxml->xml SXML_LOADER_CONTENT)',
},
},
],
// ...
```
License License
------- -------
GPLv3 or later. See full text in the [COPYING](COPYING) file GPLv3 or later. See full text in the [COPYING](COPYING) file

2
package.json

@ -1,6 +1,6 @@
{ {
"name": "sxml-loader", "name": "sxml-loader",
"version": "0.1.0", "version": "0.2.0",
"description": "Scheme XML loader for webpack", "description": "Scheme XML loader for webpack",
"main": "src/loader.js", "main": "src/loader.js",
"bugs": "http://git.vilor.one/vilor/sxml-loader/issues", "bugs": "http://git.vilor.one/vilor/sxml-loader/issues",

59
src/loader.js

@ -1,17 +1,64 @@
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// Copyright 2022 Ivan Polyakov // Copyright 2022 Ivan Polyakov
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const { validate } = require('schema-utils');
const schema = {
type: 'object',
properties: {
interpreter: {
type: 'string',
default: 'chicken-csi',
},
flags: {
type: 'array',
default: ['-e'],
},
expr: {
type: 'string',
default: '(import sxml-serializer)(display (serialize-sxml SXML_LOADER_CONTENT))',
},
},
};
module.exports = function(content, map, meta) { module.exports = function(content, map, meta) {
const cb = this.async(); const options = this.getOptions();
const expr = `(import sxml-serializer)(display (serialize-sxml ${content}))`; validate(schema, options, {
const scheme = spawn('chicken-csi', ['-e', expr]); name: 'SXML Loader',
baseDataPath: 'options',
});
let interpreter = schema.properties.interpreter.default;
if (options.interpreter)
interpreter = options.interpreter;
let flags = schema.properties.flags.default;
if (options.flags)
flags = options.flags;
scheme.stdout.on('data', data => { let expr = schema.properties.expr.default;
if (options.expr)
expr = options.expr;
expr = expr.replace('SXML_LOADER_CONTENT', content);
flags.push(expr);
const cb = this.async();
runScheme(interpreter, flags).then(data => {
cb(null, data, map, meta); cb(null, data, map, meta);
}).catch(err => {
console.error(err);
}); });
}
function runScheme(interpreter, flags) {
return new Promise((resolve, reject) => {
const scheme = spawn(interpreter, flags);
scheme.stderr.on('data', data => { scheme.stdout.on('data', (data) => {
console.error(data); resolve(data);
});
scheme.stderr.on('data', (data) => {
reject(data.toString());
});
}); });
} }

Loading…
Cancel
Save