DefinitelyTyped / NugetAutomation

Automatically generate nuget packages for the DefinetlyTyped TypeScript definitions.
Other
26 stars 10 forks source link

Automatically figure out dependencies #5

Closed staxmanade closed 11 years ago

staxmanade commented 11 years ago

We should be able to read the following from /// <reference path="????????" /> the d.ts files and determine the dependencies.

Given the above we can then fill out nuget dependencies in the nuspec file.

Diullei commented 11 years ago

@staxmanade, I created this code snippet to parse a *.ts file and search all dependencies. I'm not a PowerShell developer and I don't know how to complete this code to put on your script.

Function Get-Dependencies($file)
{
    $fileContent = get-content $file

    for ($i = 0; $i -lt $fileContent.length; $i++)
    {
        if ([regex]::ismatch($fileContent[$i],"//.*(reference\spath='.*\.ts'|reference\spath="".*\.ts"")"))
        {
            if($fileContent[$i].IndexOf("'") -ne -1)
            {
                                    # found dependence file
                Write-Host $fileContent[$i].Split("'")[1]
            }
            elseif($fileContent[$i].IndexOf("""") -ne -1)
            {
                                    # found dependence file
                Write-Host $fileContent[$i].Split("""")[1]
            }
        }
    }
}

NOTE:

fileA.ts

// <reference path="fileB.ts" />

//... some code ...

fileB.ts

// <reference path="fileA.ts" />

//... some code ...

We will have a cyclic reference. The Get-Dependencies(...) function must be recursive and must verify cyclic references to avoid infinite loop.

Diullei commented 11 years ago

I'm mistaken, this is not a recursive function. Not have infinite loop. Sorry.

staxmanade commented 11 years ago

This is a good head-start... Helps me not to have to figure out some regexes. Thanks for posting this.

staxmanade commented 11 years ago

I got this implemented. Also found a bug by using it and submitted a PR https://github.com/borisyankov/DefinitelyTyped/pull/306

Diullei commented 11 years ago

I accepted your pullrequest!

staxmanade commented 11 years ago

Thanks :+1: