Skip to content

Commit 8764774

Browse files
committed
chore: release v0.1.2
1 parent 844618b commit 8764774

File tree

7 files changed

+262
-44
lines changed

7 files changed

+262
-44
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
1-
## [0.1.1](https://github.com/xiaoluoboding/vue-sfc2esm/compare/v0.1.0...v0.1.1) (2021-04-26)
1+
## [0.1.2](https://github.com/xiaoluoboding/vue-sfc2esm/compare/v0.1.1...v0.1.2) (2021-04-28)
22

33

44
### Features
55

6-
* isolate file errors & remove crypto fn ([99cf104](https://github.com/xiaoluoboding/vue-sfc2esm/commit/99cf104229cf2c3382a4ca523a38b19227b07e30))
6+
* add code comment ([345f5b5](https://github.com/xiaoluoboding/vue-sfc2esm/commit/345f5b5e2f56d05379399bdaea949ae7ee797fea))
7+
* make deleteFile function could without confirm ([fa3fd42](https://github.com/xiaoluoboding/vue-sfc2esm/commit/fa3fd422b495b2b80aae03a334e93258e266aa48))
78

89

910

1011
## [0.1.1](https://github.com/xiaoluoboding/vue-sfc2esm/compare/v0.1.0...v0.1.1) (2021-04-26)
1112

1213

14+
### Features
15+
16+
* isolate file errors & remove crypto fn ([99cf104](https://github.com/xiaoluoboding/vue-sfc2esm/commit/99cf104229cf2c3382a4ca523a38b19227b07e30))
17+
18+
1319

14-
## 0.1.1 (2021-04-26)
20+
# [0.1.0](https://github.com/xiaoluoboding/vue-sfc2esm/compare/5e18fb5f646bbab738a87996918b226d19bed5bc...v0.1.0) (2021-04-24)
1521

1622

1723
### Features

lib/vue-sfc2esm.cjs.js

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-sfc2esm v0.1.1
2+
* vue-sfc2esm v0.1.2
33
* (c) 2021 xiaoluoboding
44
* @license MIT
55
*/
@@ -40,6 +40,11 @@ const COMP_IDENTIFIER = `__sfc__`;
4040
* but we may swap it out with a version fetched from CDNs
4141
*/
4242
let SFCCompiler = defaultCompiler__namespace;
43+
/**
44+
* Compile the `activeFile` in the store. It will change the File.compiled info.
45+
*
46+
* @param File
47+
*/
4348
async function compileFile({ filename, code, compiled }) {
4449
if (!code.trim()) {
4550
compiled.errors = [];
@@ -235,7 +240,9 @@ const IMPORT_MAP_CODE = `
235240
"imports": {
236241
}
237242
}`.trim();
238-
// Virtual Simple File System
243+
/**
244+
* Simple Virtual File System
245+
*/
239246
class File {
240247
constructor(filename, code = '') {
241248
this.compiled = {
@@ -276,6 +283,11 @@ for (const file in store.files) {
276283
compileFile(store.files[file]);
277284
}
278285
}
286+
/**
287+
* Export the files code.
288+
*
289+
* @returns exported
290+
*/
279291
function exportFiles() {
280292
const exported = {};
281293
for (const filename in store.files) {
@@ -287,20 +299,39 @@ function setActive(filename, code) {
287299
store.activeFilename = filename;
288300
store.activeFile.code = code;
289301
}
302+
/**
303+
* Record File errors when compiling file.
304+
*
305+
* @param errors
306+
*/
290307
function recordFileErrors(errors) {
291308
store.activeFile.compiled.errors = errors;
292309
}
310+
/**
311+
* Check whether has a filename in store.
312+
*
313+
* @param filename
314+
*/
315+
function hasFile(filename) {
316+
if (!(filename in store.files)) {
317+
recordFileErrors([`File "${filename}" is not exists.`]);
318+
return;
319+
}
320+
}
321+
/**
322+
* Add a file into the store, ready for compilation.
323+
*
324+
* @param filename
325+
* @param code
326+
*/
293327
function addFile(filename, code) {
294328
if (!filename.endsWith('.vue') &&
295329
!filename.endsWith('.js') &&
296330
filename !== 'import-map.json') {
297331
recordFileErrors(['Sandbox only supports *.vue, *.js files or import-map.json.']);
298332
return;
299333
}
300-
if (filename in store.files) {
301-
recordFileErrors([`File "${filename}" already exists.`]);
302-
return;
303-
}
334+
hasFile(filename);
304335
const file = (store.files[filename] = new File(filename));
305336
if (filename === 'import-map.json') {
306337
file.code = IMPORT_MAP_CODE;
@@ -310,23 +341,43 @@ function addFile(filename, code) {
310341
}
311342
setActive(filename, file.code);
312343
}
344+
/**
345+
* Change the file code, It will trigger `compileFile` action.
346+
*
347+
* @param filename
348+
* @param code
349+
*/
313350
function changeFile(filename, code) {
314-
if (!(filename in store.files)) {
315-
recordFileErrors([`File "${filename}" is not exists.`]);
316-
return;
317-
}
351+
hasFile(filename);
318352
const file = store.files[filename];
319353
setActive(file.filename, code);
320354
}
321-
function deleteFile(filename) {
322-
if (confirm(`Are you sure you want to delete ${filename}?`)) {
355+
/**
356+
* Delete the file in the store. with or without confirmation.
357+
*
358+
* @param filename
359+
* @param withConfirm
360+
*/
361+
function deleteFile(filename, withConfirm) {
362+
hasFile(filename);
363+
const doDelete = () => {
323364
if (store.activeFilename === filename) {
324365
store.activeFilename = APP_FILE;
325366
}
326367
delete store.files[filename];
368+
};
369+
if (withConfirm && confirm(`Are you sure you want to delete ${filename}?`)) {
370+
doDelete();
371+
return;
327372
}
373+
doDelete();
328374
}
329375

376+
/**
377+
* Transpiled Vue SFC File to ES modules with `@vue/compiler-sfc`.
378+
*
379+
* @param filename
380+
*/
330381
async function compileModules(filename) {
331382
if (filename !== activeFilename.value)
332383
return [];

lib/vue-sfc2esm.d.ts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1+
/**
2+
* Transpiled Vue SFC File to ES modules with `@vue/compiler-sfc`.
3+
*
4+
* @param filename
5+
*/
16
declare function compileModules(filename: string): Promise<Array<string>>;
27

8+
/**
9+
* Record the code & errors when a sfc file has been compiled.
10+
*/
311
interface FileCompiled {
412
js: string;
513
css: string;
614
ssr: string;
715
errors: Array<string | Error>;
816
}
17+
/**
18+
* Simple Virtual File System
19+
*/
920
declare class File {
1021
filename: string;
1122
code: string;
1223
compiled: FileCompiled;
1324
constructor(filename: string, code?: string);
1425
}
26+
/**
27+
* `vue-sfc2esm` built-in store.
28+
*/
1529
interface Store {
1630
files: Record<string, File>;
1731
activeFilename: string;
@@ -20,12 +34,45 @@ interface Store {
2034
errors: Array<string | Error>;
2135
}
2236
declare const store: Store;
37+
/**
38+
* Export the files code.
39+
*
40+
* @returns exported
41+
*/
2342
declare function exportFiles(): Record<string, string>;
43+
/**
44+
* Record File errors when compiling file.
45+
*
46+
* @param errors
47+
*/
2448
declare function recordFileErrors(errors: Array<string | Error>): void;
49+
/**
50+
* Add a file into the store, ready for compilation.
51+
*
52+
* @param filename
53+
* @param code
54+
*/
2555
declare function addFile(filename: string, code: string): void;
56+
/**
57+
* Change the file code, It will trigger `compileFile` action.
58+
*
59+
* @param filename
60+
* @param code
61+
*/
2662
declare function changeFile(filename: string, code: string): void;
27-
declare function deleteFile(filename: string): void;
63+
/**
64+
* Delete the file in the store. with or without confirmation.
65+
*
66+
* @param filename
67+
* @param withConfirm
68+
*/
69+
declare function deleteFile(filename: string, withConfirm?: boolean): void;
2870

71+
/**
72+
* Compile the `activeFile` in the store. It will change the File.compiled info.
73+
*
74+
* @param File
75+
*/
2976
declare function compileFile({ filename, code, compiled }: File): Promise<void>;
3077

3178
export { addFile, changeFile, compileFile, compileModules, deleteFile, exportFiles, recordFileErrors, store };

lib/vue-sfc2esm.esm.js

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-sfc2esm v0.1.1
2+
* vue-sfc2esm v0.1.2
33
* (c) 2021 xiaoluoboding
44
* @license MIT
55
*/
@@ -14,6 +14,11 @@ const COMP_IDENTIFIER = `__sfc__`;
1414
* but we may swap it out with a version fetched from CDNs
1515
*/
1616
let SFCCompiler = defaultCompiler;
17+
/**
18+
* Compile the `activeFile` in the store. It will change the File.compiled info.
19+
*
20+
* @param File
21+
*/
1722
async function compileFile({ filename, code, compiled }) {
1823
if (!code.trim()) {
1924
compiled.errors = [];
@@ -209,7 +214,9 @@ const IMPORT_MAP_CODE = `
209214
"imports": {
210215
}
211216
}`.trim();
212-
// Virtual Simple File System
217+
/**
218+
* Simple Virtual File System
219+
*/
213220
class File {
214221
constructor(filename, code = '') {
215222
this.compiled = {
@@ -250,6 +257,11 @@ for (const file in store.files) {
250257
compileFile(store.files[file]);
251258
}
252259
}
260+
/**
261+
* Export the files code.
262+
*
263+
* @returns exported
264+
*/
253265
function exportFiles() {
254266
const exported = {};
255267
for (const filename in store.files) {
@@ -261,20 +273,39 @@ function setActive(filename, code) {
261273
store.activeFilename = filename;
262274
store.activeFile.code = code;
263275
}
276+
/**
277+
* Record File errors when compiling file.
278+
*
279+
* @param errors
280+
*/
264281
function recordFileErrors(errors) {
265282
store.activeFile.compiled.errors = errors;
266283
}
284+
/**
285+
* Check whether has a filename in store.
286+
*
287+
* @param filename
288+
*/
289+
function hasFile(filename) {
290+
if (!(filename in store.files)) {
291+
recordFileErrors([`File "${filename}" is not exists.`]);
292+
return;
293+
}
294+
}
295+
/**
296+
* Add a file into the store, ready for compilation.
297+
*
298+
* @param filename
299+
* @param code
300+
*/
267301
function addFile(filename, code) {
268302
if (!filename.endsWith('.vue') &&
269303
!filename.endsWith('.js') &&
270304
filename !== 'import-map.json') {
271305
recordFileErrors(['Sandbox only supports *.vue, *.js files or import-map.json.']);
272306
return;
273307
}
274-
if (filename in store.files) {
275-
recordFileErrors([`File "${filename}" already exists.`]);
276-
return;
277-
}
308+
hasFile(filename);
278309
const file = (store.files[filename] = new File(filename));
279310
if (filename === 'import-map.json') {
280311
file.code = IMPORT_MAP_CODE;
@@ -284,23 +315,43 @@ function addFile(filename, code) {
284315
}
285316
setActive(filename, file.code);
286317
}
318+
/**
319+
* Change the file code, It will trigger `compileFile` action.
320+
*
321+
* @param filename
322+
* @param code
323+
*/
287324
function changeFile(filename, code) {
288-
if (!(filename in store.files)) {
289-
recordFileErrors([`File "${filename}" is not exists.`]);
290-
return;
291-
}
325+
hasFile(filename);
292326
const file = store.files[filename];
293327
setActive(file.filename, code);
294328
}
295-
function deleteFile(filename) {
296-
if (confirm(`Are you sure you want to delete ${filename}?`)) {
329+
/**
330+
* Delete the file in the store. with or without confirmation.
331+
*
332+
* @param filename
333+
* @param withConfirm
334+
*/
335+
function deleteFile(filename, withConfirm) {
336+
hasFile(filename);
337+
const doDelete = () => {
297338
if (store.activeFilename === filename) {
298339
store.activeFilename = APP_FILE;
299340
}
300341
delete store.files[filename];
342+
};
343+
if (withConfirm && confirm(`Are you sure you want to delete ${filename}?`)) {
344+
doDelete();
345+
return;
301346
}
347+
doDelete();
302348
}
303349

350+
/**
351+
* Transpiled Vue SFC File to ES modules with `@vue/compiler-sfc`.
352+
*
353+
* @param filename
354+
*/
304355
async function compileModules(filename) {
305356
if (filename !== activeFilename.value)
306357
return [];

0 commit comments

Comments
 (0)