forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshim-scss-imports.js
executable file
·37 lines (30 loc) · 1.13 KB
/
shim-scss-imports.js
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
#!/usr/bin/env node
const path = require('path');
const proc = require('child_process');
const fs = require('fs');
const findResult = proc
.spawnSync('find', ['.', '-iname', '"_*.scss"'], {
cwd: __dirname,
shell: true,
env: process.env,
})
.stdout.toString();
const sassFiles = findResult.trim().split('\n');
for (const f of sassFiles) {
const originalFileContent = fs.readFileSync(f, 'utf8');
const originalFileName = path.basename(f);
const originalDirectory = path.dirname(f);
let importFileContent = `@forward '${originalFileName
.replace(/^_/, '')
.replace('.scss', '')}';\n`;
const originalImportLines = originalFileContent.matchAll(/@import '(.+)';/g);
for (const match of originalImportLines) {
const importPath = match[1];
if (importPath.includes('@material')) continue;
if (importPath.includes('private')) continue;
importFileContent += `@forward '${importPath}';\n`;
}
const importFileName = originalFileName.replace('.scss', '.import.scss');
const importFilePath = path.join(originalDirectory, importFileName);
fs.writeFileSync(importFilePath, importFileContent, 'utf8');
}