scripting-cli 1.1.12 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -30
- package/README_de.md +106 -0
- package/README_fr.md +106 -0
- package/README_it.md +106 -0
- package/README_ja.md +106 -0
- package/README_zh.md +42 -31
- package/dist/controller.js +7 -13
- package/dist/index.js +14 -0
- package/dist/start_server.js +40 -30
- package/dist/util.js +58 -2
- package/package.json +2 -2
- package/src/controller.ts +8 -17
- package/src/index.ts +17 -2
- package/src/start_server.ts +49 -37
- package/src/util.ts +66 -2
package/README.md
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
# Scripting
|
|
1
|
+
# Scripting App Command-Line Tool
|
|
2
2
|
|
|
3
|
-
Welcome to the `scripting-cli
|
|
3
|
+
Welcome to the `scripting-cli`, the command-line tool designed for integrating with the Scripting app. This tool allows you to synchronize and preview your scripts in real-time as you develop them using your favorite desktop editor, such as VSCode.
|
|
4
4
|
|
|
5
|
-
[
|
|
5
|
+
[中文](./README_zh.md) | [日本語](./README_ja.md) | [Deutsch](./README_de.md) | [Français](./README_fr.md) | [Italiano](./README_it.md)
|
|
6
6
|
|
|
7
7
|
## Prerequisites
|
|
8
8
|
|
|
9
|
-
Before using `scripting-cli`,
|
|
9
|
+
Before using `scripting-cli`, ensure the following requirements are met:
|
|
10
|
+
|
|
11
|
+
1. **Node.js**: Make sure you have a recent version of Node.js installed. To check your current version, run:
|
|
10
12
|
|
|
11
|
-
1. **Node.js**: Ensure you have a recent version of Node.js installed. You can check your Node.js version by running:
|
|
12
13
|
```bash
|
|
13
14
|
node -v
|
|
14
15
|
```
|
|
15
16
|
|
|
16
|
-
2. **Scripting App**: The Scripting app must be installed to connect with the local service
|
|
17
|
+
2. **Scripting App**: The Scripting app must be installed in order to connect with the local service started by `scripting-cli`.
|
|
17
18
|
|
|
18
19
|
## Installation
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
There’s no need to install `scripting-cli` globally. Simply run it using `npx`:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx scripting-cli <command>
|
|
25
|
+
```
|
|
21
26
|
|
|
22
27
|
## Usage
|
|
23
28
|
|
|
24
29
|
### 1. Create a Working Directory
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
Start by creating a directory where your Scripting app scripts will reside. For example:
|
|
32
|
+
|
|
27
33
|
```bash
|
|
28
34
|
mkdir my-scripting-project
|
|
29
35
|
cd my-scripting-project
|
|
@@ -31,65 +37,70 @@ cd my-scripting-project
|
|
|
31
37
|
|
|
32
38
|
### 2. Start the Local Service
|
|
33
39
|
|
|
34
|
-
In your working directory, run the following command to start the local service:
|
|
40
|
+
In your working directory, run the following command to start the local development service:
|
|
35
41
|
|
|
36
42
|
```bash
|
|
37
43
|
npx scripting-cli start
|
|
38
44
|
```
|
|
39
45
|
|
|
40
|
-
By default, this
|
|
46
|
+
By default, this starts the service on port `3000`. To specify a different port, use the `--port` option:
|
|
41
47
|
|
|
42
48
|
```bash
|
|
43
|
-
npx scripting-cli start --port
|
|
49
|
+
npx scripting-cli start --port=4000
|
|
44
50
|
```
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
To enable Bonjour support—allowing the Scripting app to automatically detect the local service—add the `--bonjour` flag:
|
|
53
|
+
|
|
47
54
|
```bash
|
|
48
|
-
npx scripting-cli start --
|
|
55
|
+
npx scripting-cli start --bonjour
|
|
49
56
|
```
|
|
50
57
|
|
|
51
58
|
### 3. Connect the Scripting App
|
|
52
59
|
|
|
53
|
-
Once the service is running, open the **Scripting app** and
|
|
60
|
+
Once the service is running, open the **Scripting app** and connect to the local service you just started. This establishes a connection between the app and your working directory.
|
|
54
61
|
|
|
55
|
-
### 4. Debug and Synchronize Code
|
|
62
|
+
### 4. Debug and Synchronize Your Code
|
|
56
63
|
|
|
57
|
-
After connecting,
|
|
64
|
+
After connecting, select the script project you want to debug. The Scripting app will automatically sync the project’s code with your working directory.
|
|
58
65
|
|
|
59
66
|
### 5. Real-Time Code Synchronization
|
|
60
67
|
|
|
61
|
-
As you write and save scripts
|
|
68
|
+
As you write and save scripts using your desktop editor (e.g., VSCode), the changes will automatically sync with the Scripting app and be executed in real-time—making development and debugging much smoother.
|
|
62
69
|
|
|
63
70
|
## Example Workflow
|
|
64
71
|
|
|
65
72
|
1. Start the local service:
|
|
73
|
+
|
|
66
74
|
```bash
|
|
67
75
|
npx scripting-cli start
|
|
68
76
|
```
|
|
69
77
|
|
|
70
|
-
2. Open your
|
|
78
|
+
2. Open your editor and write your script.
|
|
71
79
|
|
|
72
80
|
3. Save the script file.
|
|
73
81
|
|
|
74
|
-
4. The code automatically
|
|
82
|
+
4. The updated code is automatically synchronized with the Scripting app and executed.
|
|
75
83
|
|
|
76
84
|
## Additional Information
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
* The default port is `3000`. If it’s already in use, specify a different one with the `--port` option.
|
|
87
|
+
* Use the `--no-auto-open` flag to prevent the tool from opening `index.tsx` or `widget.tsx` automatically:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx scripting-cli start --no-auto-open
|
|
91
|
+
```
|
|
92
|
+
* To use the Bonjour service, ensure your system supports it. On Windows, you may need to install Bonjour manually. Then, use the `--bonjour` option to enable it.
|
|
93
|
+
* This tool is ideal for users who prefer desktop editors like VSCode and want seamless code synchronization and debugging with the Scripting app.
|
|
84
94
|
|
|
85
95
|
## Troubleshooting
|
|
86
96
|
|
|
87
|
-
If you encounter
|
|
97
|
+
If you encounter issues:
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
* Ensure you're using Node.js version 20 or higher.
|
|
100
|
+
* Verify the Scripting app is properly connected to the local service.
|
|
101
|
+
* Make sure no other process is occupying your chosen port.
|
|
102
|
+
* Always run the tool using `npx scripting-cli <command>`, and check that the package is up to date.
|
|
92
103
|
|
|
93
104
|
---
|
|
94
105
|
|
|
95
|
-
Enjoy using `scripting-cli`
|
|
106
|
+
Enjoy using `scripting-cli` in your Scripting app development workflow. Happy coding!
|
package/README_de.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Scripting-App-Befehlszeilentool
|
|
2
|
+
|
|
3
|
+
Willkommen beim `scripting-cli`, dem Befehlszeilentool für die Integration mit der Scripting-App. Dieses Tool ermöglicht es Ihnen, Ihre Skripte in Echtzeit zu synchronisieren und während der Entwicklung mit Ihrem bevorzugten Desktop-Editor, wie z. B. VSCode, anzuzeigen.
|
|
4
|
+
|
|
5
|
+
[English](./README.md) | [中文](./README_zh.md) | [日本語](./README_ja.md) | [Français](./README_fr.md) | [Italiano](./README_it.md)
|
|
6
|
+
|
|
7
|
+
## Voraussetzungen
|
|
8
|
+
|
|
9
|
+
Bevor Sie `scripting-cli` verwenden, stellen Sie sicher, dass die folgenden Anforderungen erfüllt sind:
|
|
10
|
+
|
|
11
|
+
1. **Node.js**: Stellen Sie sicher, dass eine aktuelle Version von Node.js installiert ist. Überprüfen Sie Ihre aktuelle Version mit:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
node -v
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. **Scripting-App**: Die Scripting-App muss installiert sein, um eine Verbindung mit dem lokalen Dienst herzustellen, der von `scripting-cli` gestartet wird.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Es ist keine globale Installation von `scripting-cli` erforderlich. Führen Sie es einfach mit `npx` aus:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx scripting-cli <command>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Verwendung
|
|
28
|
+
|
|
29
|
+
### 1. Arbeitsverzeichnis erstellen
|
|
30
|
+
|
|
31
|
+
Erstellen Sie ein Verzeichnis, in dem Ihre Scripting-App-Skripte gespeichert werden. Zum Beispiel:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
mkdir my-scripting-project
|
|
35
|
+
cd my-scripting-project
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. Lokalen Dienst starten
|
|
39
|
+
|
|
40
|
+
Führen Sie im Arbeitsverzeichnis den folgenden Befehl aus, um den lokalen Entwicklungsdienst zu starten:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx scripting-cli start
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Standardmäßig wird der Dienst auf Port `3000` gestartet. Um einen anderen Port anzugeben, verwenden Sie die Option `--port`:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx scripting-cli start --port=4000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Um Bonjour-Unterstützung zu aktivieren, sodass die Scripting-App den lokalen Dienst automatisch erkennt, fügen Sie das Flag `--bonjour` hinzu:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx scripting-cli start --bonjour
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Scripting-App verbinden
|
|
59
|
+
|
|
60
|
+
Sobald der Dienst läuft, öffnen Sie die **Scripting-App** und verbinden Sie sich mit dem gerade gestarteten lokalen Dienst. Dadurch wird eine Verbindung zwischen der App und Ihrem Arbeitsverzeichnis hergestellt.
|
|
61
|
+
|
|
62
|
+
### 4. Code debuggen und synchronisieren
|
|
63
|
+
|
|
64
|
+
Nach der Verbindung wählen Sie das Skriptprojekt aus, das Sie debuggen möchten. Die Scripting-App synchronisiert den Code dieses Projekts automatisch mit Ihrem Arbeitsverzeichnis.
|
|
65
|
+
|
|
66
|
+
### 5. Echtzeit-Code-Synchronisierung
|
|
67
|
+
|
|
68
|
+
Wenn Sie Skripte in Ihrem Desktop-Editor (z. B. VSCode) schreiben und speichern, werden die Änderungen automatisch mit der Scripting-App synchronisiert und in Echtzeit ausgeführt, was die Entwicklung und das Debugging erheblich erleichtert.
|
|
69
|
+
|
|
70
|
+
## Beispiel-Workflow
|
|
71
|
+
|
|
72
|
+
1. Lokalen Dienst starten:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npx scripting-cli start
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
2. Öffnen Sie Ihren Editor und schreiben Sie Ihr Skript.
|
|
79
|
+
|
|
80
|
+
3. Speichern Sie die Skriptdatei.
|
|
81
|
+
|
|
82
|
+
4. Der aktualisierte Code wird automatisch mit der Scripting-App synchronisiert und ausgeführt.
|
|
83
|
+
|
|
84
|
+
## Zusätzliche Informationen
|
|
85
|
+
|
|
86
|
+
* Der Standardport ist `3000`. Wenn dieser bereits verwendet wird, geben Sie mit der Option `--port` einen anderen an.
|
|
87
|
+
* Verwenden Sie das Flag `--no-auto-open`, um zu verhindern, dass das Tool automatisch `index.tsx` oder `widget.tsx` öffnet:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx scripting-cli start --no-auto-open
|
|
91
|
+
```
|
|
92
|
+
* Um den Bonjour-Dienst zu nutzen, stellen Sie sicher, dass Ihr System diese Funktion unterstützt. Unter Windows müssen Sie Bonjour möglicherweise manuell installieren. Verwenden Sie dann die Option `--bonjour`, um den Dienst zu aktivieren.
|
|
93
|
+
* Dieses Tool ist ideal für Benutzer, die Desktop-Editoren wie VSCode bevorzugen und eine nahtlose Code-Synchronisierung und Debugging mit der Scripting-App wünschen.
|
|
94
|
+
|
|
95
|
+
## Fehlerbehebung
|
|
96
|
+
|
|
97
|
+
Wenn Sie auf Probleme stoßen, stellen Sie sicher, dass:
|
|
98
|
+
|
|
99
|
+
* Sie Node.js Version 20 oder höher verwenden.
|
|
100
|
+
* Die Scripting-App korrekt mit dem lokalen Dienst verbunden ist.
|
|
101
|
+
* Der von Ihnen gewählte Port nicht von einem anderen Prozess verwendet wird.
|
|
102
|
+
* Sie das Tool immer mit `npx scripting-cli <command>` ausführen und sicherstellen, dass das Paket auf dem neuesten Stand ist.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
Viel Spaß beim Verwenden von `scripting-cli` in Ihrem Scripting-App-Entwicklungsworkflow! Viel Erfolg beim Codieren!
|
package/README_fr.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Outil en ligne de commande pour l'application Scripting
|
|
2
|
+
|
|
3
|
+
Bienvenue dans `scripting-cli`, l'outil en ligne de commande conçu pour l'intégration avec l'application Scripting. Cet outil vous permet de synchroniser et de prévisualiser vos scripts en temps réel pendant que vous les développez à l'aide de votre éditeur de bureau préféré, tel que VSCode.
|
|
4
|
+
|
|
5
|
+
[English](./README.md) | [中文](./README_zh.md) | [日本語](./README_ja.md) | [Deutsch](./README_de.md) | [Italiano](./README_it.md)
|
|
6
|
+
|
|
7
|
+
## Prérequis
|
|
8
|
+
|
|
9
|
+
Avant d'utiliser `scripting-cli`, assurez-vous que les conditions suivantes sont remplies :
|
|
10
|
+
|
|
11
|
+
1. **Node.js** : Assurez-vous qu'une version récente de Node.js est installée. Vérifiez votre version actuelle avec :
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
node -v
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. **Application Scripting** : L'application Scripting doit être installée pour se connecter au service local lancé par `scripting-cli`.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
Il n'est pas nécessaire d'installer `scripting-cli` globalement. Exécutez-le simplement avec `npx` :
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx scripting-cli <command>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Utilisation
|
|
28
|
+
|
|
29
|
+
### 1. Créer un répertoire de travail
|
|
30
|
+
|
|
31
|
+
Créez un répertoire où vos scripts de l'application Scripting seront stockés. Par exemple :
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
mkdir my-scripting-project
|
|
35
|
+
cd my-scripting-project
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. Démarrer le service local
|
|
39
|
+
|
|
40
|
+
Dans votre répertoire de travail, exécutez la commande suivante pour démarrer le service de développement local :
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx scripting-cli start
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Par défaut, ce service démarre sur le port `3000`. Pour spécifier un autre port, utilisez l'option `--port` :
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx scripting-cli start --port=4000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Pour activer la prise en charge de Bonjour, permettant à l'application Scripting de détecter automatiquement le service local, ajoutez le drapeau `--bonjour` :
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx scripting-cli start --bonjour
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Connecter l'application Scripting
|
|
59
|
+
|
|
60
|
+
Une fois le service en cours d'exécution, ouvrez l'**application Scripting** et connectez-vous au service local que vous venez de démarrer. Cela établira une connexion entre l'application et votre répertoire de travail.
|
|
61
|
+
|
|
62
|
+
### 4. Déboguer et synchroniser le code
|
|
63
|
+
|
|
64
|
+
Après la connexion, sélectionnez le projet de script que vous souhaitez déboguer. L'application Scripting synchronisera automatiquement le code de ce projet avec votre répertoire de travail.
|
|
65
|
+
|
|
66
|
+
### 5. Synchronisation du code en temps réel
|
|
67
|
+
|
|
68
|
+
Lorsque vous écrivez et enregistrez des scripts dans votre éditeur de bureau (par exemple, VSCode), les modifications seront automatiquement synchronisées avec l'application Scripting et exécutées en temps réel, rendant le développement et le débogage beaucoup plus fluides.
|
|
69
|
+
|
|
70
|
+
## Exemple de flux de travail
|
|
71
|
+
|
|
72
|
+
1. Démarrer le service local :
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npx scripting-cli start
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
2. Ouvrez votre éditeur et écrivez votre script.
|
|
79
|
+
|
|
80
|
+
3. Enregistrez le fichier de script.
|
|
81
|
+
|
|
82
|
+
4. Le code mis à jour est automatiquement synchronisé avec l'application Scripting et exécuté.
|
|
83
|
+
|
|
84
|
+
## Informations supplémentaires
|
|
85
|
+
|
|
86
|
+
* Le port par défaut est `3000`. S'il est déjà utilisé, spécifiez-en un autre avec l'option `--port`.
|
|
87
|
+
* Utilisez le drapeau `--no-auto-open` pour empêcher l'outil d'ouvrir automatiquement `index.tsx` ou `widget.tsx` :
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx scripting-cli start --no-auto-open
|
|
91
|
+
```
|
|
92
|
+
* Pour utiliser le service Bonjour, assurez-vous que votre système le prend en charge. Sur Windows, vous devrez peut-être installer Bonjour manuellement. Ensuite, utilisez l'option `--bonjour` pour l'activer.
|
|
93
|
+
* Cet outil est idéal pour les utilisateurs qui préfèrent les éditeurs de bureau comme VSCode et souhaitent une synchronisation et un débogage du code sans faille avec l'application Scripting.
|
|
94
|
+
|
|
95
|
+
## Dépannage
|
|
96
|
+
|
|
97
|
+
Si vous rencontrez des problèmes, assurez-vous que :
|
|
98
|
+
|
|
99
|
+
* Vous utilisez Node.js version 20 ou supérieure.
|
|
100
|
+
* L'application Scripting est correctement connectée au service local.
|
|
101
|
+
* Aucun autre processus n'utilise le port que vous souhaitez utiliser.
|
|
102
|
+
* Vous exécutez toujours l'outil avec `npx scripting-cli <command>` et que le package est à jour.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
Profitez de l'utilisation de `scripting-cli` dans votre flux de travail de développement avec l'application Scripting ! Bon codage !
|
package/README_it.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Strumento da linea di comando per l'app Scripting
|
|
2
|
+
|
|
3
|
+
Benvenuto in `scripting-cli`, lo strumento da linea di comando progettato per l'integrazione con l'app Scripting. Questo strumento ti consente di sincronizzare e visualizzare in anteprima i tuoi script in tempo reale mentre li sviluppi utilizzando il tuo editor desktop preferito, come VSCode.
|
|
4
|
+
|
|
5
|
+
[English](./README.md) | [中文](./README_zh.md) | [日本語](./README_ja.md) | [Deutsch](./README_de.md) | [Français](./README_fr.md)
|
|
6
|
+
|
|
7
|
+
## Prerequisiti
|
|
8
|
+
|
|
9
|
+
Prima di utilizzare `scripting-cli`, assicurati di avere quanto segue:
|
|
10
|
+
|
|
11
|
+
1. **Node.js**: Verifica di avere una versione recente di Node.js installata. Puoi controllare la tua versione eseguendo:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
node -v
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. **App Scripting**: L'app Scripting deve essere installata per potersi connettere al servizio locale avviato da `scripting-cli`.
|
|
18
|
+
|
|
19
|
+
## Installazione
|
|
20
|
+
|
|
21
|
+
Non è necessario installare `scripting-cli` globalmente. Puoi utilizzarlo direttamente con `npx`:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx scripting-cli <command>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Utilizzo
|
|
28
|
+
|
|
29
|
+
### 1. Creare una directory di lavoro
|
|
30
|
+
|
|
31
|
+
Crea una directory nel tuo computer dove archiviare gli script dell'app Scripting. Ad esempio:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
mkdir my-scripting-project
|
|
35
|
+
cd my-scripting-project
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. Avviare il servizio locale
|
|
39
|
+
|
|
40
|
+
All'interno della directory di lavoro, esegui il comando seguente per avviare il servizio locale:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx scripting-cli start
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Per impostazione predefinita, il servizio verrà eseguito sulla porta `3000`. Se desideri utilizzare una porta diversa, puoi specificarla con l'opzione `--port`:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx scripting-cli start --port=4000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Per attivare il servizio Bonjour (che consente all'app Scripting di rilevare automaticamente il servizio locale), utilizza l'opzione `--bonjour`:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx scripting-cli start --bonjour
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Collegare l'app Scripting
|
|
59
|
+
|
|
60
|
+
Una volta che il servizio è in esecuzione, apri l'**app Scripting** e collegati al servizio locale appena avviato. Questo stabilirà la connessione tra l'app e la tua directory di lavoro.
|
|
61
|
+
|
|
62
|
+
### 4. Debug e sincronizzazione del codice
|
|
63
|
+
|
|
64
|
+
Dopo la connessione, seleziona il progetto di script che desideri eseguire il debug. L'app Scripting sincronizzerà automaticamente il codice del progetto con la tua directory locale.
|
|
65
|
+
|
|
66
|
+
### 5. Sincronizzazione del codice in tempo reale
|
|
67
|
+
|
|
68
|
+
Mentre scrivi e salvi gli script nel tuo editor desktop (ad esempio, VSCode), il codice aggiornato verrà automaticamente sincronizzato con l'app Scripting ed eseguito in tempo reale. Questo rende lo sviluppo e il debug molto più efficienti.
|
|
69
|
+
|
|
70
|
+
## Esempio di flusso di lavoro
|
|
71
|
+
|
|
72
|
+
1. Avvia il servizio locale:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npx scripting-cli start
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
2. Apri il tuo editor e scrivi lo script.
|
|
79
|
+
|
|
80
|
+
3. Salva il file dello script.
|
|
81
|
+
|
|
82
|
+
4. Il codice aggiornato viene sincronizzato automaticamente con l'app Scripting e viene eseguito.
|
|
83
|
+
|
|
84
|
+
## Informazioni aggiuntive
|
|
85
|
+
|
|
86
|
+
* La porta predefinita del servizio è `3000`. Se è già in uso, specificane un'altra con l'opzione `--port`.
|
|
87
|
+
* Utilizza l'opzione `--no-auto-open` per avviare il server di sviluppo senza aprire automaticamente `index.tsx` o `widget.tsx` nell'editor:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx scripting-cli start --no-auto-open
|
|
91
|
+
```
|
|
92
|
+
* Se desideri utilizzare il servizio Bonjour, assicurati che il tuo computer lo supporti. Su Windows, potrebbe essere necessario installarlo manualmente. Poi utilizza l'opzione `--bonjour` per abilitarlo.
|
|
93
|
+
* Questo strumento è pensato per gli utenti che preferiscono editor desktop come VSCode e desiderano un'integrazione fluida con l'app Scripting per la sincronizzazione e il debug del codice.
|
|
94
|
+
|
|
95
|
+
## Risoluzione dei problemi
|
|
96
|
+
|
|
97
|
+
Se riscontri problemi, verifica che:
|
|
98
|
+
|
|
99
|
+
* Hai installato Node.js versione 20 o superiore.
|
|
100
|
+
* L'app Scripting è correttamente collegata al servizio locale.
|
|
101
|
+
* Nessun altro processo stia utilizzando la porta desiderata.
|
|
102
|
+
* Utilizzi sempre `npx scripting-cli <command>` per avviare il servizio e che il pacchetto sia aggiornato.
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
Buon divertimento con `scripting-cli` nel tuo flusso di lavoro di sviluppo per l'app Scripting! Buona programmazione!
|
package/README_ja.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# Scripting アプリ コマンドラインツール
|
|
2
|
+
|
|
3
|
+
Scripting アプリとの統合用に設計された `scripting-cli` コマンドラインツールへようこそ。このツールを使用すると、お気に入りのデスクトップエディター(例:VSCode)でスクリプトを開発しながら、リアルタイムで同期およびプレビューできます。
|
|
4
|
+
|
|
5
|
+
[English](./README.md) | [中文](./README_zh.md) | [Deutsch](./README_de.md) | [Français](./README_fr.md) | [Italiano](./README_it.md)
|
|
6
|
+
|
|
7
|
+
## 前提条件
|
|
8
|
+
|
|
9
|
+
`scripting-cli` を使用する前に、以下の要件を満たしていることを確認してください:
|
|
10
|
+
|
|
11
|
+
1. **Node.js**:最新バージョンの Node.js がインストールされていることを確認してください。現在のバージョンを確認するには、次のコマンドを実行します:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
node -v
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
2. **Scripting アプリ**:`scripting-cli` が起動するローカルサービスに接続するために、Scripting アプリをインストールする必要があります。
|
|
18
|
+
|
|
19
|
+
## インストール
|
|
20
|
+
|
|
21
|
+
`scripting-cli` をグローバルにインストールする必要はありません。`npx` を使用して実行するだけです:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx scripting-cli <command>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 使用方法
|
|
28
|
+
|
|
29
|
+
### 1. 作業ディレクトリの作成
|
|
30
|
+
|
|
31
|
+
まず、Scripting アプリのスクリプトを保存するディレクトリを作成します。例:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
mkdir my-scripting-project
|
|
35
|
+
cd my-scripting-project
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### 2. ローカルサービスの起動
|
|
39
|
+
|
|
40
|
+
作業ディレクトリで、次のコマンドを実行してローカル開発サービスを起動します:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
npx scripting-cli start
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
デフォルトでは、サービスはポート `3000` で起動します。別のポートを指定するには、`--port` オプションを使用します:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
npx scripting-cli start --port=4000
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Bonjour サポートを有効にして、Scripting アプリがローカルサービスを自動的に検出できるようにするには、`--bonjour` フラグを追加します:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
npx scripting-cli start --bonjour
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 3. Scripting アプリの接続
|
|
59
|
+
|
|
60
|
+
サービスが起動したら、**Scripting アプリ** を開き、先ほど起動したローカルサービスに接続します。これにより、アプリと作業ディレクトリ間の接続が確立されます。
|
|
61
|
+
|
|
62
|
+
### 4. コードのデバッグと同期
|
|
63
|
+
|
|
64
|
+
接続後、デバッグしたいスクリプトプロジェクトを選択します。Scripting アプリは、プロジェクトのコードを自動的に作業ディレクトリと同期します。
|
|
65
|
+
|
|
66
|
+
### 5. リアルタイムコード同期
|
|
67
|
+
|
|
68
|
+
デスクトップエディター(例:VSCode)でスクリプトを作成して保存すると、変更内容が自動的に Scripting アプリと同期され、リアルタイムで実行されます。これにより、開発とデバッグがスムーズになります。
|
|
69
|
+
|
|
70
|
+
## 例:ワークフロー
|
|
71
|
+
|
|
72
|
+
1. ローカルサービスを起動します:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npx scripting-cli start
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
2. エディターを開いてスクリプトを作成します。
|
|
79
|
+
|
|
80
|
+
3. スクリプトファイルを保存します。
|
|
81
|
+
|
|
82
|
+
4. 更新されたコードが自動的に Scripting アプリと同期され、実行されます。
|
|
83
|
+
|
|
84
|
+
## 追加情報
|
|
85
|
+
|
|
86
|
+
* デフォルトのポートは `3000` です。既に使用されている場合は、`--port` オプションで別のポートを指定してください。
|
|
87
|
+
* `--no-auto-open` フラグを使用すると、`index.tsx` または `widget.tsx` ファイルが自動的に開かれるのを防げます:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx scripting-cli start --no-auto-open
|
|
91
|
+
```
|
|
92
|
+
* Bonjour サービスを使用するには、システムがその機能をサポートしていることを確認してください。Windows では、Bonjour を手動でインストールする必要がある場合があります。その後、`--bonjour` オプションを使用してサービスを有効にします。
|
|
93
|
+
* このツールは、VSCode などのデスクトップエディターを好み、Scripting アプリとのシームレスなコード同期とデバッグを望むユーザーに最適です。
|
|
94
|
+
|
|
95
|
+
## トラブルシューティング
|
|
96
|
+
|
|
97
|
+
問題が発生した場合は、以下を確認してください:
|
|
98
|
+
|
|
99
|
+
* Node.js バージョン 20 以上を使用していること。
|
|
100
|
+
* Scripting アプリがローカルサービスに正しく接続されていること。
|
|
101
|
+
* 選択したポートが他のプロセスによって使用されていないこと。
|
|
102
|
+
* 常に `npx scripting-cli <command>` を使用してツールを実行し、パッケージが最新であることを確認してください。
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
Scripting アプリの開発ワークフローで `scripting-cli` をご活用ください。楽しいコーディングを!
|
package/README_zh.md
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
# Scripting
|
|
1
|
+
# Scripting 应用命令行工具
|
|
2
2
|
|
|
3
|
-
欢迎使用 `scripting-cli`
|
|
3
|
+
欢迎使用 `scripting-cli` 命令行工具,它旨在与 Scripting 应用集成。该工具允许您在使用喜爱的桌面编辑器(如 VSCode)开发脚本时,实现实时同步和预览。
|
|
4
4
|
|
|
5
|
-
[English
|
|
5
|
+
[English](./README.md) | [日本語](./README_ja.md) | [Deutsch](./README_de.md) | [Français](./README_fr.md) | [Italiano](./README_it.md)
|
|
6
6
|
|
|
7
|
-
##
|
|
7
|
+
## 先决条件
|
|
8
8
|
|
|
9
|
-
在使用 `scripting-cli`
|
|
9
|
+
在使用 `scripting-cli` 之前,请确保满足以下要求:
|
|
10
|
+
|
|
11
|
+
1. **Node.js**:确保已安装最新版本的 Node.js。您可以通过运行以下命令检查当前版本:
|
|
10
12
|
|
|
11
|
-
1. **Node.js**:请确保您已安装v20+版本的 Node.js。可以通过以下命令检查您的 Node.js 版本:
|
|
12
13
|
```bash
|
|
13
14
|
node -v
|
|
14
15
|
```
|
|
15
16
|
|
|
16
|
-
2. **Scripting
|
|
17
|
+
2. **Scripting 应用**:必须安装 Scripting 应用,以便连接由 `scripting-cli` 启动的本地服务。
|
|
17
18
|
|
|
18
19
|
## 安装
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
无需全局安装 `scripting-cli`,只需使用 `npx` 运行即可:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx scripting-cli <command>
|
|
25
|
+
```
|
|
21
26
|
|
|
22
27
|
## 使用方法
|
|
23
28
|
|
|
24
29
|
### 1. 创建工作目录
|
|
25
30
|
|
|
26
|
-
|
|
31
|
+
首先创建一个目录,用于存放您的 Scripting 应用脚本。例如:
|
|
32
|
+
|
|
27
33
|
```bash
|
|
28
34
|
mkdir my-scripting-project
|
|
29
35
|
cd my-scripting-project
|
|
@@ -31,65 +37,70 @@ cd my-scripting-project
|
|
|
31
37
|
|
|
32
38
|
### 2. 启动本地服务
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
在工作目录中,运行以下命令启动本地开发服务:
|
|
35
41
|
|
|
36
42
|
```bash
|
|
37
43
|
npx scripting-cli start
|
|
38
44
|
```
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
默认情况下,服务将在端口 `3000` 上启动。如需指定其他端口,请使用 `--port` 选项:
|
|
41
47
|
|
|
42
48
|
```bash
|
|
43
|
-
npx scripting-cli start --port
|
|
49
|
+
npx scripting-cli start --port=4000
|
|
44
50
|
```
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
要启用 Bonjour 支持,使 Scripting 应用自动检测本地服务,请添加 `--bonjour` 标志:
|
|
53
|
+
|
|
47
54
|
```bash
|
|
48
|
-
npx scripting-cli start --
|
|
55
|
+
npx scripting-cli start --bonjour
|
|
49
56
|
```
|
|
50
57
|
|
|
51
58
|
### 3. 连接 Scripting 应用
|
|
52
59
|
|
|
53
|
-
|
|
60
|
+
服务运行后,打开 **Scripting 应用** 并连接您刚刚启动的本地服务。这将建立应用与工作目录之间的连接。
|
|
54
61
|
|
|
55
62
|
### 4. 调试和同步代码
|
|
56
63
|
|
|
57
|
-
|
|
64
|
+
连接后,选择要调试的脚本项目。Scripting 应用将自动将该项目的代码同步到您的工作目录。
|
|
58
65
|
|
|
59
|
-
### 5.
|
|
66
|
+
### 5. 实时代码同步
|
|
60
67
|
|
|
61
|
-
|
|
68
|
+
在桌面编辑器(如 VSCode)中编写并保存脚本时,更新的代码将自动同步到 Scripting 应用并实时执行,使开发和调试更加顺畅。
|
|
62
69
|
|
|
63
70
|
## 示例工作流程
|
|
64
71
|
|
|
65
72
|
1. 启动本地服务:
|
|
73
|
+
|
|
66
74
|
```bash
|
|
67
75
|
npx scripting-cli start
|
|
68
76
|
```
|
|
69
77
|
|
|
70
|
-
2.
|
|
78
|
+
2. 打开编辑器并编写脚本。
|
|
71
79
|
|
|
72
80
|
3. 保存脚本文件。
|
|
73
81
|
|
|
74
|
-
4.
|
|
82
|
+
4. 更新的代码将自动同步到 Scripting 应用并执行。
|
|
75
83
|
|
|
76
|
-
##
|
|
84
|
+
## 附加信息
|
|
77
85
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
* 默认端口为 `3000`。如果该端口已被占用,可使用 `--port` 选项指定其他端口。
|
|
87
|
+
* 使用 `--no-auto-open` 标志可防止工具自动打开 `index.tsx` 或 `widget.tsx` 文件:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
npx scripting-cli start --no-auto-open
|
|
91
|
+
```
|
|
92
|
+
* 要使用 Bonjour 服务,请确保系统支持该功能。在 Windows 上,可能需要手动安装 Bonjour。然后,使用 `--bonjour` 选项启用该服务。
|
|
93
|
+
* 该工具适用于喜欢使用 VSCode 等桌面编辑器,并希望与 Scripting 应用实现无缝代码同步和调试的用户。
|
|
84
94
|
|
|
85
95
|
## 故障排除
|
|
86
96
|
|
|
87
97
|
如果遇到问题,请确保:
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
* 使用的是 Node.js 版本 20 或更高。
|
|
100
|
+
* Scripting 应用已正确连接到本地服务。
|
|
101
|
+
* 所选端口未被其他进程占用。
|
|
102
|
+
* 始终使用 `npx scripting-cli <command>` 运行工具,并确保软件包是最新的。
|
|
92
103
|
|
|
93
104
|
---
|
|
94
105
|
|
|
95
|
-
|
|
106
|
+
祝您在 Scripting 应用的开发工作中使用 `scripting-cli` 顺利!编码愉快!
|
package/dist/controller.js
CHANGED
|
@@ -41,15 +41,15 @@ class Controller {
|
|
|
41
41
|
Controller.instances.delete(socket.id);
|
|
42
42
|
socket.removeAllListeners();
|
|
43
43
|
});
|
|
44
|
-
fs_1.default.promises.readdir(
|
|
45
|
-
const serverScriptNames = files.filter((filename) => fs_1.default.statSync(filename).isDirectory()
|
|
44
|
+
fs_1.default.promises.readdir((0, util_1.getScriptPath)()).then((files) => {
|
|
45
|
+
const serverScriptNames = files.filter((filename) => fs_1.default.statSync((0, util_1.getScriptPath)(filename)).isDirectory()
|
|
46
46
|
&& filename !== '.vscode'
|
|
47
47
|
&& filename !== 'dts');
|
|
48
48
|
socket.emit("serverScripts", serverScriptNames);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
createWatcher(scriptName) {
|
|
52
|
-
const scriptDir = (0, util_1.
|
|
52
|
+
const scriptDir = (0, util_1.getScriptPath)(scriptName);
|
|
53
53
|
this.watcher = chokidar_1.default.watch(scriptDir, {
|
|
54
54
|
ignored: /(^|[\/\\])\../,
|
|
55
55
|
persistent: true,
|
|
@@ -111,13 +111,7 @@ class Controller {
|
|
|
111
111
|
"scripting.d.ts": data["scripting.d.ts"],
|
|
112
112
|
});
|
|
113
113
|
this.scriptName = data.scriptName;
|
|
114
|
-
const
|
|
115
|
-
const scriptDir = (0, util_1.getPath)(data.scriptName);
|
|
116
|
-
const tsconfig = require((0, util_1.getPath)('tsconfig.json'));
|
|
117
|
-
if (!tsconfig.include.includes(scriptName)) {
|
|
118
|
-
tsconfig.include.push(scriptName);
|
|
119
|
-
await fs_1.default.promises.writeFile((0, util_1.getPath)('tsconfig.json'), JSON.stringify(tsconfig, null, 2));
|
|
120
|
-
}
|
|
114
|
+
const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
|
|
121
115
|
(0, util_1.ensureDirectoryExistence)(scriptDir);
|
|
122
116
|
await Promise.all(Object.entries(data.scriptFiles).map(async ([filename, content]) => {
|
|
123
117
|
const filePath = path_1.default.join(scriptDir, filename);
|
|
@@ -163,7 +157,7 @@ class Controller {
|
|
|
163
157
|
"global.d.ts": data["global.d.ts"],
|
|
164
158
|
"scripting.d.ts": data["scripting.d.ts"],
|
|
165
159
|
});
|
|
166
|
-
const scriptDir = (0, util_1.
|
|
160
|
+
const scriptDir = (0, util_1.getScriptPath)(data.scriptName);
|
|
167
161
|
if (!fs_1.default.existsSync(scriptDir)) {
|
|
168
162
|
ack({
|
|
169
163
|
error: `Script directory ${scriptDir} does not exist`,
|
|
@@ -224,7 +218,7 @@ class Controller {
|
|
|
224
218
|
if (data.scriptName !== this.scriptName) {
|
|
225
219
|
return;
|
|
226
220
|
}
|
|
227
|
-
const filePath = path_1.default.join((0, util_1.
|
|
221
|
+
const filePath = path_1.default.join((0, util_1.getScriptPath)(this.scriptName), data.relativePath);
|
|
228
222
|
if (!this.noAutoOpen && fs_1.default.existsSync(filePath)) {
|
|
229
223
|
(0, util_1.tryOpenFileInVSCode)(filePath);
|
|
230
224
|
}
|
|
@@ -248,7 +242,7 @@ class Controller {
|
|
|
248
242
|
});
|
|
249
243
|
return;
|
|
250
244
|
}
|
|
251
|
-
const filePath = path_1.default.join((0, util_1.
|
|
245
|
+
const filePath = path_1.default.join((0, util_1.getScriptPath)(data.scriptName), data.relativePath);
|
|
252
246
|
try {
|
|
253
247
|
const content = await fs_1.default.promises.readFile(filePath, 'utf-8');
|
|
254
248
|
ack({
|
package/dist/index.js
CHANGED
|
@@ -35,11 +35,25 @@ const start_server_1 = require("./start_server");
|
|
|
35
35
|
.example([
|
|
36
36
|
["$0 start --no-auto-open", "Start server without opening the index.tsx/widget.tsx file"],
|
|
37
37
|
["$0 start --no-auto-open -p=8000", "Start server without opening the index.tsx/widget.tsx file and listen on 8000"],
|
|
38
|
+
])
|
|
39
|
+
.options({
|
|
40
|
+
"bonjour": {
|
|
41
|
+
type: "boolean",
|
|
42
|
+
describe: "Enable bonjour service",
|
|
43
|
+
},
|
|
44
|
+
})
|
|
45
|
+
.usage("$0 start [--bonjour]")
|
|
46
|
+
.example([
|
|
47
|
+
["$0 start --bonjour", "Start server with bonjour service"],
|
|
48
|
+
["$0 start --bonjour -p=8000", "Start server with bonjour service and listen on 8000"],
|
|
49
|
+
["$0 start --bonjour --no-auto-open", "Start server with bonjour service without opening the index.tsx/widget.tsx file"],
|
|
50
|
+
["$0 start --bonjour --no-auto-open -p=8000", "Start server with bonjour service without opening the index.tsx/widget.tsx file and listen on 8000"],
|
|
38
51
|
]);
|
|
39
52
|
}, (argv) => {
|
|
40
53
|
(0, start_server_1.startServer)({
|
|
41
54
|
port: argv.port,
|
|
42
55
|
noAutoOpen: argv['no-auto-open'],
|
|
56
|
+
startBonjourService: argv.bonjour,
|
|
43
57
|
});
|
|
44
58
|
})
|
|
45
59
|
.showHelpOnFail(true)
|
package/dist/start_server.js
CHANGED
|
@@ -18,7 +18,7 @@ const app = (0, express_1.default)();
|
|
|
18
18
|
const server = http_1.default.createServer(app);
|
|
19
19
|
const io = new socket_io_1.Server(server);
|
|
20
20
|
const bonjour = (0, bonjour_1.default)();
|
|
21
|
-
function startServer({ port, noAutoOpen }) {
|
|
21
|
+
function startServer({ port, noAutoOpen, startBonjourService }) {
|
|
22
22
|
// console.log("port", port, "noAutoOpen", noAutoOpen);
|
|
23
23
|
const PORT = port ?? 3000;
|
|
24
24
|
(0, http_router_1.initHttpRouter)(app);
|
|
@@ -26,41 +26,51 @@ function startServer({ port, noAutoOpen }) {
|
|
|
26
26
|
controller_1.Controller.create(socket, noAutoOpen);
|
|
27
27
|
console.log(chalk_1.default.blue(`Client [${socket.id}] connected`));
|
|
28
28
|
});
|
|
29
|
-
server.listen(PORT, () => {
|
|
29
|
+
server.listen(PORT, async () => {
|
|
30
30
|
(0, util_1.createTsConfig)(); // Create tsconfig.json when the server starts
|
|
31
31
|
(0, util_1.createVSCodeSettings)(); // Create vscode settings.json when the server starts
|
|
32
|
+
(0, util_1.ensureScriptsDirectory)(); // Ensure the scripts directory exists
|
|
33
|
+
await (0, util_1.migrateOldFiles)(); // Migrate old files to the scripts directory
|
|
32
34
|
const ipAddress = ip_1.default.address();
|
|
33
35
|
const address = `http://${ipAddress}:${PORT}`;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
if (startBonjourService) {
|
|
37
|
+
console.log(`Server listening on ${chalk_1.default.bold.blue(address)}\n\n${chalk_1.default.yellow('You can select this server in the Scripting app to connect')}.\n`);
|
|
38
|
+
console.log(`Alternatively, you can ${chalk_1.default.green.bold("use the Scripting app to scan")} the QR code and connect: `);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.log(chalk_1.default.yellow.italic(`The bonjour service is not started, you can use \`--bonjour\` option to start it.`));
|
|
42
|
+
console.log(`Server listening on ${chalk_1.default.bold.blue(address)}\nYou can ${chalk_1.default.green.bold("use the Scripting app to scan")} the QR code and connect: `);
|
|
43
|
+
}
|
|
36
44
|
qrcode_terminal_1.default.generate(address, { small: true });
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
process.on('uncaughtException', err => {
|
|
50
|
-
console.error('Uncaught exception:', err);
|
|
51
|
-
gracefulShutdown();
|
|
52
|
-
});
|
|
53
|
-
function gracefulShutdown() {
|
|
54
|
-
console.log('Shutting down Bonjour…');
|
|
55
|
-
service.stop(() => {
|
|
56
|
-
bonjour.unpublishAll(() => {
|
|
57
|
-
// wait for 500ms,let goodbye message be sent completely
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
bonjour.destroy();
|
|
60
|
-
console.log('Bonjour services have been shut down properly.');
|
|
61
|
-
process.exit(0);
|
|
62
|
-
}, 500);
|
|
45
|
+
if (startBonjourService) {
|
|
46
|
+
function gracefulShutdown() {
|
|
47
|
+
console.log('Shutting down Bonjour…');
|
|
48
|
+
service.stop(() => {
|
|
49
|
+
bonjour.unpublishAll(() => {
|
|
50
|
+
// wait for 500ms,let goodbye message be sent completely
|
|
51
|
+
setTimeout(() => {
|
|
52
|
+
bonjour.destroy();
|
|
53
|
+
console.log('Bonjour services have been shut down properly.');
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}, 500);
|
|
56
|
+
});
|
|
63
57
|
});
|
|
58
|
+
}
|
|
59
|
+
const service = bonjour.publish({
|
|
60
|
+
name: 'Scripting-service',
|
|
61
|
+
type: 'http',
|
|
62
|
+
port: PORT,
|
|
63
|
+
host: 'scripting-service.local',
|
|
64
|
+
});
|
|
65
|
+
// Register bonjour service error handler
|
|
66
|
+
service.on('error', err => {
|
|
67
|
+
console.error('Bonjour service error:', err);
|
|
68
|
+
});
|
|
69
|
+
['SIGINT', 'SIGTERM'].forEach(sig => process.once(sig, gracefulShutdown));
|
|
70
|
+
// Handle uncaught exceptions
|
|
71
|
+
process.on('uncaughtException', err => {
|
|
72
|
+
console.error('Uncaught exception:', err);
|
|
73
|
+
gracefulShutdown();
|
|
64
74
|
});
|
|
65
75
|
}
|
|
66
76
|
});
|
package/dist/util.js
CHANGED
|
@@ -5,12 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.md5 = md5;
|
|
7
7
|
exports.getPath = getPath;
|
|
8
|
+
exports.getScriptPath = getScriptPath;
|
|
8
9
|
exports.tryOpenFileInVSCode = tryOpenFileInVSCode;
|
|
9
10
|
exports.createTsConfig = createTsConfig;
|
|
10
11
|
exports.createVSCodeSettings = createVSCodeSettings;
|
|
12
|
+
exports.ensureScriptsDirectory = ensureScriptsDirectory;
|
|
11
13
|
exports.ensureDirectoryExistence = ensureDirectoryExistence;
|
|
12
14
|
exports.writeDtsFiles = writeDtsFiles;
|
|
13
15
|
exports.getRelativePath = getRelativePath;
|
|
16
|
+
exports.migrateOldFiles = migrateOldFiles;
|
|
14
17
|
const path_1 = __importDefault(require("path"));
|
|
15
18
|
const crypto_1 = __importDefault(require("crypto"));
|
|
16
19
|
const os_1 = __importDefault(require("os"));
|
|
@@ -26,6 +29,12 @@ function md5(content) {
|
|
|
26
29
|
function getPath(filename) {
|
|
27
30
|
return path_1.default.join(process.cwd(), filename);
|
|
28
31
|
}
|
|
32
|
+
function getScriptPath(filename) {
|
|
33
|
+
if (filename != null) {
|
|
34
|
+
return path_1.default.join(process.cwd(), 'scripts', filename);
|
|
35
|
+
}
|
|
36
|
+
return path_1.default.join(process.cwd(), 'scripts');
|
|
37
|
+
}
|
|
29
38
|
function tryOpenFileInVSCode(filePath) {
|
|
30
39
|
let cmd = `code "${filePath}"`;
|
|
31
40
|
if (os_1.default.platform() === "win32") {
|
|
@@ -67,7 +76,8 @@ function createTsConfig() {
|
|
|
67
76
|
}
|
|
68
77
|
},
|
|
69
78
|
"include": [
|
|
70
|
-
"./dts/global.d.ts"
|
|
79
|
+
"./dts/global.d.ts",
|
|
80
|
+
"scripts"
|
|
71
81
|
]
|
|
72
82
|
}`;
|
|
73
83
|
const filePath = getPath('tsconfig.json');
|
|
@@ -77,7 +87,18 @@ function createTsConfig() {
|
|
|
77
87
|
console.log(chalk_1.default.green('tsconfig.json created.'));
|
|
78
88
|
}
|
|
79
89
|
else {
|
|
80
|
-
|
|
90
|
+
const tsconfig = JSON.parse(fs_1.default.readFileSync(filePath, 'utf-8'));
|
|
91
|
+
if (tsconfig.include && !tsconfig.include.includes('scripts')) {
|
|
92
|
+
tsconfig.include = [
|
|
93
|
+
"./dts/global.d.ts",
|
|
94
|
+
"scripts"
|
|
95
|
+
];
|
|
96
|
+
fs_1.default.writeFileSync(filePath, JSON.stringify(tsconfig, null, 2));
|
|
97
|
+
console.log(chalk_1.default.yellow('tsconfig.json updated to include scripts directory.'));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
console.log(chalk_1.default.gray('tsconfig.json already exists.'));
|
|
101
|
+
}
|
|
81
102
|
}
|
|
82
103
|
}
|
|
83
104
|
function createVSCodeSettings() {
|
|
@@ -95,6 +116,16 @@ function createVSCodeSettings() {
|
|
|
95
116
|
console.log(chalk_1.default.gray('.vscode/settings.json already exists.'));
|
|
96
117
|
}
|
|
97
118
|
}
|
|
119
|
+
function ensureScriptsDirectory() {
|
|
120
|
+
const scriptsDir = getScriptPath();
|
|
121
|
+
if (!fs_1.default.existsSync(scriptsDir)) {
|
|
122
|
+
fs_1.default.mkdirSync(scriptsDir, { recursive: true });
|
|
123
|
+
console.log(chalk_1.default.green('Scripts directory created.'));
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
console.log(chalk_1.default.gray('Scripts directory already exists.'));
|
|
127
|
+
}
|
|
128
|
+
}
|
|
98
129
|
function ensureDirectoryExistence(filePath) {
|
|
99
130
|
const dirname = path_1.default.dirname(filePath);
|
|
100
131
|
if (!fs_1.default.existsSync(dirname)) {
|
|
@@ -117,3 +148,28 @@ function getRelativePath(from, to) {
|
|
|
117
148
|
const relativePath = path_1.default.relative(from, to);
|
|
118
149
|
return relativePath.replaceAll("\\", "/");
|
|
119
150
|
}
|
|
151
|
+
async function migrateOldFiles() {
|
|
152
|
+
try {
|
|
153
|
+
const list = await fs_1.default.promises.readdir(process.cwd());
|
|
154
|
+
for (const file of list) {
|
|
155
|
+
if (file === 'dts' || file === '.vscode' || file == "scripts" || file === 'tsconfig.json' || file === 'package.json' || file === 'node_modules') {
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
const filePath = path_1.default.join(process.cwd(), file);
|
|
159
|
+
const stat = await fs_1.default.promises.stat(filePath);
|
|
160
|
+
if (!stat.isDirectory()) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const newFilePath = path_1.default.join(process.cwd(), 'scripts', file);
|
|
164
|
+
if (fs_1.default.existsSync(newFilePath)) {
|
|
165
|
+
console.log(chalk_1.default.yellow(`File ${newFilePath} already exists, skipping...`));
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
console.log(chalk_1.default.blue(`Moving ${filePath} to ${newFilePath}`));
|
|
169
|
+
await fs_1.default.promises.rename(filePath, newFilePath);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
console.log(`Failed to migrate old files: ${chalk_1.default.red(`${err}`)}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scripting-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "This plugin integrates the desktop editor synchronization feature of the Scripting app.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"scripting-cli": "dist/index.js"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsc",
|
|
10
|
+
"build": "npx tsc",
|
|
11
11
|
"start": "node dist/index.js",
|
|
12
12
|
"dev": "ts-node src/index.ts",
|
|
13
13
|
"help": "node dist/index.js --help",
|
package/src/controller.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import chokidar, { FSWatcher } from 'chokidar';
|
|
3
3
|
import { Socket } from 'socket.io';
|
|
4
|
-
import { ensureDirectoryExistence, getPath, getRelativePath, md5, tryOpenFileInVSCode, writeDtsFiles } from './util';
|
|
4
|
+
import { ensureDirectoryExistence, getPath, getRelativePath, getScriptPath, md5, tryOpenFileInVSCode, writeDtsFiles } from './util';
|
|
5
5
|
import fs from 'fs';
|
|
6
6
|
import chalk from 'chalk';
|
|
7
7
|
import path from 'path';
|
|
@@ -52,9 +52,9 @@ export class Controller {
|
|
|
52
52
|
socket.removeAllListeners();
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
fs.promises.readdir(
|
|
55
|
+
fs.promises.readdir(getScriptPath()).then((files) => {
|
|
56
56
|
const serverScriptNames = files.filter((filename) =>
|
|
57
|
-
fs.statSync(filename).isDirectory()
|
|
57
|
+
fs.statSync(getScriptPath(filename)).isDirectory()
|
|
58
58
|
&& filename !== '.vscode'
|
|
59
59
|
&& filename !== 'dts'
|
|
60
60
|
)
|
|
@@ -63,7 +63,7 @@ export class Controller {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
createWatcher(scriptName: string) {
|
|
66
|
-
const scriptDir =
|
|
66
|
+
const scriptDir = getScriptPath(scriptName)
|
|
67
67
|
this.watcher = chokidar.watch(scriptDir, {
|
|
68
68
|
ignored: /(^|[\/\\])\../,
|
|
69
69
|
persistent: true,
|
|
@@ -142,16 +142,7 @@ export class Controller {
|
|
|
142
142
|
|
|
143
143
|
this.scriptName = data.scriptName;
|
|
144
144
|
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
const scriptDir = getPath(data.scriptName);
|
|
148
|
-
|
|
149
|
-
const tsconfig = require(getPath('tsconfig.json'));
|
|
150
|
-
|
|
151
|
-
if (!tsconfig.include.includes(scriptName)) {
|
|
152
|
-
tsconfig.include.push(scriptName);
|
|
153
|
-
await fs.promises.writeFile(getPath('tsconfig.json'), JSON.stringify(tsconfig, null, 2))
|
|
154
|
-
}
|
|
145
|
+
const scriptDir = getScriptPath(data.scriptName);
|
|
155
146
|
|
|
156
147
|
ensureDirectoryExistence(scriptDir);
|
|
157
148
|
|
|
@@ -220,7 +211,7 @@ export class Controller {
|
|
|
220
211
|
"scripting.d.ts": data["scripting.d.ts"],
|
|
221
212
|
});
|
|
222
213
|
|
|
223
|
-
const scriptDir =
|
|
214
|
+
const scriptDir = getScriptPath(data.scriptName);
|
|
224
215
|
|
|
225
216
|
if (!fs.existsSync(scriptDir)) {
|
|
226
217
|
ack({
|
|
@@ -303,7 +294,7 @@ export class Controller {
|
|
|
303
294
|
return;
|
|
304
295
|
}
|
|
305
296
|
|
|
306
|
-
const filePath = path.join(
|
|
297
|
+
const filePath = path.join(getScriptPath(this.scriptName), data.relativePath)
|
|
307
298
|
|
|
308
299
|
if (!this.noAutoOpen && fs.existsSync(filePath)) {
|
|
309
300
|
tryOpenFileInVSCode(filePath)
|
|
@@ -337,7 +328,7 @@ export class Controller {
|
|
|
337
328
|
return;
|
|
338
329
|
}
|
|
339
330
|
|
|
340
|
-
const filePath = path.join(
|
|
331
|
+
const filePath = path.join(getScriptPath(data.scriptName), data.relativePath);
|
|
341
332
|
try {
|
|
342
333
|
const content = await fs.promises.readFile(filePath, 'utf-8');
|
|
343
334
|
ack({
|
package/src/index.ts
CHANGED
|
@@ -32,11 +32,26 @@ yargs(hideBin(process.argv))
|
|
|
32
32
|
.example([
|
|
33
33
|
["$0 start --no-auto-open", "Start server without opening the index.tsx/widget.tsx file"],
|
|
34
34
|
["$0 start --no-auto-open -p=8000", "Start server without opening the index.tsx/widget.tsx file and listen on 8000"],
|
|
35
|
-
])
|
|
35
|
+
])
|
|
36
|
+
.options({
|
|
37
|
+
"bonjour": {
|
|
38
|
+
type: "boolean",
|
|
39
|
+
describe: "Enable bonjour service",
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
.usage("$0 start [--bonjour]")
|
|
43
|
+
.example([
|
|
44
|
+
["$0 start --bonjour", "Start server with bonjour service"],
|
|
45
|
+
["$0 start --bonjour -p=8000", "Start server with bonjour service and listen on 8000"],
|
|
46
|
+
["$0 start --bonjour --no-auto-open", "Start server with bonjour service without opening the index.tsx/widget.tsx file"],
|
|
47
|
+
["$0 start --bonjour --no-auto-open -p=8000", "Start server with bonjour service without opening the index.tsx/widget.tsx file and listen on 8000"],
|
|
48
|
+
])
|
|
49
|
+
;
|
|
36
50
|
}, (argv) => {
|
|
37
51
|
startServer({
|
|
38
52
|
port: argv.port,
|
|
39
|
-
noAutoOpen: argv['no-auto-open']
|
|
53
|
+
noAutoOpen: argv['no-auto-open'],
|
|
54
|
+
startBonjourService: argv.bonjour,
|
|
40
55
|
});
|
|
41
56
|
})
|
|
42
57
|
.showHelpOnFail(true)
|
package/src/start_server.ts
CHANGED
|
@@ -6,7 +6,7 @@ import ip from 'ip';
|
|
|
6
6
|
import Bonjour from 'bonjour';
|
|
7
7
|
import chalk from 'chalk';
|
|
8
8
|
import qrcode from 'qrcode-terminal';
|
|
9
|
-
import { createTsConfig, createVSCodeSettings, } from './util';
|
|
9
|
+
import { createTsConfig, createVSCodeSettings, ensureScriptsDirectory, migrateOldFiles, } from './util';
|
|
10
10
|
import { Controller } from './controller';
|
|
11
11
|
import { initHttpRouter } from './http_router';
|
|
12
12
|
|
|
@@ -15,9 +15,10 @@ const server = http.createServer(app);
|
|
|
15
15
|
const io = new SocketIOServer(server);
|
|
16
16
|
const bonjour = Bonjour();
|
|
17
17
|
|
|
18
|
-
export function startServer({ port, noAutoOpen }: {
|
|
18
|
+
export function startServer({ port, noAutoOpen, startBonjourService }: {
|
|
19
19
|
port: number | undefined
|
|
20
20
|
noAutoOpen: boolean | undefined
|
|
21
|
+
startBonjourService: boolean | undefined
|
|
21
22
|
}) {
|
|
22
23
|
|
|
23
24
|
// console.log("port", port, "noAutoOpen", noAutoOpen);
|
|
@@ -31,51 +32,62 @@ export function startServer({ port, noAutoOpen }: {
|
|
|
31
32
|
console.log(chalk.blue(`Client [${socket.id}] connected`));
|
|
32
33
|
});
|
|
33
34
|
|
|
34
|
-
server.listen(PORT, () => {
|
|
35
|
+
server.listen(PORT, async () => {
|
|
35
36
|
createTsConfig(); // Create tsconfig.json when the server starts
|
|
36
37
|
createVSCodeSettings(); // Create vscode settings.json when the server starts
|
|
38
|
+
ensureScriptsDirectory(); // Ensure the scripts directory exists
|
|
39
|
+
await migrateOldFiles(); // Migrate old files to the scripts directory
|
|
37
40
|
|
|
38
41
|
const ipAddress = ip.address()
|
|
39
42
|
const address = `http://${ipAddress}:${PORT}`;
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
if (startBonjourService) {
|
|
45
|
+
console.log(`Server listening on ${chalk.bold.blue(address)}\n\n${chalk.yellow('You can select this server in the Scripting app to connect')}.\n`);
|
|
46
|
+
|
|
47
|
+
console.log(`Alternatively, you can ${chalk.green.bold("use the Scripting app to scan")} the QR code and connect: `);
|
|
48
|
+
} else {
|
|
49
|
+
console.log(chalk.yellow.italic(`The bonjour service is not started, you can use \`--bonjour\` option to start it.`));
|
|
50
|
+
console.log(`Server listening on ${chalk.bold.blue(address)}\nYou can ${chalk.green.bold("use the Scripting app to scan")} the QR code and connect: `);
|
|
51
|
+
}
|
|
42
52
|
|
|
43
|
-
console.log(`Alternatively, you can ${chalk.green.bold("use the Scripting app to scan")} the QR code and connect: `);
|
|
44
53
|
qrcode.generate(address, { small: true });
|
|
45
54
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
process.once(sig, gracefulShutdown)
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// Handle uncaught exceptions
|
|
63
|
-
process.on('uncaughtException', err => {
|
|
64
|
-
console.error('Uncaught exception:', err);
|
|
65
|
-
gracefulShutdown();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
function gracefulShutdown() {
|
|
69
|
-
console.log('Shutting down Bonjour…');
|
|
70
|
-
service.stop(() => {
|
|
71
|
-
bonjour.unpublishAll(() => {
|
|
72
|
-
// wait for 500ms,let goodbye message be sent completely
|
|
73
|
-
setTimeout(() => {
|
|
74
|
-
bonjour.destroy();
|
|
75
|
-
console.log('Bonjour services have been shut down properly.');
|
|
76
|
-
process.exit(0);
|
|
77
|
-
}, 500);
|
|
55
|
+
if (startBonjourService) {
|
|
56
|
+
|
|
57
|
+
function gracefulShutdown() {
|
|
58
|
+
console.log('Shutting down Bonjour…');
|
|
59
|
+
service.stop(() => {
|
|
60
|
+
bonjour.unpublishAll(() => {
|
|
61
|
+
// wait for 500ms,let goodbye message be sent completely
|
|
62
|
+
setTimeout(() => {
|
|
63
|
+
bonjour.destroy();
|
|
64
|
+
console.log('Bonjour services have been shut down properly.');
|
|
65
|
+
process.exit(0);
|
|
66
|
+
}, 500);
|
|
67
|
+
});
|
|
78
68
|
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const service = bonjour.publish({
|
|
72
|
+
name: 'Scripting-service',
|
|
73
|
+
type: 'http',
|
|
74
|
+
port: PORT,
|
|
75
|
+
host: 'scripting-service.local',
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Register bonjour service error handler
|
|
79
|
+
service.on('error', err => {
|
|
80
|
+
console.error('Bonjour service error:', err);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
['SIGINT', 'SIGTERM'].forEach(sig =>
|
|
84
|
+
process.once(sig, gracefulShutdown)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Handle uncaught exceptions
|
|
88
|
+
process.on('uncaughtException', err => {
|
|
89
|
+
console.error('Uncaught exception:', err);
|
|
90
|
+
gracefulShutdown();
|
|
79
91
|
});
|
|
80
92
|
}
|
|
81
93
|
|
package/src/util.ts
CHANGED
|
@@ -16,6 +16,13 @@ export function getPath(filename: string) {
|
|
|
16
16
|
return path.join(process.cwd(), filename);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
+
export function getScriptPath(filename?: string) {
|
|
20
|
+
if (filename != null) {
|
|
21
|
+
return path.join(process.cwd(), 'scripts', filename);
|
|
22
|
+
}
|
|
23
|
+
return path.join(process.cwd(), 'scripts');
|
|
24
|
+
}
|
|
25
|
+
|
|
19
26
|
export function tryOpenFileInVSCode(filePath: string) {
|
|
20
27
|
let cmd = `code "${filePath}"`;
|
|
21
28
|
if (os.platform() === "win32") {
|
|
@@ -57,7 +64,8 @@ export function createTsConfig() {
|
|
|
57
64
|
}
|
|
58
65
|
},
|
|
59
66
|
"include": [
|
|
60
|
-
"./dts/global.d.ts"
|
|
67
|
+
"./dts/global.d.ts",
|
|
68
|
+
"scripts"
|
|
61
69
|
]
|
|
62
70
|
}`;
|
|
63
71
|
|
|
@@ -68,7 +76,17 @@ export function createTsConfig() {
|
|
|
68
76
|
fs.writeFileSync(filePath, tsconfigContent);
|
|
69
77
|
console.log(chalk.green('tsconfig.json created.'));
|
|
70
78
|
} else {
|
|
71
|
-
|
|
79
|
+
const tsconfig = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
80
|
+
if (tsconfig.include && !tsconfig.include.includes('scripts')) {
|
|
81
|
+
tsconfig.include = [
|
|
82
|
+
"./dts/global.d.ts",
|
|
83
|
+
"scripts"
|
|
84
|
+
];
|
|
85
|
+
fs.writeFileSync(filePath, JSON.stringify(tsconfig, null, 2));
|
|
86
|
+
console.log(chalk.yellow('tsconfig.json updated to include scripts directory.'));
|
|
87
|
+
} else {
|
|
88
|
+
console.log(chalk.gray('tsconfig.json already exists.'));
|
|
89
|
+
}
|
|
72
90
|
}
|
|
73
91
|
}
|
|
74
92
|
|
|
@@ -89,6 +107,16 @@ export function createVSCodeSettings() {
|
|
|
89
107
|
|
|
90
108
|
}
|
|
91
109
|
|
|
110
|
+
export function ensureScriptsDirectory() {
|
|
111
|
+
const scriptsDir = getScriptPath();
|
|
112
|
+
if (!fs.existsSync(scriptsDir)) {
|
|
113
|
+
fs.mkdirSync(scriptsDir, { recursive: true });
|
|
114
|
+
console.log(chalk.green('Scripts directory created.'));
|
|
115
|
+
} else {
|
|
116
|
+
console.log(chalk.gray('Scripts directory already exists.'));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
92
120
|
export function ensureDirectoryExistence(filePath: string) {
|
|
93
121
|
const dirname = path.dirname(filePath);
|
|
94
122
|
if (!fs.existsSync(dirname)) {
|
|
@@ -116,3 +144,39 @@ export function getRelativePath(from: string, to: string) {
|
|
|
116
144
|
const relativePath = path.relative(from, to);
|
|
117
145
|
return relativePath.replaceAll("\\", "/");
|
|
118
146
|
}
|
|
147
|
+
|
|
148
|
+
export async function migrateOldFiles() {
|
|
149
|
+
try {
|
|
150
|
+
const list = await fs.promises.readdir(process.cwd());
|
|
151
|
+
|
|
152
|
+
for (const file of list) {
|
|
153
|
+
|
|
154
|
+
if (file === 'dts' || file === '.vscode' || file == "scripts" || file === 'tsconfig.json' || file === 'package.json' || file === 'node_modules') {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const filePath = path.join(process.cwd(), file);
|
|
159
|
+
|
|
160
|
+
const stat = await fs.promises.stat(filePath);
|
|
161
|
+
|
|
162
|
+
if (!stat.isDirectory()) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const newFilePath = path.join(process.cwd(), 'scripts', file);
|
|
167
|
+
|
|
168
|
+
if (fs.existsSync(newFilePath)) {
|
|
169
|
+
console.log(chalk.yellow(`File ${newFilePath} already exists, skipping...`));
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
console.log(chalk.blue(`Moving ${filePath} to ${newFilePath}`));
|
|
174
|
+
await fs.promises.rename(filePath, newFilePath);
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
} catch (err) {
|
|
179
|
+
console.log(`Failed to migrate old files: ${chalk.red(`${err}`)}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
}
|