mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-09-11 13:45:56 +03:00
This PR is part of porting all old scripts #221 and ports `make_release` folder ## Summary ### make_release/this_week_in_nu_weekly.nu This script has already been ported and has received some updates: #433. So I just removed it ```yaml from: before_v0.60/make_release/this_week_in_nu_weekly.nu to: make_release/this_week_in_nu_weekly.nu functions: do-work: make_release/this_week_in_nu_weekly.nu:1:query-week-span ``` ### make_release/this_week_in_nu_release.nu I have ported this, but I'm not sure if we need it because it has strange name and we have `prs.nu` and `make_release/release-note/` ```yaml from: before_v0.60/make_release/this_week_in_nu_release.nu to: make_release/this_week_in_nu_release.nu functions: do-work: make_release/this_week_in_nu_release.nu:1:do-work ``` ### make_release/nu_release.nu This has already been ported to `make_release/nu_release.nu` and has received new updates #828 so I just removed it ```yaml from: before_v0.60/make_release/nu_release.nu to: make_release/nu_release.nu ``` ### make_release/gen-js-ext.nu This has already been moved to `make_release/gen-js-ext.nu` and has received new updates #621 but not completely ported so I have ported it - pipeline `for` to `each` - `$nu.scope.commands` to `scope commands` - explicit `print` ```yaml from: before_v0.60/make_release/gen-js-ext.nu to: make_release/gen-js-ext.nu functions: gen_keywords: make_release/gen-js-ext.nu:1:gen_keywords gen_sub_keywords: make_release/gen-js-ext.nu:20:gen_sub_keywords ``` ### make_release/gen-ts-ext.nu I have ported this script ```yaml from: before_v0.60/make_release/gen-ts-ext.nu to: make_release/gen-ts-ext.nu functions: gen-ts-cmds-begin: make_release/gen-ts-ext.nu:1:gen-ts-cmds-begin gen-ts-cmds: make_release/gen-ts-ext.nu:18:gen-ts-cmds gen-ts-subs: make_release/gen-ts-ext.nu:40:gen-ts-subs ```
94 lines
4.6 KiB
Plaintext
94 lines
4.6 KiB
Plaintext
def gen-ts-cmds-begin [] {
|
|
# hooray for multi-line strings
|
|
[ "import * as vscode from 'vscode';
|
|
export function activate(context: vscode.ExtensionContext) {
|
|
const keywordsWithSubCommandsProvider = vscode.languages.registerCompletionItemProvider(
|
|
'nushell',
|
|
{
|
|
provideCompletionItems(
|
|
document: vscode.TextDocument,
|
|
position: vscode.Position,
|
|
token: vscode.CancellationToken,
|
|
context: vscode.CompletionContext
|
|
) {
|
|
" ] | str join
|
|
}
|
|
|
|
# generate typescript from nushell commands
|
|
def gen-ts-cmds [] {
|
|
let cmds = (scope commands | where usage != '' | select name usage)
|
|
let updated_cmds = (echo $cmds | insert camel {|it| $it.name + 'Completion' | str camel-case } )
|
|
|
|
let ts = (echo $updated_cmds |
|
|
each {|it|
|
|
let line1 = ([ " const " $it.camel " = new vscode.CompletionItem('" $it.name "');" (char newline) ] | str join)
|
|
let line2 = ([ " " $it.camel ".commitCharacters = [' '];" (char newline) (char newline) ] | str join)
|
|
$line1 + $line2
|
|
} | str join)
|
|
|
|
[
|
|
(echo $ts) (char nl)
|
|
" return [ "
|
|
(echo $updated_cmds | get camel | str join ', ')
|
|
" ];"
|
|
(char nl) ' },' (char nl), ' }' (char nl) ' );'
|
|
(char nl) (char nl)
|
|
] | str join
|
|
}
|
|
|
|
# generate typescript from nushell subcommands
|
|
def gen-ts-subs [] {
|
|
let cmds = (scope commands | where is_sub == true | select name usage | insert base { get name | split column ' ' base sub } | flatten --all)
|
|
let updated_cmds = (echo $cmds | insert camelProvider {|row| $row.base + 'SubCommandsProvider' | str camel-case } | insert method {|row| $row.name | str camel-case})
|
|
let subs_count = (scope commands | where is_sub == true | select name usage | insert base { get name | split column ' ' base sub} | flatten --all | group-by base | transpose cmd cmd_count | update cmd_count { get cmd_count | length })
|
|
let subs_collection = (scope commands | where is_sub == true | select name usage | insert base { get name | split column ' ' base sub} | flatten --all | group-by base | transpose cmd sub_cmds)
|
|
|
|
let ts = ($subs_collection | each {|it|
|
|
let preamble = (get sub_cmds | enumerate | each {|it|
|
|
let method = ([ $it.item.name | str camel-case ] | str join)
|
|
let camel = ([ $it.item.base 'SubCommandsProvider' | str camel-case ] | str join)
|
|
if $it.index == 0 {
|
|
let line01 = ([" const " $camel " = vscode.languages.registerCompletionItemProvider(" (char newline)] | str join)
|
|
let line02 = ([" 'nushell'," (char nl)] | str join)
|
|
let line03 = ([" {" (char nl)] | str join)
|
|
let line04 = ([ " provideCompletionItems(document: vscode.TextDocument, position: vscode.Position) {" (char nl) (char nl) ] | str join)
|
|
let line05 = ([ " const linePrefix = document.lineAt(position).text.substr(0, position.character);" (char nl) ] | str join)
|
|
let line06 = ([ " if (linePrefix.endsWith('" $it.item.base " ')) {" (char nl) (char nl) ] | str join)
|
|
let line07 = ([ " const " $method " = new vscode.CompletionItem('" $it.item.sub "', vscode.CompletionItemKind.Method);" (char nl) ] | str join)
|
|
let line08 = ([ ' ' $method '.detail = "' $it.item.usage '";' (char nl) (char nl) ] | str join)
|
|
$line01 + $line02 + $line03 + $line04 + $line05 + $line06 + $line07 + $line08
|
|
} else {
|
|
let line07 = ([ " const " $method " = new vscode.CompletionItem('" $it.item.sub "', vscode.CompletionItemKind.Method);" (char nl) ] | str join)
|
|
let line08 = ([ ' ' $method '.detail = "' $it.item.usage '";' (char nl) (char nl) ] | str join)
|
|
$line07 + $line08
|
|
}
|
|
} | str join)
|
|
|
|
let methods = (echo $it.sub_cmds.name | str camel-case | str join ', ')
|
|
|
|
let lines = $"
|
|
return [
|
|
($methods)
|
|
];
|
|
} else {
|
|
return undefined;
|
|
}
|
|
}
|
|
},
|
|
' '
|
|
);
|
|
"
|
|
|
|
$preamble + $lines
|
|
} | str join)
|
|
|
|
let post01 = (" context.subscriptions.push(" + (char nl))
|
|
let post02 = ([ " " (echo $updated_cmds | get camelProvider | uniq | str join ', ') (char nl) ] | str join)
|
|
let post03 = ([ " );" (char nl) "}" (char nl) ] | str join)
|
|
|
|
[$ts $post01 $post02 $post03] | str join
|
|
}
|
|
|
|
|
|
[ (gen-ts-cmds-begin) (gen-ts-cmds) (gen-ts-subs) ] | str join | save -f extension.ts
|