1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Stylable = void 0;
|
4 | const create_infra_structure_1 = require("./create-infra-structure");
|
5 | const diagnostics_1 = require("./diagnostics");
|
6 | const parser_1 = require("./parser");
|
7 | const stylable_processor_1 = require("./stylable-processor");
|
8 | const stylable_resolver_1 = require("./stylable-resolver");
|
9 | const stylable_transformer_1 = require("./stylable-transformer");
|
10 | class Stylable {
|
11 | constructor(projectRoot, fileSystem, requireModule, delimiter = '__', onProcess, diagnostics = new diagnostics_1.Diagnostics(), hooks = {}, resolveOptions = {}, optimizer, mode = 'production', resolveNamespace, timedCacheOptions = {
|
12 | timeout: 1,
|
13 | useTimer: true,
|
14 | }, resolveModule) {
|
15 | this.projectRoot = projectRoot;
|
16 | this.fileSystem = fileSystem;
|
17 | this.requireModule = requireModule;
|
18 | this.delimiter = delimiter;
|
19 | this.onProcess = onProcess;
|
20 | this.diagnostics = diagnostics;
|
21 | this.hooks = hooks;
|
22 | this.resolveOptions = resolveOptions;
|
23 | this.optimizer = optimizer;
|
24 | this.mode = mode;
|
25 | this.resolveNamespace = resolveNamespace;
|
26 | this.timedCacheOptions = timedCacheOptions;
|
27 | this.resolveModule = resolveModule;
|
28 | const { fileProcessor, resolvePath } = create_infra_structure_1.createInfrastructure(projectRoot, fileSystem, onProcess, resolveOptions, this.resolveNamespace, timedCacheOptions, resolveModule);
|
29 | this.resolvePath = resolvePath;
|
30 | this.fileProcessor = fileProcessor;
|
31 | this.resolver = new stylable_resolver_1.StylableResolver(this.fileProcessor, this.requireModule);
|
32 | }
|
33 | static create(config) {
|
34 | return new this(config.projectRoot, config.fileSystem, (id) => {
|
35 | if (config.requireModule) {
|
36 | return config.requireModule(id);
|
37 | }
|
38 | throw new Error('Javascript files are not supported without requireModule options');
|
39 | }, config.delimiter, config.onProcess, config.diagnostics, config.hooks, config.resolveOptions, config.optimizer, config.mode, config.resolveNamespace, config.timedCacheOptions, config.resolveModule);
|
40 | }
|
41 | createTransformer(options = {}) {
|
42 | return new stylable_transformer_1.StylableTransformer({
|
43 | delimiter: this.delimiter,
|
44 | diagnostics: new diagnostics_1.Diagnostics(),
|
45 | fileProcessor: this.fileProcessor,
|
46 | requireModule: this.requireModule,
|
47 | postProcessor: this.hooks.postProcessor,
|
48 | replaceValueHook: this.hooks.replaceValueHook,
|
49 | mode: this.mode,
|
50 | ...options,
|
51 | });
|
52 | }
|
53 | transform(meta, resourcePath, options = {}) {
|
54 | if (typeof meta === 'string') {
|
55 |
|
56 |
|
57 | const root = parser_1.safeParse(meta, { from: resourcePath });
|
58 | meta = new stylable_processor_1.StylableProcessor(undefined, this.resolveNamespace).process(root);
|
59 | }
|
60 | const transformer = this.createTransformer(options);
|
61 | this.fileProcessor.add(meta.source, meta);
|
62 | return transformer.transform(meta);
|
63 | }
|
64 | process(fullpath, context, ignoreCache) {
|
65 | return this.fileProcessor.process(fullpath, ignoreCache, context);
|
66 | }
|
67 | }
|
68 | exports.Stylable = Stylable;
|
69 |
|
\ | No newline at end of file |