Skip to content
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

Merged
merged 20 commits into from
Sep 7, 2016
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: node_js
node_js:
- '0.10'
- '0.12'
- '4'
before_script:
- npm install -g grunt-cli
- gem install cucumber aruba
Expand All @@ -25,4 +24,4 @@ env:
global:
- secure: iytO3AZ1pOvuZ8Mb6F6WqNjFnbxWw5yfadrnN5z43jK+23/YKS04bvcExJJ095L7t9IX9Jes2YfH1nbUm/f0oys3l1K40MDTDP7JvG39AfTHxLezUTrNKLryCI/FbuvIcA3BX1x2KH9FuRO1kmz5zaDQ0paNnn8z1MHU2PqizR0=
- secure: 04u05uQP06WQX0BvFY2RISY/9/Z63c+Tjono6Z4habOvLYtYsfE0rmxEcQkp3PGgRnWlDtYek/2S5XMKAG1Vlhlmv/kRpmp4h9t+SsPwLuYlUu8VI0/ADcOn9nLurFVc95jAtLjXSWTtwq5A92Lqj8Ujzpucr8m3pF9XWRnhLg0=
- secure: dF44muD7/0sSF6D0JV1KaVcgjPp/P/q8Yd2CzC/okP+xYNo5DcZhJGjNoPEtdOleE5/Osj+XWPQZfhQaWfoe1tptdXppEYJlkHvkHgJh7k3OIBKxCWr+1onssxkUIYuWZEKtwF4koxtoUNw1EFsHkfSOEWGpb644wL6aeddDv+k=
- secure: dF44muD7/0sSF6D0JV1KaVcgjPp/P/q8Yd2CzC/okP+xYNo5DcZhJGjNoPEtdOleE5/Osj+XWPQZfhQaWfoe1tptdXppEYJlkHvkHgJh7k3OIBKxCWr+1onssxkUIYuWZEKtwF4koxtoUNw1EFsHkfSOEWGpb644wL6aeddDv+k=
8 changes: 4 additions & 4 deletions Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ module.exports = (grunt) ->
stderr: true
failOnError: true
coverage:
command: 'istanbul cover jasmine-node --captureExceptions test && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage'
jasmine:
command: 'jasmine-node --captureExceptions test'
command: 'istanbul cover node_modules/.bin/_mocha test/**/*.spec.js && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage'
mocha:
command: './node_modules/.bin/mocha test/**/*.spec.js'
publish:
command: 'npm publish'

Expand Down Expand Up @@ -101,7 +101,7 @@ module.exports = (grunt) ->
grunt.registerTask 'default', ['build']
grunt.registerTask 'build', ['clean', 'coffeelint', 'coffee', 'concat']
grunt.registerTask 'coverage', ['build', 'shell:coverage']
grunt.registerTask 'test', ['build', 'shell:jasmine']
grunt.registerTask 'test', ['build', 'shell:mocha']
grunt.registerTask 'release', 'Release a new version, push it and publish it', (target) ->
target = 'patch' unless target
grunt.task.run "bump-only:#{target}", 'test', 'bump-commit', 'shell:publish'
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,31 @@ alias product-type='docker run -v /path/to/files/:/files sphereio/product-type-g
* Clone this repository and change into the directory
* Install all necessary dependencies with

```bash
npm install
```
```bash
npm install
```

* To run the test do:
* To run tests you have to set up credentials for sphere project first:
For setting credentials you can create file in your home folder `~/.sphere-project-credentials.json` with content:

```
{
"{PROJECT_ID}": {
"client_id": "{CLIENT_ID}",
"client_secret": "{CLIENT_SECRET}"
}
}
```

```bash
Than you can do:

```bash
export SPHERE_PROJECT_KEY={PROJECT_ID}
npm test
```
```

This will start tests under sphere project `{PROJECT_ID}`.

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
More info [here](CONTRIBUTING.md)
Expand Down
64 changes: 32 additions & 32 deletions data/tests/product-types-attributes-boolean-text-number.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,38 @@ booleanSFF,boolean,SameForAll,false,false,Boolsch,Boolean,,,,,
booleanSTF,boolean,SameForAll,true,false,Boolsch,Boolean,,,,,
booleanSFT,boolean,SameForAll,false,true,Boolsch,Boolean,,,,,
booleanSTT,boolean,SameForAll,true,true,Boolsch,Boolean,,,,,
textNFF,text,None,false,false,Text,Text,,,,,
textNTF,text,None,true,false,Text,Text,,,,,
textNFT,text,None,false,true,Text,Text,,,,,
textNTT,text,None,true,true,Text,Text,,,,,
textUFF,text,Unique,false,false,Text,Text,,,,,
textUTF,text,Unique,true,false,Text,Text,,,,,
textUFT,text,Unique,false,true,Text,Text,,,,,
textUTT,text,Unique,true,true,Text,Text,,,,,
textCFF,text,CombinationUnique,false,false,Text,Text,,,,,
textCTF,text,CombinationUnique,true,false,Text,Text,,,,,
textCFT,text,CombinationUnique,false,true,Text,Text,,,,,
textCTT,text,CombinationUnique,true,true,Text,Text,,,,,
textSFF,text,SameForAll,false,false,Text,Text,,,,,
textSTF,text,SameForAll,true,false,Text,Text,,,,,
textSFT,text,SameForAll,false,true,Text,Text,,,,,
textSTT,text,SameForAll,true,true,Text,Text,,,,,
LocTextNFF,ltext,None,false,false,Lokalisierter Text,Localizable Text,,,,,
LocTextNTF,ltext,None,true,false,Lokalisierter Text,Localizable Text,,,,,
LocTextNFT,ltext,None,false,true,Lokalisierter Text,Localizable Text,,,,,
LocTextNTT,ltext,None,true,true,Lokalisierter Text,Localizable Text,,,,,
LocTextUFF,ltext,Unique,false,false,Lokalisierter Text,Localizable Text,,,,,
LocTextUTF,ltext,Unique,true,false,Lokalisierter Text,Localizable Text,,,,,
LocTextUFT,ltext,Unique,false,true,Lokalisierter Text,Localizable Text,,,,,
LocTextUTT,ltext,Unique,true,true,Lokalisierter Text,Localizable Text,,,,,
LocTextCFF,ltext,CombinationUnique,false,false,Lokalisierter Text,Localizable Text,,,,,
LocTextCTF,ltext,CombinationUnique,true,false,Lokalisierter Text,Localizable Text,,,,,
LocTextCFT,ltext,CombinationUnique,false,true,Lokalisierter Text,Localizable Text,,,,,
LocTextCTT,ltext,CombinationUnique,true,true,Lokalisierter Text,Localizable Text,,,,,
LocTextSFF,ltext,SameForAll,false,false,Lokalisierter Text,Localizable Text,,,,,
LocTextSTF,ltext,SameForAll,true,false,Lokalisierter Text,Localizable Text,,,,,
LocTextSFT,ltext,SameForAll,false,true,Lokalisierter Text,Localizable Text,,,,,
LocTextSTT,ltext,SameForAll,true,true,Lokalisierter Text,Localizable Text,,,,,
textNFF,text,None,false,false,Text,Text,,,,,SingleLine
textNTF,text,None,true,false,Text,Text,,,,,SingleLine
textNFT,text,None,false,true,Text,Text,,,,,SingleLine
textNTT,text,None,true,true,Text,Text,,,,,SingleLine
textUFF,text,Unique,false,false,Text,Text,,,,,SingleLine
textUTF,text,Unique,true,false,Text,Text,,,,,SingleLine
textUFT,text,Unique,false,true,Text,Text,,,,,SingleLine
textUTT,text,Unique,true,true,Text,Text,,,,,SingleLine
textCFF,text,CombinationUnique,false,false,Text,Text,,,,,SingleLine
textCTF,text,CombinationUnique,true,false,Text,Text,,,,,SingleLine
textCFT,text,CombinationUnique,false,true,Text,Text,,,,,SingleLine
textCTT,text,CombinationUnique,true,true,Text,Text,,,,,SingleLine
textSFF,text,SameForAll,false,false,Text,Text,,,,,SingleLine
textSTF,text,SameForAll,true,false,Text,Text,,,,,SingleLine
textSFT,text,SameForAll,false,true,Text,Text,,,,,SingleLine
textSTT,text,SameForAll,true,true,Text,Text,,,,,SingleLine
LocTextNFF,ltext,None,false,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextNTF,ltext,None,true,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextNFT,ltext,None,false,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextNTT,ltext,None,true,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextUFF,ltext,Unique,false,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextUTF,ltext,Unique,true,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextUFT,ltext,Unique,false,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextUTT,ltext,Unique,true,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextCFF,ltext,CombinationUnique,false,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextCTF,ltext,CombinationUnique,true,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextCFT,ltext,CombinationUnique,false,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextCTT,ltext,CombinationUnique,true,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextSFF,ltext,SameForAll,false,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextSTF,ltext,SameForAll,true,false,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextSFT,ltext,SameForAll,false,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
LocTextSTT,ltext,SameForAll,true,true,Lokalisierter Text,Localizable Text,,,,,SingleLine
numberNFF,number,None,false,false,Nummer,Number,,,,,
numberNTF,number,None,true,false,Nummer,Number,,,,,
numberNFT,number,None,false,true,Nummer,Number,,,,,
Expand Down
6 changes: 3 additions & 3 deletions features/common.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ Feature: Show common information for tooling
"attributeConstraint": "CombinationUnique",
"isRequired": false,
"isSearchable": false,
"inputHint": ""
}
"inputHint": "SingleLine"
},
"""
When I run `product-type-update --projectKey import-101-64 --source product-type-boo-txt-num.json`
When I run `product-type-update --projectKey nicola --source product-type-boo-txt-num.json`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this changed?

Copy link
Contributor Author

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

#Then the exit status should be 0
And the output should contain:
"""
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@
},
"main": "main.js",
"engines": {
"node": ">= 0.10.0"
"node": ">= 4"
},
"scripts": {
"test": "grunt coverage"
"test": "grunt coverage",
"build": "grunt build"
},
"dependencies": {
"bluebird": "2.9.x",
Expand All @@ -49,10 +50,12 @@
"optimist": "0.6.x",
"sphere-node-sdk": "1.3.x",
"sphere-node-utils": "0.7.0",
"underscore": "1.8.x",
"sphere-product-type-import": "^1.1.0",
"underscore": "1.8.3",
"underscore.string": "3.1.x"
},
"devDependencies": {
"chai": "^3.5.0",
"coveralls": "2.11.x",
"grunt": "0.4.5",
"grunt-bump": "0.3.x",
Expand All @@ -63,7 +66,7 @@
"grunt-contrib-watch": "0.6.1",
"grunt-shell": "1.1.x",
"istanbul": "0.3.x",
"jasmine-node": "1.14.5",
"mocha": "^3.0.2",
"sphere-coffeelint": "git://github.com/sphereio/sphere-coffeelint.git#master"
},
"keywords": [
Expand Down
4 changes: 3 additions & 1 deletion src/coffee/product-type-generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ class ProductTypeGenerator
label: @_i18n row, "#{ATTRIBUTE_TYPES.enum}Label"
]
when ATTRIBUTE_TYPES.reference
if row['type']
if row['type.referenceTypeId']
type['referenceTypeId'] = row['type.referenceTypeId']
else if row['type']
type['referenceTypeId'] = @_type(@_typeOrElementType(rawTypeName))
when ATTRIBUTE_TYPES.set
# TODO: ensure set is correctly build
Expand Down
85 changes: 85 additions & 0 deletions src/coffee/product-type-import.coffee
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) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the constructor

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had problems with constructor containing asynchronous operation

Copy link
Member

Choose a reason for hiding this comment

The 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 run or import is enough, you just do everything there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to use path.join here

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might consider to put a concurrency limit here

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Loading