https://github.com/yankeguo-deprecated/scriptlet-5119c630
MIGRATED TO guoyk93/scriptlet
https://github.com/yankeguo-deprecated/scriptlet-5119c630
Last synced: about 2 months ago
JSON representation
MIGRATED TO guoyk93/scriptlet
- Host: GitHub
- URL: https://github.com/yankeguo-deprecated/scriptlet-5119c630
- Owner: yankeguo-deprecated
- License: mit
- Created: 2018-01-21T02:12:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-23T21:38:22.000Z (over 7 years ago)
- Last Synced: 2025-02-14T16:58:30.446Z (3 months ago)
- Language: TypeScript
- Homepage: https://github.com/guoyk93/scriptlet
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# scriptlet
[](https://travis-ci.org/yankeguo/scriptlet)
scriptlet engine for node.js
## What is a Scriptlet?
A **scriptlet** is a piece of JavaScript code that could finish running in finite time.
These kinds of code can be regarded as **scriptlet**
* definition of a object / function / scalar constants
* copy a file to another folder
* connect to redis server and set a value
* fetch a web page and save it to a databaseThese kinds of code can NOT be regarded as **scriptlet**
* a web server
* a job server## How to define and run a **scriptlet**
Unlike standard Node.js module, **scriptlet** are defined in `AMD` style.
You can easly run a **scriptlet** via this package.
```javascript
// helper.js
//
// this defines a static objectdefine({
log(message) {
console.log(message)
}
})// rm.js
//
// this defines a async function, will be evaluated while running// 'fs-extra' is a standard node.js module
// './helper' is a relative scriptlet file defined above
// '$in' is a injected value upon running, see 'index.js'
define('fs-extra', '../helper', '$in', async function(fs, helper, $in) {
helper.log(`unlinking file ${$in}`)
await fs.unlink($in)
})// index.js
//
// this runs the scriptlet rm.js with $in injected
const scriptlet = require('scriptlet')
const path = require('path')
async function main() {
await scriptlet.run(path.join(__dirname, 'rm.js'), {
// inject the '$in' arguments
extra: new Map(['$in', process.argv[2]]),
// use mtime based cache policy
cache: 'mtime'
})
}
main()
```## More
You can build a **scriptlet** based web server with hot-reload support or even build your own Amazon Lambda Service.
## Credits
Copyright (c) 2018 Yanke Guo
This software is released under the MIT License, see https://opensource.org/licenses/MIT