ymotongpoo / vsc-licenser

License handler extension for Visual Studio Code.
Apache License 2.0
45 stars 40 forks source link

Make multiple file mode respects shebang and outputs file names correctly. #91

Closed ReVanTis closed 3 years ago

ReVanTis commented 3 years ago

The original method to add license to multiple files does not respect shebang in shell script or PHP file. And the FILE field in custom license will incorrectly filled with the current file opened in the editor. This pull request attempts to fix this two issues.

ReVanTis commented 3 years ago

こんにちは、やまぐちさん @ymotongpoo

Any chance we could get this patch reviewed soon or you could help loop in a few reviewers? Thanks! ;)

Sorry if this causes any trouble. Typescript could not even count as a second language for me :(

ymotongpoo commented 3 years ago

@ReVanTis thank you for your contribution! TS is my second language too. Can you share some examples of failure caused by the current implementation and how it is fixed with this PR?

ReVanTis commented 3 years ago

Hi @ymotongpoo , To reproduce this issue, you will need to test using the feature implemented by https://github.com/ymotongpoo/vsc-licenser/pull/65 , and select Custom license header.

Steps to reproduce: Sample project for testing: licenser_test.zip

  1. Prepare a few shell scripts with shebang in the first line, like these ones test.sh

    #! /usr/bin/bash
    echo "This is a test script"

    and test2.sh,

    #! /usr/bin/bash
    echo "This is another test script"

    Put these two files under a folder named scripts.

  2. Prepare a .vscode/settings.json like this under the workspace:

    {
    "licenser.projectName": "Test Project",
    "licenser.license": "Custom",
    "licenser.customHeader": "\n@PROJECT@\nFile Name: @FILE@\nCopyright @YEAR@ Do whatever you want with this one."
    }
  3. Open this folder with VS Code, open script/test.sh, then right click script folder, then click "lincenser: Insert license headers to content",

The correct output should be: test.sh

#! /usr/bin/bash
# 
# Test Project
# File Name: test.sh
# Copyright 2020 Do whatever you want with this one.
# 

echo "This is a test script"

test2.sh

#! /usr/bin/bash
# 
# Test Project
# File Name: test2.sh
# Copyright 2020 Do whatever you want with this one.
# 

echo "This is another test script"

However, with current solution, the output would be: test.sh

# 
# Test Project
# File Name: test.sh
# Copyright 2020 Do whatever you want with this one.
# 

#! /usr/bin/bash
echo "This is a test script"

test2.sh

# 
# Test Project
# File Name: test.sh
# Copyright 2020 Do whatever you want with this one.
# 

#! /usr/bin/bash
echo "This is another test script"

And if header is inserted from command palette, the output matches the correct ones.

Result from current solution: licenser_test_origin_result.zip

Result patched: licenser_test_patched_result.zip

ymotongpoo commented 3 years ago

Thank you for your contribution, @ReVanTis ! This looks perfect!