Here is a simple plugin with no config and it runs on a single lifecycle event postBuild
// Plugin code |
| const axios = require('axios') | |
| const GITHUB_REPO = process.env.GITHUB_REPO | |
| const GITHUB_API_TOKEN = process.env.GITHUB_API_TOKEN | |
| const GITHUB_USERNAME = process.env.GITHUB_USERNAME | |
| module.exports = function addUserToGithubRepo(username) { | |
| const githubEndpoint = `https://api.github.com/repos/${GITHUB_REPO}/collaborators/${username}` | |
| const config = { | |
| 'headers': { | |
| 'User-Agent': GITHUB_USERNAME, |
| const path = require('path') | |
| const globby = require('globby') | |
| const execSync = require('child_process').execSync | |
| globby(['*/serverless.yml']).then(paths => { | |
| // Now run npm install | |
| const command = `npm install` | |
| paths.forEach((p) => { | |
| var t = path.join(__dirname, p) | |
| execSync(command, { |
| const CHARS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}[]:;<>?/|\\'; | |
| function generatePassword(length = 12) { | |
| let pass = ''; | |
| for (let i = length; i > 0; --i) pass += CHARS[Math.floor(Math.random() * CHARS.length)]; | |
| return pass | |
| } | |
| // Usage: | |
| generatePassword(15) |
| function stringToBoolean(str) { | |
| const string = (typeof str === 'string') ? str.toLowerCase().trim() : str | |
| switch (string) { | |
| case "true": case "yes": case "1": return true | |
| case "false": case "no": case "0": case null: return false | |
| default: return Boolean(string) | |
| } | |
| } | |
| // Usage |
| const path = require('path') | |
| const fetch = require('node-fetch') | |
| const flatcache = require('flat-cache') | |
| /* Download API | |
| period: Joi.string().regex(/(\d{4}-\d{2}-\d{2}(:\d{4}-\d{2}-\d{2})?|[\w-]+)/).required(), | |
| Package "package-name", last week: | |
| /downloads/point/last-week/package-name | |
| Package "package-name", given 7-day period: |
Normal text here. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer vitae mauris arcu, eu pretium nisi. Vivamus vitae mi ligula, non hendrerit urna. Suspendisse potenti. Quisque eget massa a massa semper mollis.
Tiny text is here. Awwwww its so cuteeeeeeeeeee
Normal big text
| function stringify(obj_from_json){ | |
| if(typeof obj_from_json !== "object" || Array.isArray(obj_from_json)){ | |
| // not an object, stringify using native function | |
| return JSON.stringify(obj_from_json); | |
| } | |
| // Implements recursive object serialization according to JSON spec | |
| // but without quotes around the keys. | |
| let props = Object | |
| .keys(obj_from_json) | |
| .map(key => `${key}:${stringify(obj_from_json[key])}`) |
| service: my-service | |
| custom: | |
| one: 'hello' | |
| two: 'there' | |
| together: ${merge(${custom.one}, ${custom.two})} | |
| # ^ resolves to 'hellothere' | |
| provider: | |
| name: aws |
| const isEqual = require('lodash.isequal') | |
| function compareNewToOld(newValues, oldValues) { | |
| const initialData = { | |
| // default everything is equal | |
| isEqual: true, | |
| // Keys that are different | |
| keys: [], | |
| // Values of the keys that are different | |
| diffs: {} |