-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(process): add cli parameters for importing directly to sphere #40
Changes from 18 commits
66b0dee
bb33a25
253d716
f7c2903
9f20130
ed574c7
fde65e2
6c34f70
1571e16
63d72c1
4866775
a4f15b6
48a32c2
8a42cf5
fe50f87
943923e
0f5fb54
5fcb461
e866a9d
09fdc1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
_ = require 'underscore' | ||
Promise = require 'bluebird' | ||
ProductTypeImport = require 'sphere-product-type-import' | ||
{ExtendedLogger, ProjectCredentialsConfig} = require 'sphere-node-utils' | ||
package_json = require '../package.json' | ||
|
||
class ProductTypeImporter | ||
|
||
### | ||
Prepare for importing, initialize used modules | ||
### | ||
init: (argv) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had problems with constructor containing asynchronous operation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the async stuff shouldn't go in the contructor :) I think just a function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but than it would have to create ProductTypeImport object in that import function which is wrong because it should be initialized on some central place so it can be possibly used on other places There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated here 631bdd8 |
||
@logOptions = | ||
name: "#{package_json.name}-#{package_json.version}" | ||
silent: !! argv.logSilent | ||
streams: [ | ||
{ level: 'error', stream: process.stderr } | ||
{ level: argv.logLevel || 'info', path: "#{argv.logDir || '.'}/#{package_json.name}.log" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be better to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added here 09fdc1b |
||
] | ||
|
||
@logger = new ExtendedLogger | ||
additionalFields: | ||
'project_key': argv.projectKey | ||
logConfig: @logOptions | ||
if argv.logSilent | ||
@logger.bunyanLogger.trace = -> # noop | ||
@logger.bunyanLogger.debug = -> # noop | ||
|
||
@_ensureCredentials argv | ||
.then (credentials) -> | ||
@sphereImporter = new ProductTypeImport.default(@logger, credentials) | ||
Promise.resolve @ | ||
|
||
### | ||
Create sphere credentials config from command line arguments | ||
### | ||
_ensureCredentials: (argv) -> | ||
credentialsPromise = null | ||
|
||
if argv.accessToken | ||
credentialsPromise = Promise.resolve | ||
config: | ||
project_key: argv.projectKey | ||
access_token: argv.accessToken | ||
else | ||
credentialsPromise = ProjectCredentialsConfig.create() | ||
.then (credentials) -> | ||
config = credentials.enrichCredentials | ||
project_key: argv.projectKey | ||
|
||
if(argv.clientId) | ||
config.client_id = argv.clientId | ||
|
||
if(argv.clientSecret) | ||
config.client_secret = argv.clientSecret | ||
config: config | ||
|
||
credentialsPromise.then (credentials) -> | ||
options = _.extend credentials, | ||
timeout: argv.timeout | ||
user_agent: "#{package_json.name} - #{package_json.version}" | ||
|
||
options.host = argv.sphereHost if argv.sphereHost | ||
options.protocol = argv.sphereProtocol if argv.sphereProtocol | ||
if argv.sphereAuthHost | ||
options.oauth_host = argv.sphereAuthHost | ||
options.rejectUnauthorized = false | ||
options.oauth_protocol = argv.sphereAuthProtocol if argv.sphereAuthProtocol | ||
sphereClientConfig: options | ||
|
||
### | ||
Import product types using sphere product import tool | ||
### | ||
import: (data) -> | ||
console.log "Importing product types to sphere" | ||
Promise.map data.productTypes, (productType) -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might consider to put a concurrency limit here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added here 4866775 |
||
@sphereImporter.importProductType productType | ||
.then (res) -> | ||
console.log "Imported product type", res.name | ||
Promise.resolve res | ||
.catch (e) -> | ||
console.error "Oops, something went wrong when importing product type #{productType.name} to sphere" | ||
Promise.reject e | ||
, concurrency: 5 | ||
module.exports = ProductTypeImporter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because travis had configured env variables for nicola project - thats why there were failing tests