let group = {
molds: 'object',
tools: 'object',
lines: 'object',
mergers: 'object',
install: 'function'
}
// s3.js
const group = {
install: (group, options, packhouse) => {
const AWS = require('aws-sdk')
group.service = new AWS.S3({
apiVersion: options.apiVersion
})
}
}
module.exports = group
packhouse.addGroup('s3', () => {
return {
data: require('./s3'),
options: {
apiVersion: '2006-03-01'
}
}
})
const group = {
tools: {
sum: {
handler(self, v1, v2) {
self.success(v1 + v2)
}
}
}
}
const group2 = {
mergers: {
mySum: 'sum'
},
tools: {
double: {
install({ include }) {
include('sum').tool('mySum/sum')
},
handler(self, value) {
self.tool('sum')
.noGood(self.error)
.action(value, value, self.success)
}
}
}
}
packhouse.addGroup('sum', () => {
return {
data: group
}
})
packhouse.addGroup('double', () => {
return {
data: group2
}
})
packhouse.tool('double/double').action(10, (error, result) => {
console.log(result) // 20
})
import { Group } from 'packhouse/types'
const group: Group = {}
// 這是個糟糕的例子 😢
const AWS = require('aws-sdk')
const group = {
install: (group, options) => {
group.service = new AWS.S3({
apiVersion: options.apiVersion
})
}
}
module.exports = group
// 這是個優良案例 🤣
const group = {
install: (group, options) => {
const AWS = require('aws-sdk')
group.service = new AWS.S3({
apiVersion: options.apiVersion
})
}
}
module.exports = group