Adding sample docker file creation option.
This commit is contained in:
Peter Jausovec 2015-10-16 19:51:25 -07:00
Родитель bd7f8abdf8
Коммит 74950de042
10 изменённых файлов: 209 добавлений и 2 удалений

1
.gitattributes поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
* text=auto

1
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1 @@
node_modules/

3
.yo-rc.json Normal file
Просмотреть файл

@ -0,0 +1,3 @@
{
"generator-generator": {}
}

23
LICENSE Normal file
Просмотреть файл

@ -0,0 +1,23 @@
generator-docker
The MIT License (MIT)
Copyright (c) Microsoft Corporation
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Просмотреть файл

@ -1,2 +1,41 @@
# generator-docker
Yeoman generator for Docker
# Yeoman Docker Generator
## Developing & testing
After making changes to the code, run:
```bash
npm link
```
And then run the generator:
```bash
yo docker
```
Run the following command from the root folder of the project:
```bash
mocha
```
## Publishing
To publish a new version of the docker generator, increase the generator version and run:
```bash
npm publish
```
## Installing
To install generator-docker from npm, run:
```bash
npm install -g generator-docker
```
Finally, initiate the generator:
```bash
yo docker
```
## License
MIT

82
generators/app/index.js Normal file
Просмотреть файл

@ -0,0 +1,82 @@
'use strict';
var yeoman = require('yeoman-generator');
var chalk = require('chalk');
var yosay = require('yosay');
var path = require('path');
var DockerGenerator = yeoman.generators.Base.extend({
constructor: function () {
yeoman.generators.Base.apply(this, arguments);
},
init: function () {
this.log(yosay('Welcome to the ' + chalk.red('Docker') + ' generator!'));
this.templatedata = {};
},
initializing: function () {
},
initForTest: function(artifactType) {
this.type = artifactType;
},
askFor: function () {
var done = this.async();
var prompts = [{
type: 'list',
name: 'type',
message: 'Which Docker artifact do you want to create?',
choices: [
{
name: 'Docker file (' + chalk.bold('Dockerfile') + ')',
value: 'dockerfile'
},
{
name: 'Compose file (' + chalk.bold('Docker-compose.yml') + ')',
value: 'composefile'
}
]
}];
this.prompt(prompts, function (props) {
this.type = props.type;
done();
}.bind(this));
},
writing: function () {
this.sourceRoot(path.join(__dirname, './templates'));
switch (this.type) {
case 'dockerfile':
this.copy(this.sourceRoot() + '/_Dockerfile', 'Dockerfile');
break;
case 'composefile':
break;
default:
// unknown.
break;
}
},
install: function () {
// this.installDependencies();
},
end: function () {
switch (this.type) {
case 'dockerfile':
this.log('Dockerfile was added to your project.');
break;
case 'composefile':
this.log('Oops, nothing there yet :(');
break;
default:
break;
}
}
});
module.exports = DockerGenerator;

Просмотреть файл

@ -0,0 +1,3 @@
# Hello World Dockerfile
FROM ubuntu:latest
RUN ["/bin/echo", "Hello World!"]

6
jsconfig.json Normal file
Просмотреть файл

@ -0,0 +1,6 @@
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs"
}
}

29
package.json Normal file
Просмотреть файл

@ -0,0 +1,29 @@
{
"name": "generator-docker",
"version": "0.0.4",
"description": "Docker generator",
"files": [
"generators/app"
],
"keywords": [
"yeoman-generator",
"vscode",
"docker",
"extensions",
"visual studio",
"docker compose"
],
"license": "MIT",
"author": {
"name": "DockerToolsDevTeam",
"url": "https://github.com/Microsoft"
},
"dependencies": {
"yeoman-generator": "^0.19.0",
"chalk": "^1.0.0",
"yosay": "^1.0.2"
},
"devDependencies": {
"mocha": "*"
}
}

20
test/test-app.js Normal file
Просмотреть файл

@ -0,0 +1,20 @@
'use strict';
var path = require('path');
var assert = require('yeoman-generator').assert;
var helpers = require('yeoman-generator').test;
var os = require('os');
describe('docker:app', function () {
before(function (done) {
helpers.run(path.join(__dirname, '../generators/app'))
.withPrompts({ type:"dockerfile"})
.on('end', done);
});
it('creates files', function () {
assert.file([
'Dockerfile'
]);
});
});