forked from tailwindlabs/tailwindcss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
89 lines (77 loc) · 1.73 KB
/
lib.rs
File metadata and controls
89 lines (77 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use napi::bindgen_prelude::{FromNapiValue, ToNapiValue};
use std::path::PathBuf;
#[macro_use]
extern crate napi_derive;
#[derive(Debug, Clone)]
#[napi(object)]
pub struct ChangedContent {
pub file: Option<String>,
pub content: Option<String>,
pub extension: String,
}
impl From<ChangedContent> for tailwindcss_oxide::ChangedContent {
fn from(changed_content: ChangedContent) -> Self {
tailwindcss_oxide::ChangedContent {
file: changed_content.file.map(PathBuf::from),
content: changed_content.content,
}
}
}
#[derive(Debug, Clone)]
#[napi(object)]
pub struct ScanResult {
pub globs: Vec<GlobEntry>,
pub files: Vec<String>,
pub candidates: Vec<String>,
}
#[derive(Debug, Clone)]
#[napi(object)]
pub struct GlobEntry {
pub base: String,
pub glob: String,
}
#[derive(Debug, Clone)]
#[napi(object)]
pub struct ScanOptions {
pub base: String,
pub globs: Option<bool>,
}
#[napi]
pub fn clear_cache() {
tailwindcss_oxide::clear_cache();
}
#[napi]
pub fn scan_dir(args: ScanOptions) -> ScanResult {
let result = tailwindcss_oxide::scan_dir(tailwindcss_oxide::ScanOptions {
base: args.base,
globs: args.globs.unwrap_or(false),
});
ScanResult {
files: result.files,
candidates: result.candidates,
globs: result
.globs
.into_iter()
.map(|g| GlobEntry {
base: g.base,
glob: g.glob,
})
.collect(),
}
}
#[derive(Debug)]
#[napi]
pub enum IO {
Sequential = 0b0001,
Parallel = 0b0010,
}
#[derive(Debug)]
#[napi]
pub enum Parsing {
Sequential = 0b0100,
Parallel = 0b1000,
}
#[napi]
pub fn scan_files(input: Vec<ChangedContent>, strategy: u8) -> Vec<String> {
tailwindcss_oxide::scan_files(input.into_iter().map(Into::into).collect(), strategy)
}