dxfl 0.1.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/LICENSE +287 -0
- package/README.md +45 -0
- package/auth.ts +81 -0
- package/bootstrap.js +3 -0
- package/deploy.ts +152 -0
- package/index.ts +26 -0
- package/package.json +26 -0
- package/tsconfig.json +111 -0
- package/vhosts.ts +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
EUROPEAN UNION PUBLIC LICENCE v. 1.2
|
|
2
|
+
EUPL © the European Union 2007, 2016
|
|
3
|
+
|
|
4
|
+
This European Union Public Licence (the ‘EUPL’) applies to the Work (as defined
|
|
5
|
+
below) which is provided under the terms of this Licence. Any use of the Work,
|
|
6
|
+
other than as authorised under this Licence is prohibited (to the extent such
|
|
7
|
+
use is covered by a right of the copyright holder of the Work).
|
|
8
|
+
|
|
9
|
+
The Work is provided under the terms of this Licence when the Licensor (as
|
|
10
|
+
defined below) has placed the following notice immediately following the
|
|
11
|
+
copyright notice for the Work:
|
|
12
|
+
|
|
13
|
+
Licensed under the EUPL
|
|
14
|
+
|
|
15
|
+
or has expressed by any other means his willingness to license under the EUPL.
|
|
16
|
+
|
|
17
|
+
1. Definitions
|
|
18
|
+
|
|
19
|
+
In this Licence, the following terms have the following meaning:
|
|
20
|
+
|
|
21
|
+
- ‘The Licence’: this Licence.
|
|
22
|
+
|
|
23
|
+
- ‘The Original Work’: the work or software distributed or communicated by the
|
|
24
|
+
Licensor under this Licence, available as Source Code and also as Executable
|
|
25
|
+
Code as the case may be.
|
|
26
|
+
|
|
27
|
+
- ‘Derivative Works’: the works or software that could be created by the
|
|
28
|
+
Licensee, based upon the Original Work or modifications thereof. This Licence
|
|
29
|
+
does not define the extent of modification or dependence on the Original Work
|
|
30
|
+
required in order to classify a work as a Derivative Work; this extent is
|
|
31
|
+
determined by copyright law applicable in the country mentioned in Article 15.
|
|
32
|
+
|
|
33
|
+
- ‘The Work’: the Original Work or its Derivative Works.
|
|
34
|
+
|
|
35
|
+
- ‘The Source Code’: the human-readable form of the Work which is the most
|
|
36
|
+
convenient for people to study and modify.
|
|
37
|
+
|
|
38
|
+
- ‘The Executable Code’: any code which has generally been compiled and which is
|
|
39
|
+
meant to be interpreted by a computer as a program.
|
|
40
|
+
|
|
41
|
+
- ‘The Licensor’: the natural or legal person that distributes or communicates
|
|
42
|
+
the Work under the Licence.
|
|
43
|
+
|
|
44
|
+
- ‘Contributor(s)’: any natural or legal person who modifies the Work under the
|
|
45
|
+
Licence, or otherwise contributes to the creation of a Derivative Work.
|
|
46
|
+
|
|
47
|
+
- ‘The Licensee’ or ‘You’: any natural or legal person who makes any usage of
|
|
48
|
+
the Work under the terms of the Licence.
|
|
49
|
+
|
|
50
|
+
- ‘Distribution’ or ‘Communication’: any act of selling, giving, lending,
|
|
51
|
+
renting, distributing, communicating, transmitting, or otherwise making
|
|
52
|
+
available, online or offline, copies of the Work or providing access to its
|
|
53
|
+
essential functionalities at the disposal of any other natural or legal
|
|
54
|
+
person.
|
|
55
|
+
|
|
56
|
+
2. Scope of the rights granted by the Licence
|
|
57
|
+
|
|
58
|
+
The Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
|
|
59
|
+
sublicensable licence to do the following, for the duration of copyright vested
|
|
60
|
+
in the Original Work:
|
|
61
|
+
|
|
62
|
+
- use the Work in any circumstance and for all usage,
|
|
63
|
+
- reproduce the Work,
|
|
64
|
+
- modify the Work, and make Derivative Works based upon the Work,
|
|
65
|
+
- communicate to the public, including the right to make available or display
|
|
66
|
+
the Work or copies thereof to the public and perform publicly, as the case may
|
|
67
|
+
be, the Work,
|
|
68
|
+
- distribute the Work or copies thereof,
|
|
69
|
+
- lend and rent the Work or copies thereof,
|
|
70
|
+
- sublicense rights in the Work or copies thereof.
|
|
71
|
+
|
|
72
|
+
Those rights can be exercised on any media, supports and formats, whether now
|
|
73
|
+
known or later invented, as far as the applicable law permits so.
|
|
74
|
+
|
|
75
|
+
In the countries where moral rights apply, the Licensor waives his right to
|
|
76
|
+
exercise his moral right to the extent allowed by law in order to make effective
|
|
77
|
+
the licence of the economic rights here above listed.
|
|
78
|
+
|
|
79
|
+
The Licensor grants to the Licensee royalty-free, non-exclusive usage rights to
|
|
80
|
+
any patents held by the Licensor, to the extent necessary to make use of the
|
|
81
|
+
rights granted on the Work under this Licence.
|
|
82
|
+
|
|
83
|
+
3. Communication of the Source Code
|
|
84
|
+
|
|
85
|
+
The Licensor may provide the Work either in its Source Code form, or as
|
|
86
|
+
Executable Code. If the Work is provided as Executable Code, the Licensor
|
|
87
|
+
provides in addition a machine-readable copy of the Source Code of the Work
|
|
88
|
+
along with each copy of the Work that the Licensor distributes or indicates, in
|
|
89
|
+
a notice following the copyright notice attached to the Work, a repository where
|
|
90
|
+
the Source Code is easily and freely accessible for as long as the Licensor
|
|
91
|
+
continues to distribute or communicate the Work.
|
|
92
|
+
|
|
93
|
+
4. Limitations on copyright
|
|
94
|
+
|
|
95
|
+
Nothing in this Licence is intended to deprive the Licensee of the benefits from
|
|
96
|
+
any exception or limitation to the exclusive rights of the rights owners in the
|
|
97
|
+
Work, of the exhaustion of those rights or of other applicable limitations
|
|
98
|
+
thereto.
|
|
99
|
+
|
|
100
|
+
5. Obligations of the Licensee
|
|
101
|
+
|
|
102
|
+
The grant of the rights mentioned above is subject to some restrictions and
|
|
103
|
+
obligations imposed on the Licensee. Those obligations are the following:
|
|
104
|
+
|
|
105
|
+
Attribution right: The Licensee shall keep intact all copyright, patent or
|
|
106
|
+
trademarks notices and all notices that refer to the Licence and to the
|
|
107
|
+
disclaimer of warranties. The Licensee must include a copy of such notices and a
|
|
108
|
+
copy of the Licence with every copy of the Work he/she distributes or
|
|
109
|
+
communicates. The Licensee must cause any Derivative Work to carry prominent
|
|
110
|
+
notices stating that the Work has been modified and the date of modification.
|
|
111
|
+
|
|
112
|
+
Copyleft clause: If the Licensee distributes or communicates copies of the
|
|
113
|
+
Original Works or Derivative Works, this Distribution or Communication will be
|
|
114
|
+
done under the terms of this Licence or of a later version of this Licence
|
|
115
|
+
unless the Original Work is expressly distributed only under this version of the
|
|
116
|
+
Licence — for example by communicating ‘EUPL v. 1.2 only’. The Licensee
|
|
117
|
+
(becoming Licensor) cannot offer or impose any additional terms or conditions on
|
|
118
|
+
the Work or Derivative Work that alter or restrict the terms of the Licence.
|
|
119
|
+
|
|
120
|
+
Compatibility clause: If the Licensee Distributes or Communicates Derivative
|
|
121
|
+
Works or copies thereof based upon both the Work and another work licensed under
|
|
122
|
+
a Compatible Licence, this Distribution or Communication can be done under the
|
|
123
|
+
terms of this Compatible Licence. For the sake of this clause, ‘Compatible
|
|
124
|
+
Licence’ refers to the licences listed in the appendix attached to this Licence.
|
|
125
|
+
Should the Licensee's obligations under the Compatible Licence conflict with
|
|
126
|
+
his/her obligations under this Licence, the obligations of the Compatible
|
|
127
|
+
Licence shall prevail.
|
|
128
|
+
|
|
129
|
+
Provision of Source Code: When distributing or communicating copies of the Work,
|
|
130
|
+
the Licensee will provide a machine-readable copy of the Source Code or indicate
|
|
131
|
+
a repository where this Source will be easily and freely available for as long
|
|
132
|
+
as the Licensee continues to distribute or communicate the Work.
|
|
133
|
+
|
|
134
|
+
Legal Protection: This Licence does not grant permission to use the trade names,
|
|
135
|
+
trademarks, service marks, or names of the Licensor, except as required for
|
|
136
|
+
reasonable and customary use in describing the origin of the Work and
|
|
137
|
+
reproducing the content of the copyright notice.
|
|
138
|
+
|
|
139
|
+
6. Chain of Authorship
|
|
140
|
+
|
|
141
|
+
The original Licensor warrants that the copyright in the Original Work granted
|
|
142
|
+
hereunder is owned by him/her or licensed to him/her and that he/she has the
|
|
143
|
+
power and authority to grant the Licence.
|
|
144
|
+
|
|
145
|
+
Each Contributor warrants that the copyright in the modifications he/she brings
|
|
146
|
+
to the Work are owned by him/her or licensed to him/her and that he/she has the
|
|
147
|
+
power and authority to grant the Licence.
|
|
148
|
+
|
|
149
|
+
Each time You accept the Licence, the original Licensor and subsequent
|
|
150
|
+
Contributors grant You a licence to their contributions to the Work, under the
|
|
151
|
+
terms of this Licence.
|
|
152
|
+
|
|
153
|
+
7. Disclaimer of Warranty
|
|
154
|
+
|
|
155
|
+
The Work is a work in progress, which is continuously improved by numerous
|
|
156
|
+
Contributors. It is not a finished work and may therefore contain defects or
|
|
157
|
+
‘bugs’ inherent to this type of development.
|
|
158
|
+
|
|
159
|
+
For the above reason, the Work is provided under the Licence on an ‘as is’ basis
|
|
160
|
+
and without warranties of any kind concerning the Work, including without
|
|
161
|
+
limitation merchantability, fitness for a particular purpose, absence of defects
|
|
162
|
+
or errors, accuracy, non-infringement of intellectual property rights other than
|
|
163
|
+
copyright as stated in Article 6 of this Licence.
|
|
164
|
+
|
|
165
|
+
This disclaimer of warranty is an essential part of the Licence and a condition
|
|
166
|
+
for the grant of any rights to the Work.
|
|
167
|
+
|
|
168
|
+
8. Disclaimer of Liability
|
|
169
|
+
|
|
170
|
+
Except in the cases of wilful misconduct or damages directly caused to natural
|
|
171
|
+
persons, the Licensor will in no event be liable for any direct or indirect,
|
|
172
|
+
material or moral, damages of any kind, arising out of the Licence or of the use
|
|
173
|
+
of the Work, including without limitation, damages for loss of goodwill, work
|
|
174
|
+
stoppage, computer failure or malfunction, loss of data or any commercial
|
|
175
|
+
damage, even if the Licensor has been advised of the possibility of such damage.
|
|
176
|
+
However, the Licensor will be liable under statutory product liability laws as
|
|
177
|
+
far such laws apply to the Work.
|
|
178
|
+
|
|
179
|
+
9. Additional agreements
|
|
180
|
+
|
|
181
|
+
While distributing the Work, You may choose to conclude an additional agreement,
|
|
182
|
+
defining obligations or services consistent with this Licence. However, if
|
|
183
|
+
accepting obligations, You may act only on your own behalf and on your sole
|
|
184
|
+
responsibility, not on behalf of the original Licensor or any other Contributor,
|
|
185
|
+
and only if You agree to indemnify, defend, and hold each Contributor harmless
|
|
186
|
+
for any liability incurred by, or claims asserted against such Contributor by
|
|
187
|
+
the fact You have accepted any warranty or additional liability.
|
|
188
|
+
|
|
189
|
+
10. Acceptance of the Licence
|
|
190
|
+
|
|
191
|
+
The provisions of this Licence can be accepted by clicking on an icon ‘I agree’
|
|
192
|
+
placed under the bottom of a window displaying the text of this Licence or by
|
|
193
|
+
affirming consent in any other similar way, in accordance with the rules of
|
|
194
|
+
applicable law. Clicking on that icon indicates your clear and irrevocable
|
|
195
|
+
acceptance of this Licence and all of its terms and conditions.
|
|
196
|
+
|
|
197
|
+
Similarly, you irrevocably accept this Licence and all of its terms and
|
|
198
|
+
conditions by exercising any rights granted to You by Article 2 of this Licence,
|
|
199
|
+
such as the use of the Work, the creation by You of a Derivative Work or the
|
|
200
|
+
Distribution or Communication by You of the Work or copies thereof.
|
|
201
|
+
|
|
202
|
+
11. Information to the public
|
|
203
|
+
|
|
204
|
+
In case of any Distribution or Communication of the Work by means of electronic
|
|
205
|
+
communication by You (for example, by offering to download the Work from a
|
|
206
|
+
remote location) the distribution channel or media (for example, a website) must
|
|
207
|
+
at least provide to the public the information requested by the applicable law
|
|
208
|
+
regarding the Licensor, the Licence and the way it may be accessible, concluded,
|
|
209
|
+
stored and reproduced by the Licensee.
|
|
210
|
+
|
|
211
|
+
12. Termination of the Licence
|
|
212
|
+
|
|
213
|
+
The Licence and the rights granted hereunder will terminate automatically upon
|
|
214
|
+
any breach by the Licensee of the terms of the Licence.
|
|
215
|
+
|
|
216
|
+
Such a termination will not terminate the licences of any person who has
|
|
217
|
+
received the Work from the Licensee under the Licence, provided such persons
|
|
218
|
+
remain in full compliance with the Licence.
|
|
219
|
+
|
|
220
|
+
13. Miscellaneous
|
|
221
|
+
|
|
222
|
+
Without prejudice of Article 9 above, the Licence represents the complete
|
|
223
|
+
agreement between the Parties as to the Work.
|
|
224
|
+
|
|
225
|
+
If any provision of the Licence is invalid or unenforceable under applicable
|
|
226
|
+
law, this will not affect the validity or enforceability of the Licence as a
|
|
227
|
+
whole. Such provision will be construed or reformed so as necessary to make it
|
|
228
|
+
valid and enforceable.
|
|
229
|
+
|
|
230
|
+
The European Commission may publish other linguistic versions or new versions of
|
|
231
|
+
this Licence or updated versions of the Appendix, so far this is required and
|
|
232
|
+
reasonable, without reducing the scope of the rights granted by the Licence. New
|
|
233
|
+
versions of the Licence will be published with a unique version number.
|
|
234
|
+
|
|
235
|
+
All linguistic versions of this Licence, approved by the European Commission,
|
|
236
|
+
have identical value. Parties can take advantage of the linguistic version of
|
|
237
|
+
their choice.
|
|
238
|
+
|
|
239
|
+
14. Jurisdiction
|
|
240
|
+
|
|
241
|
+
Without prejudice to specific agreement between parties,
|
|
242
|
+
|
|
243
|
+
- any litigation resulting from the interpretation of this License, arising
|
|
244
|
+
between the European Union institutions, bodies, offices or agencies, as a
|
|
245
|
+
Licensor, and any Licensee, will be subject to the jurisdiction of the Court
|
|
246
|
+
of Justice of the European Union, as laid down in article 272 of the Treaty on
|
|
247
|
+
the Functioning of the European Union,
|
|
248
|
+
|
|
249
|
+
- any litigation arising between other parties and resulting from the
|
|
250
|
+
interpretation of this License, will be subject to the exclusive jurisdiction
|
|
251
|
+
of the competent court where the Licensor resides or conducts its primary
|
|
252
|
+
business.
|
|
253
|
+
|
|
254
|
+
15. Applicable Law
|
|
255
|
+
|
|
256
|
+
Without prejudice to specific agreement between parties,
|
|
257
|
+
|
|
258
|
+
- this Licence shall be governed by the law of the European Union Member State
|
|
259
|
+
where the Licensor has his seat, resides or has his registered office,
|
|
260
|
+
|
|
261
|
+
- this licence shall be governed by Belgian law if the Licensor has no seat,
|
|
262
|
+
residence or registered office inside a European Union Member State.
|
|
263
|
+
|
|
264
|
+
Appendix
|
|
265
|
+
|
|
266
|
+
‘Compatible Licences’ according to Article 5 EUPL are:
|
|
267
|
+
|
|
268
|
+
- GNU General Public License (GPL) v. 2, v. 3
|
|
269
|
+
- GNU Affero General Public License (AGPL) v. 3
|
|
270
|
+
- Open Software License (OSL) v. 2.1, v. 3.0
|
|
271
|
+
- Eclipse Public License (EPL) v. 1.0
|
|
272
|
+
- CeCILL v. 2.0, v. 2.1
|
|
273
|
+
- Mozilla Public Licence (MPL) v. 2
|
|
274
|
+
- GNU Lesser General Public Licence (LGPL) v. 2.1, v. 3
|
|
275
|
+
- Creative Commons Attribution-ShareAlike v. 3.0 Unported (CC BY-SA 3.0) for
|
|
276
|
+
works other than software
|
|
277
|
+
- European Union Public Licence (EUPL) v. 1.1, v. 1.2
|
|
278
|
+
- Québec Free and Open-Source Licence — Reciprocity (LiLiQ-R) or Strong
|
|
279
|
+
Reciprocity (LiLiQ-R+).
|
|
280
|
+
|
|
281
|
+
The European Commission may update this Appendix to later versions of the above
|
|
282
|
+
licences without producing a new version of the EUPL, as long as they provide
|
|
283
|
+
the rights granted in Article 2 of this Licence and protect the covered Source
|
|
284
|
+
Code from exclusive appropriation.
|
|
285
|
+
|
|
286
|
+
All other changes or additions to this Appendix require the production of a new
|
|
287
|
+
EUPL version.
|
package/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# dfl
|
|
2
|
+
|
|
3
|
+
A CLI tool to manage your Deuxfleurs account.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
npm install -g git+https://git.deuxfleurs.fr/Deuxfleurs/dfl
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
*Not ready*
|
|
14
|
+
|
|
15
|
+
Start by login with your username, for example for `john`:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
dfl login john
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then you can list your websites:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
dfl list
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
And then to deploy your `_public` folder on `example.com`:
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
dfl deploy example.com _public
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Development
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
git clone https://git.deuxfleurs.fr/Deuxfleurs/dfl
|
|
37
|
+
cd dfl
|
|
38
|
+
npm install
|
|
39
|
+
tsc
|
|
40
|
+
node index.js
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
This software is distributed under the EUPL-1.2 license.
|
package/auth.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { Configuration, WebsiteApi } from "guichet-sdk-ts";
|
|
2
|
+
import { read } from 'read';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import fs from 'node:fs/promises';
|
|
5
|
+
|
|
6
|
+
function configPath(): string {
|
|
7
|
+
let path = ".dfl/config.json";
|
|
8
|
+
if (process.env.XDG_CONFIG_HOME) {
|
|
9
|
+
path = process.env.XDG_CONFIG_HOME + "/dfl/config.json";
|
|
10
|
+
} else if (process.env.HOME) {
|
|
11
|
+
path = process.env.HOME + "/.config/dfl/config.json";
|
|
12
|
+
}
|
|
13
|
+
return path
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PersistedConfig {
|
|
17
|
+
username: string,
|
|
18
|
+
password: string,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export async function openApiConf() {
|
|
22
|
+
let strConf: string;
|
|
23
|
+
let dictConf: PersistedConfig;
|
|
24
|
+
|
|
25
|
+
const configFile = configPath();
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
strConf = await fs.readFile(configFile, { encoding: 'utf8' });
|
|
29
|
+
} catch (err) {
|
|
30
|
+
console.error(err, `\n\nUnable to read ${configFile}, run 'dfl login' first.`);
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
dictConf = JSON.parse(strConf);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
console.error(err, `\n\nUnable to parse ${configFile} as JSON, check your syntax. Did you manually edit this file?`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// @FIXME: we do not validate that the dictConf object really contains a username or password field...
|
|
42
|
+
|
|
43
|
+
return new Configuration({
|
|
44
|
+
username: dictConf.username,
|
|
45
|
+
password: dictConf.password,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function login(username: string) {
|
|
50
|
+
const password = await read({
|
|
51
|
+
prompt: "password: ",
|
|
52
|
+
silent: true,
|
|
53
|
+
replace: "*"
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// check config
|
|
57
|
+
const testConf = new Configuration({
|
|
58
|
+
username: username,
|
|
59
|
+
password: password,
|
|
60
|
+
});
|
|
61
|
+
const web = new WebsiteApi(testConf);
|
|
62
|
+
try {
|
|
63
|
+
await web.listWebsites();
|
|
64
|
+
} catch (err) {
|
|
65
|
+
console.error(err, `\n\nLogin failed. Is your username and password correct?`);
|
|
66
|
+
process.exit(1);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// create config folder if needed
|
|
70
|
+
const configFile = configPath();
|
|
71
|
+
const parent = path.dirname(configFile);
|
|
72
|
+
await fs.mkdir(parent, { recursive: true });
|
|
73
|
+
|
|
74
|
+
// create, serialize, save config data
|
|
75
|
+
const configData: PersistedConfig = { username, password };
|
|
76
|
+
const serializedConfig = JSON.stringify(configData);
|
|
77
|
+
await fs.writeFile(configFile, serializedConfig, { mode: 0o600 });
|
|
78
|
+
// @FIXME: we would like to avoid storing the password in clear text in the future.
|
|
79
|
+
|
|
80
|
+
console.log('ok')
|
|
81
|
+
}
|
package/bootstrap.js
ADDED
package/deploy.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import mime from "mime";
|
|
4
|
+
import { WebsiteApi } from "guichet-sdk-ts";
|
|
5
|
+
import {
|
|
6
|
+
S3Client,
|
|
7
|
+
ListObjectsV2Command,
|
|
8
|
+
DeleteObjectsCommand,
|
|
9
|
+
DeleteObjectsCommandOutput,
|
|
10
|
+
} from "@aws-sdk/client-s3";
|
|
11
|
+
import { Upload } from "@aws-sdk/lib-storage";
|
|
12
|
+
import { openApiConf } from "./auth";
|
|
13
|
+
import Pool from "@supercharge/promise-pool";
|
|
14
|
+
|
|
15
|
+
// Walks through the local directory at path `dir`, and for each file it contains, returns :
|
|
16
|
+
// - `localPath`: its path on the local filesystem (includes `dir`). On windows, this path
|
|
17
|
+
// will typically use `\` as separator.
|
|
18
|
+
// - `s3Path`: an equivalent path as we would store it in an S3 bucket, using '/' as separator.
|
|
19
|
+
// This path includes `s3Prefix` as a prefix if provided. If `s3Prefix` is null, `s3Path`
|
|
20
|
+
// is relative to the root (of the form "a/b/c", instead of "/a/b/c" if `s3Prefix` is "").
|
|
21
|
+
async function getLocalFiles(dir: string, s3Prefix: string | null): Promise<{ localPath: string, s3Path: string}[]> {
|
|
22
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
23
|
+
const files = await Promise.all(entries.map(entry => {
|
|
24
|
+
const localPath = path.join(dir, entry.name);
|
|
25
|
+
const s3Path = s3Prefix ? s3Prefix + "/" + entry.name : entry.name;
|
|
26
|
+
if (entry.isDirectory()) {
|
|
27
|
+
return getLocalFiles(localPath, s3Path)
|
|
28
|
+
} else {
|
|
29
|
+
return Promise.resolve([{ localPath, s3Path }])
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
return files.flat()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function getBucketFiles(client: S3Client, Bucket: string): Promise<string[]> {
|
|
36
|
+
const files = [];
|
|
37
|
+
let done = false;
|
|
38
|
+
let cmd = new ListObjectsV2Command({ Bucket });
|
|
39
|
+
while (!done) {
|
|
40
|
+
const resp = await client.send(cmd);
|
|
41
|
+
if (resp.$metadata.httpStatusCode != 200) {
|
|
42
|
+
// TODO: better error handling?
|
|
43
|
+
console.error(resp);
|
|
44
|
+
process.exit(1)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (var item of resp.Contents!) {
|
|
48
|
+
files.push(item.Key!)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (resp.NextContinuationToken) {
|
|
52
|
+
cmd = new ListObjectsV2Command({
|
|
53
|
+
Bucket,
|
|
54
|
+
ContinuationToken: resp.NextContinuationToken
|
|
55
|
+
})
|
|
56
|
+
} else {
|
|
57
|
+
done = true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return files
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function uploadFile(client: S3Client, Bucket: string, Key: string, Body: any) {
|
|
64
|
+
// use `path.posix` because `Key` is a path in a bucket that uses `/` as separator.
|
|
65
|
+
let ContentType = mime.getType(path.posix.extname(Key)) ?? undefined;
|
|
66
|
+
// add charset=utf-8 by default on text files (TODO: allow the user to override this)
|
|
67
|
+
if (ContentType && ContentType.startsWith("text/")) {
|
|
68
|
+
ContentType = ContentType + "; charset=utf-8";
|
|
69
|
+
}
|
|
70
|
+
const parallelUpload = new Upload({ client, params: { Bucket, Key, Body, ContentType } });
|
|
71
|
+
parallelUpload.on("httpUploadProgress", progress => {
|
|
72
|
+
process.stdout.moveCursor(0, -1)
|
|
73
|
+
process.stdout.clearLine(1)
|
|
74
|
+
process.stdout.write("Sending " + progress.Key);
|
|
75
|
+
if (! (progress.loaded == progress.total && progress.part == 1)) {
|
|
76
|
+
process.stdout.write(" (" + progress.loaded + "/" + progress.total + ")");
|
|
77
|
+
}
|
|
78
|
+
process.stdout.write("\n");
|
|
79
|
+
});
|
|
80
|
+
await parallelUpload.done();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function deleteFiles(client: S3Client, Bucket: string, files: string[]): Promise<DeleteObjectsCommandOutput | null> {
|
|
84
|
+
if (files.length == 0) {
|
|
85
|
+
return null
|
|
86
|
+
}
|
|
87
|
+
return await client.send(new DeleteObjectsCommand({
|
|
88
|
+
Bucket,
|
|
89
|
+
Delete: {
|
|
90
|
+
Objects: files.map(f => { return { Key: f }}),
|
|
91
|
+
},
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export async function deploy(vhost: string, localFolder: string) {
|
|
96
|
+
const conf = await openApiConf();
|
|
97
|
+
|
|
98
|
+
// Get paths of the local files to deploy
|
|
99
|
+
const localFiles = await getLocalFiles(localFolder, "").catch(err => {
|
|
100
|
+
if (err.errno = -2) {
|
|
101
|
+
console.error(`Error: directory '${localFolder}' does not exist`);
|
|
102
|
+
} else {
|
|
103
|
+
console.error(err);
|
|
104
|
+
}
|
|
105
|
+
process.exit(1)
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Get website info from guichet (bucket name and keys)
|
|
109
|
+
const api = new WebsiteApi(conf);
|
|
110
|
+
let vhostInfo = await api.getWebsite({ vhost }).catch(err => {
|
|
111
|
+
if (err.response.status == 404) {
|
|
112
|
+
console.error(`Error: website '${vhost}' does not exist`);
|
|
113
|
+
} else {
|
|
114
|
+
console.error(err);
|
|
115
|
+
}
|
|
116
|
+
process.exit(1)
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
// List the files currently stored in the bucket
|
|
120
|
+
// @FIXME this info could be returned by the guichet API
|
|
121
|
+
const s3client = new S3Client({
|
|
122
|
+
endpoint: "https://garage.deuxfleurs.fr",
|
|
123
|
+
region: "garage",
|
|
124
|
+
forcePathStyle: true,
|
|
125
|
+
credentials: {
|
|
126
|
+
accessKeyId: vhostInfo.accessKeyId!,
|
|
127
|
+
secretAccessKey: vhostInfo.secretAccessKey!,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const Bucket = vhostInfo.vhost!.name!;
|
|
131
|
+
const remoteFiles = await getBucketFiles(s3client, Bucket);
|
|
132
|
+
|
|
133
|
+
// Delete files that are present in the bucket but not locally.
|
|
134
|
+
// Do this before sending the new files to avoid hitting the size quota
|
|
135
|
+
// unnecessarily.
|
|
136
|
+
const resp = await deleteFiles(
|
|
137
|
+
s3client,
|
|
138
|
+
Bucket,
|
|
139
|
+
remoteFiles.filter(f => !localFiles.find(({ s3Path }) => s3Path == f))
|
|
140
|
+
);
|
|
141
|
+
if (resp && resp!.$metadata.httpStatusCode != 200) {
|
|
142
|
+
// TODO: better error handling?
|
|
143
|
+
console.error(resp);
|
|
144
|
+
process.exit(1)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Control concurrence while uploading
|
|
148
|
+
await Pool
|
|
149
|
+
.for(localFiles)
|
|
150
|
+
.withConcurrency(6)
|
|
151
|
+
.process(({ localPath, s3Path }) => uploadFile(s3client, Bucket, s3Path,fs.createReadStream(localPath)));
|
|
152
|
+
}
|
package/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { program } from "commander";
|
|
2
|
+
import { login } from "./auth";
|
|
3
|
+
import { deploy } from "./deploy";
|
|
4
|
+
import { vhostsList } from "./vhosts";
|
|
5
|
+
|
|
6
|
+
program
|
|
7
|
+
.name('dxfl')
|
|
8
|
+
.description('Deuxfleurs CLI tool')
|
|
9
|
+
.version('0.1.0');
|
|
10
|
+
|
|
11
|
+
program.command('login')
|
|
12
|
+
.description('Link your Deuxfleurs account with this tool.')
|
|
13
|
+
.argument('<username>', 'your account username')
|
|
14
|
+
.action(login);
|
|
15
|
+
|
|
16
|
+
program.command('list')
|
|
17
|
+
.description('List all your websites')
|
|
18
|
+
.action(vhostsList);
|
|
19
|
+
|
|
20
|
+
program.command('deploy')
|
|
21
|
+
.description('Deploy your website')
|
|
22
|
+
.argument('<vhost>', 'selected vhost')
|
|
23
|
+
.argument('<local_folder>', 'your local folder')
|
|
24
|
+
.action(deploy)
|
|
25
|
+
|
|
26
|
+
program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "dxfl",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"license": "EUPL-1.2",
|
|
6
|
+
"author": "Deuxfleurs Team <coucou@deuxfleurs.fr>",
|
|
7
|
+
"type": "commonjs",
|
|
8
|
+
"main": "bootstrap.js",
|
|
9
|
+
"bin": {
|
|
10
|
+
"dfl": "./bootstrap.js"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@aws-sdk/client-s3": "^3.750.0",
|
|
17
|
+
"@aws-sdk/lib-storage": "^3.750.0",
|
|
18
|
+
"@supercharge/promise-pool": "^3.2.0",
|
|
19
|
+
"@types/node": "^22.13.5",
|
|
20
|
+
"commander": "^13.1.0",
|
|
21
|
+
"guichet-sdk-ts": "git+https://git.deuxfleurs.fr/Deuxfleurs/guichet-sdk-ts",
|
|
22
|
+
"mime": "^4.0.6",
|
|
23
|
+
"read": "^4.1.0",
|
|
24
|
+
"tsx": "^4.19.3"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
/* Visit https://aka.ms/tsconfig to read more about this file */
|
|
4
|
+
|
|
5
|
+
/* Projects */
|
|
6
|
+
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
|
7
|
+
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
|
8
|
+
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
|
9
|
+
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
|
10
|
+
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
|
11
|
+
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
|
12
|
+
|
|
13
|
+
/* Language and Environment */
|
|
14
|
+
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
|
15
|
+
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
|
16
|
+
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
|
17
|
+
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
|
18
|
+
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
|
19
|
+
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
|
20
|
+
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
|
21
|
+
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
|
22
|
+
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
|
23
|
+
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
|
24
|
+
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
|
25
|
+
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
|
26
|
+
|
|
27
|
+
/* Modules */
|
|
28
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
|
29
|
+
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
30
|
+
// "moduleResolution": "node10", /* Specify how TypeScript looks up a file from a given module specifier. */
|
|
31
|
+
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
32
|
+
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
33
|
+
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
34
|
+
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
|
35
|
+
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
|
36
|
+
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
|
37
|
+
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
|
38
|
+
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
|
|
39
|
+
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
|
|
40
|
+
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
|
41
|
+
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
|
42
|
+
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
|
43
|
+
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
|
|
44
|
+
// "resolveJsonModule": true, /* Enable importing .json files. */
|
|
45
|
+
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
|
46
|
+
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
|
47
|
+
|
|
48
|
+
/* JavaScript Support */
|
|
49
|
+
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
|
50
|
+
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
|
51
|
+
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
|
52
|
+
|
|
53
|
+
/* Emit */
|
|
54
|
+
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
|
55
|
+
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
|
56
|
+
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
|
57
|
+
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
|
58
|
+
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
59
|
+
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
60
|
+
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
61
|
+
// "outDir": "./", /* Specify an output folder for all emitted files. */
|
|
62
|
+
// "removeComments": true, /* Disable emitting comments. */
|
|
63
|
+
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
64
|
+
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
65
|
+
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
66
|
+
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
67
|
+
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
68
|
+
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
69
|
+
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
|
70
|
+
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
71
|
+
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
72
|
+
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
73
|
+
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
74
|
+
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
75
|
+
|
|
76
|
+
/* Interop Constraints */
|
|
77
|
+
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
78
|
+
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
79
|
+
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
80
|
+
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
81
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
82
|
+
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
83
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
84
|
+
|
|
85
|
+
/* Type Checking */
|
|
86
|
+
"strict": true, /* Enable all strict type-checking options. */
|
|
87
|
+
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
88
|
+
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
89
|
+
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
90
|
+
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
91
|
+
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
92
|
+
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
93
|
+
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
94
|
+
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
95
|
+
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
96
|
+
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
97
|
+
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
98
|
+
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
99
|
+
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
100
|
+
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
101
|
+
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
102
|
+
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
103
|
+
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
104
|
+
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
105
|
+
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
106
|
+
|
|
107
|
+
/* Completeness */
|
|
108
|
+
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
109
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
110
|
+
}
|
|
111
|
+
}
|
package/vhosts.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Configuration, WebsiteApi } from "guichet-sdk-ts";
|
|
2
|
+
import { openApiConf } from "./auth";
|
|
3
|
+
|
|
4
|
+
export async function vhostsList() {
|
|
5
|
+
const conf = await openApiConf();
|
|
6
|
+
const web = new WebsiteApi(conf);
|
|
7
|
+
const wlist = await web.listWebsites();
|
|
8
|
+
wlist.vhosts?.forEach(v => console.log(v.name));
|
|
9
|
+
}
|