Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

fix: Failing generator-swiftserver integration tests for SDKGen service #412

Merged
merged 10 commits into from
Jan 10, 2018
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ coverage/
coverage.lcov
.vscode/
*.swp
.DS_Store
24 changes: 6 additions & 18 deletions lib/sdkGenHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
var re = /\.package\(url:\s"https:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*).git",\s(\.upToNextMinor|\.upToNextMajor)\(from:\s"(-?\d+\.){2}-?\d+"\)\),?/g
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'))
}
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 []
Expand Down
107 changes: 78 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion refresh/templates/common/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 { _%>
]),
Expand Down
Binary file modified test/resources/dummy_PackageSDK.zip
Binary file not shown.