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

Commit

Permalink
transfer content from private repository
Browse files Browse the repository at this point in the history
  • Loading branch information
radufalcusanStoneone committed Aug 18, 2021
1 parent 11df756 commit 41bdc12
Show file tree
Hide file tree
Showing 15 changed files with 22,493 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
**/templates
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
9 changes: 9 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"generator-node": {
"promptValues": {
"authorName": "Michael Falkenthal",
"authorEmail": "[email protected]",
"authorUrl": ""
}
}
}
13 changes: 13 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2021 StoneOne AG

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
# yo-generator-planqk-service
# generator-planqk-service [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
> Generator for scuffolding PlanQK services
## Installation

First, install [Yeoman](http://yeoman.io) and generator-planqk-service using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo
npm install -g generator-planqk-service
```

Then generate your new project:

```bash
yo planqk-service
```

## Getting To Know Yeoman

* Yeoman has a heart of gold.
* Yeoman is a person with feelings and opinions, but is very easy to work with.
* Yeoman can be too opinionated at times but is easily convinced not to be.
* Feel free to [learn more about Yeoman](http://yeoman.io/).

## License

Apache-2.0 © [Michael Falkenthal]()


[npm-image]: https://badge.fury.io/js/generator-planqk-service.svg
[npm-url]: https://npmjs.org/package/generator-planqk-service
[travis-image]: https://travis-ci.com//generator-planqk-service.svg?branch=master
[travis-url]: https://travis-ci.com//generator-planqk-service
[daviddm-image]: https://david-dm.org//generator-planqk-service.svg?theme=shields.io
[daviddm-url]: https://david-dm.org//generator-planqk-service
16 changes: 16 additions & 0 deletions __tests__/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
const path = require("path");
const assert = require("yeoman-assert");
const helpers = require("yeoman-test");

describe("generator-planqk-service:app", () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, "../generators/app"))
.withPrompts({ someAnswer: true });
});

it("creates files", () => {
assert.file(["dummyfile.txt"]);
});
});
244 changes: 244 additions & 0 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
"use strict";
const Generator = require("yeoman-generator");
const chalk = require("chalk");
const yosay = require("yosay");
const AdmZip = require("adm-zip");
const axios = require("axios");

module.exports = class extends Generator {
constructor(args, opts) {
super(args, opts);

this.argument("name", {
type: String,
required: true,
default: "my-service",
desc: "Name of the new service"
});
}

_isSdkValid(sdk) {
if (
typeof sdk === "string" &&
(sdk.toLowerCase() === "ocean" || sdk.toLowerCase() === "qiskit")
) {
return true;
}

return false;
}

initializing() {}

async prompting() {
this.props = {};
// Have Yeoman greet the user.
this.log(
yosay(
`Welcome to the delightful ${chalk.red(
"PlanQK Service"
)} generator!`
)
);

const sdkQuestion = {
type: "list",
name: "sdk",
message: "Tell me in which SDK you want to program:",
default: "none",
choices: [
{ name: "That is my secret", value: "none", short: "None" },
{ name: "DWAVE OCEAN", value: "ocean", short: "OCEAN" },
{ name: "IBM QISKIT", value: "qiskit", short: "QISKIT" }
],
store: true
};
Object.assign(this.props, await this.prompt(sdkQuestion));

if (this.props.sdk !== "none") {
const installSDKQuestion = {
type: "confirm",
name: "installSDK",
message: "Should I install the selected SDK via pip for you?",
default: false,
store: true
};
Object.assign(this.props, await this.prompt(installSDKQuestion));
}

const vsCodeLaunchConfigQuestion = {
type: "confirm",
name: "installLaunchConfig",
message: "May I add a launch configuration for Visual Studio Code?",
default: true,
store: true
};
Object.assign(
this.props,
await this.prompt(vsCodeLaunchConfigQuestion)
);

const initGitQuestion = {
type: "confirm",
name: "initGit",
message: "Do you want to develop in a git repo?",
default: true,
store: true
};
Object.assign(this.props, await this.prompt(initGitQuestion));
}

configuring() {}

async _generateUserCodeFolder() {
try {
const config = {
headers: {
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"Expires": "0",
},
responseType: "arraybuffer"
}
this.log(` ${chalk.green("download")} service-template`);
const serviceTemplate = await axios.get(
"https://storage.googleapis.com/yeoman-templates/1.0.0/service-template.zip",
config
);
this.log(` ${chalk.green("extract")} to ${this.options.name}/service-template`);
new AdmZip(serviceTemplate.data).extractAllTo(
this.destinationPath(this.options.name)
);
} catch (err) {
this.log.error(
"Something went wrong while fetching the template.\n" +
chalk.red(err.message)
);
}
}

async _generateOpenApiSpec() {
try {
const config = {
headers: {
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"Expires": "0",
},
responseType: "arraybuffer"
}
this.log(` ${chalk.green("download")} openapi-spec.yml`);
const openapiSpec = await axios.get(
"https://storage.googleapis.com/yeoman-templates/1.0.0/openapi-spec.yml",
config
);
this.fs.write(
this.destinationPath(this.options.name, "openapi-spec.yml"),
openapiSpec.data
);
} catch (error) {
this.log.error(
"Something went wrong while fetching openapi-spec template.\n" +
chalk.red(error.message)
);
}
}

async _generateVSCodeLaunchConfig() {
try {
const config = {
headers: {
"Cache-Control": "no-cache",
"Pragma": "no-cache",
"Expires": "0",
},
responseType: "arraybuffer"
}
const response = await axios.get(
"https://storage.googleapis.com/yeoman-templates/1.0.0/vscode-launch.json",
config
);
this.fs.write(
this.destinationPath(
this.options.name,
".vscode",
"launch.json"
),
response.data
);
} catch (err) {
this.log.error(
"Something went wrong while fetching the VSCode launch configuration.\n" +
chalk.red(err.message)
);
}
}

async writing() {
await this._generateUserCodeFolder();

await this._generateOpenApiSpec();

if (this.props.installLaunchConfig) {
await this._generateVSCodeLaunchConfig();
}

// Todo: Move requirements files to cloud storage bucket
if (
this._isSdkValid(this.props.sdk) &&
this.props.sdk.toLowerCase() === "ocean"
) {
this.fs.copy(
this.templatePath(
"requirements-templates/requirements-ocean.txt"
),
this.destinationPath(this.options.name, "requirements.txt")
);
}

if (
this._isSdkValid(this.props.sdk) &&
this.props.sdk.toLowerCase() === "qiskit"
) {
this.fs.copy(
this.templatePath(
"requirements-templates/requirements-qiskit.txt"
),
this.destinationPath(this.options.name, "requirements.txt")
);
}
}

conflicts() {}

_initGit() {
this.spawnCommandSync("git", ["init", "-b", "main"]);
}

async install() {
if (this._isSdkValid(this.props.sdk) && this.props.installSDK) {
let requirementsFilePath = this.destinationPath(
this.options.name,
"requirements.txt"
);
this.spawnCommandSync("pip", [
"install",
"-r",
requirementsFilePath
]);
}

if (this.props.initGit) {
this.fs.commit(() => {
process.chdir(this.destinationPath(this.options.name));
this._initGit();
});
}
}

end() {
this.log(
`Everything initialized for you. ${chalk.green("Happy coding!")}`
);
}
};
1 change: 1 addition & 0 deletions generators/app/templates/gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dwave-ocean-sdk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
qiskit
15 changes: 15 additions & 0 deletions generators/app/templates/vscode-launch-config/vscode-launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Modul",
"type": "python",
"request": "launch",
"cwd": "${workspaceFolder}",
"module": "user_code"
}
]
}
Loading

0 comments on commit 41bdc12

Please sign in to comment.