diff --git a/.gitignore b/.gitignore index ba382ff8..b6049593 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ coverage/ coverage.lcov .vscode/ *.swp +.DS_Store diff --git a/lib/sdkGenHelper.js b/lib/sdkGenHelper.js index 86a74783..6f396653 100644 --- a/lib/sdkGenHelper.js +++ b/lib/sdkGenHelper.js @@ -139,7 +139,6 @@ exports.getServerSDKAsync = function (sdkName, generatedID) { .pipe(unzip.Extract({ path: tempDir })) .on('close', () => { debug(`finished server SDK download and unzip for ${sdkName} from ${serverDownloadURL} to ${tempDir}`) - var sdkDir = path.join(tempDir, sdkName) debug(`reading package dependencies from server SDK ${sdkName} in ${sdkDir}`) try { @@ -158,27 +157,16 @@ function ensureTrailingComma (string) { function readPackageDependencies (sdkName, sdkDir) { var originFile = fs.readFileSync(sdkDir + '/Package.swift', 'utf8') - var originMatches = originFile.match(/\.\bPackage\b.*/g) - var parsedDependencies = null + var originMatches = originFile.match(/\.\bpackage\b.*/g) if (originMatches) { - parsedDependencies = [] - // input : .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 7) - // output : .package(url: "https://github.com/IBM-Swift/Kitura.git", .upToNextMinor(from : "1.7.0") - originMatches.forEach(function (dependency) { - if (dependency.indexOf('minor') < 0) { - throw Error(chalk.red('SDKGEN Package dependency format is incompatible')) + var re = /\.package\(url:\s"https:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*).git",\s((\.upToNextMajor|\.upToNextMinor)\(from:\s"(-?\d+\.){2}-?\d+"\)|from:\s"(-?\d+\.){2}-?\d+")\),?$/ + debug(`found ${originMatches.length} package dependencies in server SDK ${sdkName}`) + return originMatches.map(function (m) { + if (!re.test(m)) { + throw Error(chalk.red('SDKGEN Package dependency format is incompatible with input: ' + m)) } - dependency = dependency.replace('Package', 'package') - var commaSplit = dependency.split(',') - var majorVersion = commaSplit[1].replace(/[^0-9.]/g, '') - var minor = commaSplit[2].replace(/[^0-9.]/g, '') - dependency = commaSplit[0] + ', .upToNextMinor( from:"' + majorVersion + '.' + minor + '.0"))' - parsedDependencies.push(dependency) + return ensureTrailingComma(m.trim()) }) - } - if (parsedDependencies) { - debug(`found ${parsedDependencies.length} package dependencies in server SDK ${sdkName}`) - return parsedDependencies.map(m => ensureTrailingComma(m.trim())) } else { debug(`found no package dependencies in server SDK ${sdkName}`) return [] diff --git a/package-lock.json b/package-lock.json index 6944f580..357a2a15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2020,21 +2020,34 @@ } }, "generator-ibm-cloud-enablement": { - "version": "0.0.114", - "resolved": "https://registry.npmjs.org/generator-ibm-cloud-enablement/-/generator-ibm-cloud-enablement-0.0.114.tgz", - "integrity": "sha512-mSdjSmtTq21KrGyX/48TWOT64EtFU2/l17TBMruKGo8K2YuE/ok/hMI1CEhRkQeEOHG0fh6iQw+yrNYKeGzfTQ==", + "version": "0.6.11", + "resolved": "https://registry.npmjs.org/generator-ibm-cloud-enablement/-/generator-ibm-cloud-enablement-0.6.11.tgz", + "integrity": "sha512-o3kIKuLCA6z2TZq4H1r/ghUOg3BYULS2t1oc4MDu6D0BNjC2JDhTDQp8HZpdu2LNCuPqjP++6ChXe8LBtwJz6g==", "requires": { "fs-extra": "2.1.2", - "handlebars": "4.0.10", + "handlebars": "4.0.11", "js-yaml": "3.10.0", "lodash": "4.17.4", "yeoman-generator": "1.1.1" + }, + "dependencies": { + "handlebars": { + "version": "4.0.11", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.0.11.tgz", + "integrity": "sha1-Ywo13+ApS8KB7a5v/F0yn8eYLcw=", + "requires": { + "async": "1.5.2", + "optimist": "0.6.1", + "source-map": "0.4.4", + "uglify-js": "2.8.29" + } + } } }, "generator-ibm-service-enablement": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/generator-ibm-service-enablement/-/generator-ibm-service-enablement-0.6.1.tgz", - "integrity": "sha512-7kWYDw3Wr0IGV9pq7qyvZ6Q1lgYKwcKlIxbt/b7RfPWeC4/Kr7tVFzwXoLJGVVEmxgdTGKEL7V38asYgLa+Wpg==", + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/generator-ibm-service-enablement/-/generator-ibm-service-enablement-0.6.4.tgz", + "integrity": "sha512-gG4lynu4ZwyLTwAOz0qUSvh9qfJpm63gu0Kt+exFvXkcV6Gi+fk5RPH0XnGnMpLb0LvCy/E7rMxEdsHIhU00iQ==", "requires": { "handlebars": "4.0.10", "lodash": "4.17.4", @@ -2043,9 +2056,9 @@ } }, "generator-ibm-usecase-enablement": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/generator-ibm-usecase-enablement/-/generator-ibm-usecase-enablement-3.0.0.tgz", - "integrity": "sha512-vkQOWGcywXv1Me+fgDh3I0Uud5TH4jL0S6QJ9W+lNqGwNy4iehnn3ppTqL5JZpSEdls5TMn4gUV9c96MxyvOJw==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/generator-ibm-usecase-enablement/-/generator-ibm-usecase-enablement-3.1.2.tgz", + "integrity": "sha512-cMHl0uea0jAU9HY3L7WtZ0Hv4l+dbo4cgep+y64fCoxWYmUnE0Yj9ngPiy5jB7Q23MfUn8JnjebaPEoXJ+7J8Q==", "requires": { "glob": "7.1.2", "guid": "0.0.12", @@ -2056,6 +2069,7 @@ "minimatch": "3.0.4", "q": "1.5.0", "request": "2.83.0", + "shelljs": "0.7.8", "yeoman-generator": "1.1.1" } }, diff --git a/refresh/templates/common/Package.swift b/refresh/templates/common/Package.swift index 50d071f0..d4f2919e 100644 --- a/refresh/templates/common/Package.swift +++ b/refresh/templates/common/Package.swift @@ -24,7 +24,7 @@ let package = Package( <% }); -%> ]), <% Object.keys(sdkTargets).forEach(function(target) { -%> - .target(name: "<%- sdkTargets[target] %>", dependencies: ["ObjectMapper","SimpleHttpClient"], path: "Sources/<%- sdkTargets[target] %>" ), + .target(name: "<%- sdkTargets[target] %>", dependencies: ["SimpleHttpClient"], path: "Sources/<%- sdkTargets[target] %>" ), <% }); -%> <% }else { _%> ]), diff --git a/test/resources/dummy_PackageSDK.zip b/test/resources/dummy_PackageSDK.zip index f39403ed..32ac4c99 100644 Binary files a/test/resources/dummy_PackageSDK.zip and b/test/resources/dummy_PackageSDK.zip differ diff --git a/test/unit/refresh.js b/test/unit/refresh.js index 0d63de43..22a171a7 100644 --- a/test/unit/refresh.js +++ b/test/unit/refresh.js @@ -1005,7 +1005,7 @@ describe('Unit tests for swiftserver:refresh', function () { it(`should throw error`, function () { assert(error, 'Should throw an error') - assert(error.match(/SDKGEN.*incompatible/), 'Thrown error should be about failing to parse SDK package dependency, it was: ' + error) + assert(error.match(/SDKGEN.*incompatible.*.package\(url: ".*", from: "1\.0"\)/), 'Thrown error should be about failing to parse SDK package dependency, it was: ' + error) }) }) })