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

Capability to detect precedence in scripts? #119

Open
jeffchulg opened this issue Aug 26, 2020 · 5 comments
Open

Capability to detect precedence in scripts? #119

jeffchulg opened this issue Aug 26, 2020 · 5 comments
Labels
enhancement New feature or request

Comments

@jeffchulg
Copy link

Hi,

I've just learned about this module and I would like to know if there is a way to detect dynamically scripts dependencies so that the overall execution will be successful?

I explain myself:
I'm used to create one script per database object. This script is re-runnable (it checks if the object exists or one of its column/index exists and if not => it adds it).
In most of cases, There is a hierarchy between scripts. For instance, the script running the CREATE SCHEMA [a] should be run before any script that will create an object in that schema.

Thanks in advance for the explanation.

@nvarscar
Copy link
Collaborator

Currently, there is no capability of detecting dependancies in the module. And it would be quite an undertaking to implement something like this.
The only way of approaching this that I can see is to implement a language parser that would distinct object dependencies and build them up in a dependency chain. Then it would be possible to rename the files in a proper order.
Not to mention, it becomes significantly more complex to have this functionality across different platforms.

@nvarscar nvarscar assigned nvarscar and unassigned nvarscar Aug 27, 2020
@nvarscar nvarscar added the enhancement New feature or request label Aug 27, 2020
@jeffchulg
Copy link
Author

jeffchulg commented Aug 28, 2020

Well, I've been using Combiner for more than 6 years, even if it's been designed for CSS combination in the first place...

It's written in java, so cross-platform and you only need to add "/*requires <filename>*/" at the beginning of your files.

I don't know why, but it's sometime tricky to get the dependency tree match your need if you have a lot of files, but if you get used to develop "feature-based" or "plugin-based" it works! (the divide and conquer principle)

Hope this helps !

@jeffchulg
Copy link
Author

Here is the code that wraps up combiner:

function Build-File {
    param (
        [string]$BUILT_FILE,
        [string]$BUILD_LOG,
        [string[]]$SRC_STR
    )
    Write-Host "Now building ${BUILT_FILE}"

    java -jar $CombinerToolPath --charset UTF8 -v -e -o ${BUILT_FILE} ${SRC_STR} 2>&1 | Where-Object {$_ -match '\S'} | Out-File -Encoding UTF8 "${BUILD_LOG}" -width 250

    $nbErrors = Select-String -pattern "^\[ERROR\]" -path "${BUILD_LOG}"

    $nbErrors = Select-String -pattern "^\[ERROR\]" -path "${BUILD_LOG}"
    $nbFilesNotFound = Select-String -pattern "Couldn't find file" -path "${BUILD_LOG}"

    if($nbErrors -ne $null) {
        Write-Host "    > ERROR - Check Log ${BUILD_LOG}"
        foreach ($err in $nbErrors) {
            Write-Host "         At line $($err.LineNumber)"
        }
        throw "An error occurred during combiner execution"
    }

    if($nbFilesNotFound -ne $null) {
        Write-Host "    > ERROR - Check Log ${BUILD_LOG}"
        foreach ($err in $nbFilesNotFound) {
            Write-Host "         At line $($err.LineNumber)"
        }
        throw "An error occurred before combiner execution"
    }
    return $true
}

@nvarscar
Copy link
Collaborator

nvarscar commented Sep 1, 2020

So, if I understand correctly, this solution still requires manually added requirements "tag" in the file, and then combines them all in one single file in the right order. That's not exactly a fully automatic precedence detection and you can pretty much achieve the same thing by renaming files to be in a proper precedence order.

@jeffchulg
Copy link
Author

it's nearly correct...

Except that if you number the files and a change comes "between" two consecutive numbers, or involve a complete review or the sequence, then, with this way, you don't need to bother with that, it will be performed dynamically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants