Skip to content

Commit b7ac00d

Browse files
committed
feat: implement custom CLI lang for Prism
1 parent 5636fda commit b7ac00d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+526
-317
lines changed

.vitepress/config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ const {
33
codeBlocksPlugin,
44
markFlavorHeadings,
55
wrapFlavorContainersInTabs,
6+
setupPrismCLILang,
67
} = require('./theme/nativescript-theme/plugins')
78

9+
setupPrismCLILang()
10+
811
module.exports = {
912
lang: 'en-US',
1013
title: 'NativeScript',

.vitepress/theme/nativescript-theme/plugins/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22
Object.defineProperty(exports, '__esModule', { value: true })
3-
exports.wrapFlavorContainersInTabs = exports.markFlavorHeadings = exports.createFlavorContainer = exports.codeBlocksPlugin = void 0
3+
exports.setupPrismCLILang = exports.wrapFlavorContainersInTabs = exports.markFlavorHeadings = exports.createFlavorContainer = exports.codeBlocksPlugin = void 0
44
var code_blocks_1 = require('./code-blocks')
55
Object.defineProperty(exports, 'codeBlocksPlugin', {
66
enumerable: true,
@@ -27,3 +27,10 @@ Object.defineProperty(exports, 'wrapFlavorContainersInTabs', {
2727
return flavor_container_1.wrapFlavorContainersInTabs
2828
},
2929
})
30+
var prism_lang_cli_1 = require('./prism-lang-cli')
31+
Object.defineProperty(exports, 'setupPrismCLILang', {
32+
enumerable: true,
33+
get: function () {
34+
return prism_lang_cli_1.setupPrismCLILang
35+
},
36+
})
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict'
2+
Object.defineProperty(exports, '__esModule', { value: true })
3+
exports.setupPrismCLILang = void 0
4+
const prism = require('prismjs')
5+
function setupPrismCLILang() {
6+
prism.languages.cli = {
7+
comment: [/^#.*/gm, ...prism.languages.js.comment],
8+
output: {
9+
pattern: /^\$\:.*/gms,
10+
greedy: true,
11+
inside: {
12+
hidden: /^\$\:/,
13+
},
14+
},
15+
command: {
16+
// pattern: /^(\S+)\s(.*)/gm,
17+
pattern: /^(?:\$\s)?(?:.+\s\\(?:\r\n|\r|\n))*.+/gm,
18+
inside: {
19+
'command-line-break': {
20+
pattern: /\s\\(?:\r\n|\r|\n)/,
21+
alias: ['comment'],
22+
},
23+
'command-name': {
24+
pattern: /^(?:\$\s)?(\S+)/g,
25+
alias: ['keyword'],
26+
inside: {
27+
visual: /\$\s/,
28+
},
29+
},
30+
'command-flag': {
31+
pattern: /\s-\w\S*\s?/g,
32+
inside: {
33+
punctuation: /^-/,
34+
bold: /\S+/,
35+
},
36+
},
37+
'command-parameter': {
38+
pattern: /\s--\S+([\s=]\S+)?/g,
39+
inside: {
40+
'command-parameter-name': {
41+
pattern: /^(\s--)([\w-]+)/g,
42+
lookbehind: true,
43+
alias: ['bold'],
44+
},
45+
'command-parameter-value': {
46+
pattern: /(\s|=)(?!-)(\S+)/,
47+
lookbehind: true,
48+
alias: ['function-name'],
49+
},
50+
punctuation: /(--|=)/,
51+
},
52+
},
53+
'command-subcommand-name': {
54+
pattern: /^\s\w\S*\s?/g,
55+
alias: ['function'],
56+
},
57+
},
58+
},
59+
}
60+
}
61+
exports.setupPrismCLILang = setupPrismCLILang

.vitepress/theme/nativescript-theme/styles.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,15 @@ div[class*='language-'].line-numbers-mode {
24692469
color: #e2e8f0;
24702470
}
24712471

2472+
.token.visual {
2473+
color: #64748b;
2474+
pointer-events: none;
2475+
-webkit-user-select: none;
2476+
-moz-user-select: none;
2477+
-ms-user-select: none;
2478+
user-select: none;
2479+
}
2480+
24722481
.token.tag,
24732482
.token.namespace {
24742483
color: #e879f9;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Writing Guide from the Vue team we can refer to and follow: https://v3.vuejs.org/guide/contributing/writing-guide.html
22

3-
```shell
3+
```cli
44
git clone https://github.com/NativeScript/docs-new.git
55
npm i
66
npm start

advanced-concepts.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ function generateNativeIOSHMAC() {
155155

156156
5. Build your NativeScript application by running the following and you should see the base64encryptedKey print in your terminal.
157157

158-
```bash
159-
ns clean && ns run ios --no-hmr
158+
```cli
159+
ns clean
160+
ns run ios --no-hmr
160161
```
161162

162163
## iOS Marshalling

best-practices/ios-tips.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,28 @@ For example:
1010

1111
- **BAD**
1212

13-
```
14-
let applePayController: PKPaymentAuthorizationViewController;
15-
16-
applePayController = PKPaymentAuthorizationViewController.alloc().initWithPaymentRequest(paymentRequest);
17-
applePayController.delegate = PKPaymentAuthorizationViewControllerDelegateImpl.initWithOwner(this);
13+
```ts
14+
let applePayController: PKPaymentAuthorizationViewController
15+
16+
applePayController = PKPaymentAuthorizationViewController.alloc().initWithPaymentRequest(
17+
paymentRequest
18+
)
19+
applePayController.delegate = PKPaymentAuthorizationViewControllerDelegateImpl.initWithOwner(
20+
this
21+
)
1822
```
1923

2024
- **GOOD**
2125

22-
```
23-
let applePayController: PKPaymentAuthorizationViewController;
24-
let applePayControllerDelegate: PKPaymentAuthorizationViewControllerDelegateImpl;
25-
26-
applePayController = PKPaymentAuthorizationViewController.alloc().initWithPaymentRequest(paymentRequest);
27-
applePayControllerDelegate = PKPaymentAuthorizationViewControllerDelegateImpl.initWithOwner(this);
28-
applePayController.delegate = applePayControllerDelegate;
26+
```ts
27+
let applePayController: PKPaymentAuthorizationViewController
28+
let applePayControllerDelegate: PKPaymentAuthorizationViewControllerDelegateImpl
29+
30+
applePayController = PKPaymentAuthorizationViewController.alloc().initWithPaymentRequest(
31+
paymentRequest
32+
)
33+
applePayControllerDelegate = PKPaymentAuthorizationViewControllerDelegateImpl.initWithOwner(
34+
this
35+
)
36+
applePayController.delegate = applePayControllerDelegate
2937
```

best-practices/listviews.md

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,33 @@ ListView, RadListView and really any view component that utilizes some form of r
1010

1111
Let's first look at a bad way to setup a ListView row template and why:
1212

13-
```
13+
```xml
1414
<ListView items="{{ myTitles }}" class="list-group">
15-
<ListView.itemTemplate>
16-
<StackLayout>
17-
<r:Render when="{{ !showSomethingElse }}">
18-
<r:Render.template>
19-
<StackLayout backgroundColor="lightblue">
20-
<Label text="{{ title }}" textWrap="true" class="title" />
21-
</StackLayout>
22-
</r:Render.template>
23-
</r:Render>
24-
<r:Render when="{{ showSomethingElse }}">
25-
<r:Render.template>
26-
<GridLayout rows="auto,5,auto,5,auto" backgroundColor="red">
27-
<Label text="{{ title }}" textWrap="true" class="title" />
28-
<Label row="2" text="Something Else" textWrap="true" class="title" />
29-
<Label row="4" text="Could show yet anything thing here" textWrap="true" class="title" />
30-
</GridLayout>
31-
</r:Render.template>
32-
</r:Render>
33-
</StackLayout>
34-
</ListView.itemTemplate>
15+
<ListView.itemTemplate>
16+
<StackLayout>
17+
<r:Render when="{{ !showSomethingElse }}">
18+
<r:Render.template>
19+
<StackLayout backgroundColor="lightblue">
20+
<Label text="{{ title }}" textWrap="true" class="title" />
21+
</StackLayout>
22+
</r:Render.template>
23+
</r:Render>
24+
<r:Render when="{{ showSomethingElse }}">
25+
<r:Render.template>
26+
<GridLayout rows="auto,5,auto,5,auto" backgroundColor="red">
27+
<Label text="{{ title }}" textWrap="true" class="title" />
28+
<Label row="2" text="Something Else" textWrap="true" class="title" />
29+
<Label
30+
row="4"
31+
text="Could show yet anything thing here"
32+
textWrap="true"
33+
class="title"
34+
/>
35+
</GridLayout>
36+
</r:Render.template>
37+
</r:Render>
38+
</StackLayout>
39+
</ListView.itemTemplate>
3540
</ListView>
3641
```
3742

@@ -41,7 +46,7 @@ This is bad because it causes the creation and destruction of view elements whil
4146

4247
## Good setup
4348

44-
```
49+
```xml
4550
<ListView items="{{ myTitles }}" class="list-group" itemTemplateSelector="{{selectItemTemplate}}">
4651
<ListView.itemTemplates>
4752
<template key="onelayout">

best-practices/native-class.md

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ There's a couple things to note about it's usage.
1010

1111
When using the custom native class within the same file you can define it as follows:
1212

13-
```
13+
```ts
1414
@NativeClass()
15-
class CustomClass extends NSObject {
16-
17-
}
15+
class CustomClass extends NSObject {}
1816

19-
const customClass = CustomClass.new();
17+
const customClass = CustomClass.new()
2018
```
2119

2220
This allows the code to be compiled naturally and will work as expected.
@@ -25,26 +23,22 @@ This allows the code to be compiled naturally and will work as expected.
2523

2624
You can use setup methods in this case to mitigate any cross compilation issue, for example:
2725

28-
```
29-
let customClass;
26+
```ts
27+
let customClass
3028
function setupCustomClass() {
3129
if (global.isAndroid) {
3230
@NativeClass()
33-
class CustomClass extends android.view.View {
34-
35-
}
36-
customClass = CustomClass;
31+
class CustomClass extends android.view.View {}
32+
customClass = CustomClass
3733
} else {
3834
@NativeClass()
39-
class CustomClass extends NSObject {
40-
41-
}
42-
customClass = CustomClass;
35+
class CustomClass extends NSObject {}
36+
customClass = CustomClass
4337
}
4438
}
4539

46-
setupCustomClass();
47-
const myClass = new customClass(); // can handle different platform args with ternary if needed
40+
setupCustomClass()
41+
const myClass = new customClass() // can handle different platform args with ternary if needed
4842
```
4943

5044
The `global.isAndroid` conditional will get removed when building the app for iOS so your compiled code is clean and isolated while allowing you to handle in a single file.
@@ -53,15 +47,13 @@ The `global.isAndroid` conditional will get removed when building the app for iO
5347

5448
Since the `@NativeClass()` decorator modifies the JS syntax to work with the NativeScript runtimes you want to ensure the symbol is exported properly when using that outside of the file it's defined. Here's how you can do that:
5549

56-
```
50+
```ts
5751
// custom-class.ts
5852
@NativeClass()
59-
class CustomClass extends NSObject {
60-
61-
}
53+
class CustomClass extends NSObject {}
6254

63-
export { CustomClass };
55+
export { CustomClass }
6456

6557
// usage.ts
66-
import { CustomClass } from './custom-class';
58+
import { CustomClass } from './custom-class'
6759
```

best-practices/rogue-timers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ One single timeout left unprotected or otherwise kept in check can lead to devas
1010

1111
It's always recommended to track your timeouts and intervals and clean them up properly when no longer needed:
1212

13-
```
13+
```ts
1414
this.myTimeout = setTimeout(() => {
1515
// something
1616
}, 2000);
@@ -26,7 +26,7 @@ cleanup() {
2626

2727
Intervals are the worst case as they can go on forever eating up valuable device resources your app wants to provide a good user experience. In the most offending cases, they double up and continue to eat away at the UX of an app.
2828

29-
```
29+
```ts
3030
this.myInterval = setInterval(() => {
3131
// something
3232
}, 2000);

best-practices/view-bindings.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@ You want fast view rendering and responsible view bindings are the first step to
88

99
### Bad:
1010

11-
```
11+
```xml
1212
// view markup
1313
<Label text="{{getMyText}} />
14+
```
1415
16+
<!-- -->
17+
18+
```ts
1519
// view binding class
1620
export class ViewBinding extends Observable {
17-
1821
getMyText() {
19-
return 'label text';
22+
return 'label text'
2023
}
2124
}
2225
```
@@ -25,14 +28,17 @@ This leads to developers doing logic in methods and can cause unnecessary view b
2528
2629
### Good:
2730
28-
```
31+
```xml
2932
// view markup
3033
<Label text="{{myText}} />
34+
```
3135

36+
<!-- -->
37+
38+
```ts
3239
// view binding class
3340
export class ViewBinding extends Observable {
34-
35-
myText = 'label text';
41+
myText = 'label text'
3642
}
3743
```
3844

0 commit comments

Comments
 (0)