Skip to content
This repository has been archived by the owner on Sep 28, 2023. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
aureeaubert committed Dec 4, 2018
0 parents commit ed20680
Show file tree
Hide file tree
Showing 28 changed files with 4,850 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false
34 changes: 34 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"env": {
"es6": true,
"node": true,
"jest/globals": true
},
"extends": [
"airbnb-base",
"plugin:jest/recommended",
"plugin:prettier/recommended",
"prettier",
"prettier/standard"
],
"plugins": [
"jest",
"prettier"
],
"rules": {
"arrow-body-style" : [0],
"arrow-parens": [0],
"camelcase": [0],
"class-methods-use-this": [0],
"comma-dangle": [0],
"eqeqeq": [1],
"max-len": [0],
"new-cap": [0],
"no-console": [0],
"no-param-reassign" : [0],
"no-underscore-dangle": [0],
"prefer-arrow-callback": [0],
"prefer-destructuring": [0],
"quotes": [2, "double"]
}
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test-collector
node_modules
coverage
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Spendesk Collector Template

This is a scaffolding tool for creating and maintaining Spendesk Collectors. It comes with base directory and file structure, default configuration and documentation files templates.

## Installation

Install it as a global node package:

```
npm install -g spendesk-collector-template
```

Now you can use the `spendesk-collector-template` command to generate or update collector base code.

## Creating new collector

```
spendesk-collector-template [working-path]
```

You can execute this command over new directory which will be created, or run it inside an empty, already existing directory.

When run script will ask you couple of questions interactively to fill in templates with data.
38 changes: 38 additions & 0 deletions bin/collector-template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#! /usr/bin/env node

const argv = require("minimist")(process.argv.slice(2));
const gulp = require("gulp");
const conflict = require("gulp-conflict");
const template = require("gulp-template");

const collectorTemplateVersion = require("../package").version;
const promptUser = require("../src/prompt-user");
const loadJsonFile = require("../src/load-json-file");
const combineData = require("../src/combine-data");

if (argv.v || argv.version) {
console.log("spendesk-collector-template version:", collectorTemplateVersion);
process.exit(0);
}

const targetPath = argv._[0] || "./";

const existingManifestJson = loadJsonFile(targetPath, "manifest.json");
const existingPackageJson = loadJsonFile(targetPath, "package.json");

promptUser(argv, existingManifestJson, existingPackageJson).then(
userAnswers => {
const data = combineData(
argv,
userAnswers,
existingManifestJson,
existingPackageJson
);

gulp
.src(`${__dirname}/../template/**/*`, { dot: true })
.pipe(template(data, { interpolate: /<%=([\s\S]+?)%>/g }))
.pipe(conflict(targetPath))
.pipe(gulp.dest(targetPath));
}
);
26 changes: 26 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
"collectCoverage": true,
"collectCoverageFrom": [
"src/**/*.{js,jsx}",
"template/**/*.{js,jsx}",
"bin/**/*.{js,jsx}",
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/tests/"
],
"coverageThreshold": {
"global": {
"branches": 40,
"functions": 40,
"lines": 40,
"statements": 40
}
},
"testEnvironment": "node",
"testMatch": ["<rootDir>/tests/units/**/*.spec.js", "<rootDir>/tests/integrations/**/*.spec.js"],
"transformIgnorePatterns": ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"],
"testPathIgnorePatterns": [
"<rootDir>/(dist|docs|dll|config|flow-typed|node_modules)/"
]
};
44 changes: 44 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "spendesk-collector-template",
"version": "0.0.2",
"description": "Template to develop Spendesk collectors",
"dependencies": {
"child_process": "^1.0.2",
"gulp": "^3.9.1",
"gulp-conflict": "^0.4.0",
"gulp-template": "^5.0.0",
"inquirer": "^5.2.0",
"lodash": "^4.17.5",
"minimist": "^1.2.0"
},
"engines": {
"node": "8.11.x",
"npm": "5.6.x",
"yarn": "1.6.x"
},
"devDependencies": {
"eslint": "^5.9.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-config-prettier": "^3.3.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jest": "^22.0.1",
"eslint-plugin-prettier": "^3.0.0",
"jest": "^23.6.0",
"prettier": "^1.15.2"
},
"scripts": {
"test": "yarn run test:lint && yarn run test:combined",
"test:lint": "eslint bin src",
"test:combined": "NODE_ENV=test jest ./tests",
"test:unit": "NODE_ENV=test jest ./tests/units",
"test:integration": "NODE_ENV=test jest ./tests/integrations"
},
"bin": {
"spendesk-collector-template": "./bin/collector-template.js"
},
"main": "bin/collector-template",
"repository": "[email protected]:Spendesk/collect-template.git",
"author": "Auree Aubert <[email protected]>",
"license": "MIT",
"private": false
}
23 changes: 23 additions & 0 deletions src/combine-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const _ = require("lodash");
const templateVersion = require("./../package.json").version;

module.exports = (
argv,
userAnswers,
existingManifestJson,
existingPackageJson
) => {
const forcedData = {
version: existingPackageJson.version || "0.0.1",
template_version: templateVersion
};

if (argv["non-interactive"]) {
userAnswers = {
name: `${_.startCase(_.camelCase(argv.name))}`,
package_name: `spendesk-${_.kebabCase(argv.name)}-collector`
};
}

return _.defaults({}, forcedData, userAnswers);
};
16 changes: 16 additions & 0 deletions src/load-json-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const path = require("path");
const fs = require("fs");

module.exports = (targetPath, fileName) => {
try {
const existingJsonFilePath = path.join(process.cwd(), targetPath, fileName);
if (fs.existsSync(existingJsonFilePath)) {
console.log("Loading: ", existingJsonFilePath);
return require(existingJsonFilePath); // eslint-disable-line
}
return {};
} catch (e) {
console.log(`Failed to load ${fileName}, exiting`);
return process.exit(1);
}
};
33 changes: 33 additions & 0 deletions src/prompt-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const _ = require("lodash");
const inquirer = require("inquirer");

module.exports = (argv, existingManifestJson, existingPackageJson) => {
function showQuestion(answers) {
return !argv["non-interactive"];
}

return inquirer.prompt([
{
type: "text",
name: "name",
message: "Collector human redable name (e.g. 'LinkedIn Ads')",
validate: input => {
return input.match(/[a-zA-Z][a-zA-Z0-9]+/) !== null;
},
default: existingManifestJson.name,
when: showQuestion
},
{
type: "text",
name: "package_name",
message: "Package name",
default: data => {
return (
existingPackageJson.name ||
`spendesk-${_.kebabCase(data.name)}-collector`
);
},
when: showQuestion
}
]);
};
16 changes: 16 additions & 0 deletions template/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; EditorConfig helps developers define and maintain consistent
; coding styles between different editors and IDEs
; editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
34 changes: 34 additions & 0 deletions template/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"env": {
"es6": true,
"node": true,
"jest/globals": true
},
"extends": [
"airbnb-base",
"plugin:jest/recommended",
"plugin:prettier/recommended",
"prettier",
"prettier/standard"
],
"plugins": [
"jest",
"prettier"
],
"rules": {
"arrow-body-style" : [0],
"arrow-parens": [0],
"camelcase": [0],
"class-methods-use-this": [0],
"comma-dangle": [0],
"eqeqeq": [1],
"max-len": [0],
"new-cap": [0],
"no-console": [0],
"no-param-reassign" : [0],
"no-underscore-dangle": [0],
"prefer-arrow-callback": [0],
"prefer-destructuring": [0],
"quotes": [2, "double"]
}
}
4 changes: 4 additions & 0 deletions template/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
coverage
.vscode
.env
14 changes: 14 additions & 0 deletions template/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# <%= name %> Collector
TODO: description

## Getting Started
TODO: getting started and configuration

## How it works
TODO: general overview

## Features
TODO: features descriptions

## FAQ
TODO: limitations
1 change: 1 addition & 0 deletions template/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: NODE_ENV=production node app
1 change: 1 addition & 0 deletions template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# <%= name %> Collector
6 changes: 6 additions & 0 deletions template/app/actions/collect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = (req, res) => {
const spendeskCollectClient = req.client;
const spendeskCollectShip = req.ship;

res.json({ ok: true });
};
6 changes: 6 additions & 0 deletions template/app/actions/status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = (req, res) => {
const spendeskCollectClient = req.client;
const spendeskCollectShip = req.ship;

return res.json({ label: "ok" });
};
6 changes: 6 additions & 0 deletions template/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const SpendeskCollect = require("spendesk-collect");

const { PORT = 8082 } = process.env;

const collector = new SpendeskCollect.Collector(PORT);
collector.startApp();
Empty file added template/assets/.keep
Empty file.
24 changes: 24 additions & 0 deletions template/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
"collectCoverage": true,
"collectCoverageFrom": [
"app/**/*.{js,jsx}"
],
"coveragePathIgnorePatterns": [
"/node_modules/",
"/tests/"
],
"coverageThreshold": {
"global": {
"branches": 40,
"functions": 40,
"lines": 40,
"statements": 40
}
},
"testEnvironment": "node",
"testMatch": ["<rootDir>/tests/units/**/*.spec.js", "<rootDir>/tests/integrations/**/*.spec.js"],
"transformIgnorePatterns": ["[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"],
"testPathIgnorePatterns": [
"<rootDir>/(dist|docs|dll|config|flow-typed|node_modules)/"
]
};
Loading

0 comments on commit ed20680

Please sign in to comment.