diff --git a/package-lock.json b/package-lock.json index 283bbfb..d54b32f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1309,7 +1309,6 @@ "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", - "dev": true, "requires": { "sprintf-js": "~1.0.2" } @@ -3716,6 +3715,11 @@ "map-cache": "^0.2.2" } }, + "fs-exists-sync": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/fs-exists-sync/-/fs-exists-sync-0.1.0.tgz", + "integrity": "sha1-mC1ok6+RjnLQjeyehnP/K1qNat0=" + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -5226,8 +5230,7 @@ "is-extendable": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", - "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=", - "dev": true + "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=" }, "is-extglob": { "version": "2.1.1", @@ -6094,8 +6097,7 @@ "minimist": { "version": "0.0.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", - "dev": true + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" }, "minimist-options": { "version": "3.0.2", @@ -6132,7 +6134,6 @@ "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", - "dev": true, "requires": { "minimist": "0.0.8" } @@ -9278,8 +9279,7 @@ "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true + "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=" }, "sshpk": { "version": "1.16.1", @@ -10362,6 +10362,49 @@ "signal-exit": "^3.0.2" } }, + "write-yaml": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/write-yaml/-/write-yaml-1.0.0.tgz", + "integrity": "sha1-MUWWEZ0NuRJHy8g1vOADO24LoJ4=", + "requires": { + "extend-shallow": "^2.0.1", + "js-yaml": "^3.8.3", + "write": "^0.3.3" + }, + "dependencies": { + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==" + }, + "extend-shallow": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", + "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", + "requires": { + "is-extendable": "^0.1.0" + } + }, + "js-yaml": { + "version": "3.13.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.13.0.tgz", + "integrity": "sha512-pZZoSxcCYco+DIKBTimr67J6Hy+EYGZDY/HCWC+iAEA9h1ByhMXAIVUXMcMFpOCxQ/xjXmPI2MkDL5HRm5eFrQ==", + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + }, + "write": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/write/-/write-0.3.3.tgz", + "integrity": "sha1-Cc3FohVWB+4nn0XjjZGuKftqUXg=", + "requires": { + "fs-exists-sync": "^0.1.0", + "mkdirp": "^0.5.1" + } + } + } + }, "x-is-string": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/x-is-string/-/x-is-string-0.1.0.tgz", diff --git a/package.json b/package.json index 1d28824..aa6eeac 100644 --- a/package.json +++ b/package.json @@ -52,5 +52,8 @@ "rollup-plugin-auto-external": "^2.0.0", "sinon": "^7.3.0", "travis-lint": "^1.0.0" + }, + "dependencies": { + "write-yaml": "^1.0.0" } } diff --git a/src/config.js b/src/config.js new file mode 100644 index 0000000..b1ab572 --- /dev/null +++ b/src/config.js @@ -0,0 +1,8 @@ +import writeYaml from '../third-party-wrappers/write-yaml'; + +export default function ({projectRoot}) { + return writeYaml( + `${projectRoot}/.travis.yml`, + {language: 'generic', notifications: {email: false}, install: 'bpkg getdeps', script: 'make test'} + ); +} diff --git a/src/scaffolder.js b/src/scaffolder.js index 57151d9..fc12573 100644 --- a/src/scaffolder.js +++ b/src/scaffolder.js @@ -1,3 +1,7 @@ -export default function () { +import scaffoldConfig from './config'; + +export default async function ({projectRoot}) { + await scaffoldConfig({projectRoot}); + return {}; } diff --git a/test/unit/config-test.js b/test/unit/config-test.js new file mode 100644 index 0000000..11fca43 --- /dev/null +++ b/test/unit/config-test.js @@ -0,0 +1,35 @@ +import sinon from 'sinon'; +import {assert} from 'chai'; +import any from '@travi/any'; +import * as yamlWriter from '../../third-party-wrappers/write-yaml'; +import scaffoldConfig from '../../src/config'; + +suite('config file generation', () => { + let sandbox; + const projectRoot = any.string(); + + setup(() => { + sandbox = sinon.createSandbox(); + + sandbox.stub(yamlWriter, 'default'); + + yamlWriter.default.resolves(); + }); + + teardown(() => sandbox.restore()); + + test('that a base config is created for a shell project', async () => { + await scaffoldConfig({projectRoot}); + + assert.calledWith( + yamlWriter.default, + `${projectRoot}/.travis.yml`, + { + language: 'generic', + notifications: {email: false}, + install: 'bpkg getdeps', + script: 'make test' + } + ); + }); +}); diff --git a/test/unit/scaffolder-test.js b/test/unit/scaffolder-test.js index 3e7c5b0..e450a90 100644 --- a/test/unit/scaffolder-test.js +++ b/test/unit/scaffolder-test.js @@ -1,8 +1,24 @@ import {assert} from 'chai'; +import any from '@travi/any'; +import sinon from 'sinon'; +import * as configScaffolder from '../../src/config'; import {scaffold} from '../../src'; suite('scaffolder', () => { - test('that the config is scaffolded', () => { - assert.deepEqual(scaffold(), {}); + let sandbox; + + setup(() => { + sandbox = sinon.createSandbox(); + + sandbox.stub(configScaffolder, 'default'); + }); + + teardown(() => sandbox.restore()); + + test('that the config is scaffolded', async () => { + const projectRoot = any.string(); + + assert.deepEqual(await scaffold({projectRoot}), {}); + assert.calledWith(configScaffolder.default, {projectRoot}); }); }); diff --git a/third-party-wrappers/write-yaml.js b/third-party-wrappers/write-yaml.js new file mode 100644 index 0000000..300f04a --- /dev/null +++ b/third-party-wrappers/write-yaml.js @@ -0,0 +1,4 @@ +import {promisify} from 'util'; +import yaml from 'write-yaml'; + +export default promisify(yaml);