Skip to content

Commit 17ae838

Browse files
committed
Start development of new module system
1 parent 30b7773 commit 17ae838

File tree

2 files changed

+44
-11
lines changed

2 files changed

+44
-11
lines changed

cli/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env node
22

33
const fs = require('fs')
4+
const path = require('path')
45
const postcss = require('postcss');
56
const autoprefixer = require('autoprefixer');
67
const nested = require('postcss-nested');
@@ -11,9 +12,9 @@ const mediaMinMax = require('postcss-media-minmax');
1112
const customMedia = require('postcss-custom-media');
1213
const imports = require('postcss-easy-import');
1314

14-
const src = require('./src');
1515
const lh = require('./lib/lh');
1616
const typeScale = require('./lib/type-scale');
17+
const use = require('./lib/use')
1718

1819
const command = {
1920
name: process.argv[2],
@@ -33,16 +34,16 @@ const compile = async src => await postcss()
3334
.use(autoprefixer())
3435
.process(src, { parser: scssSyntax, from: command.input });
3536

36-
const build = () => {
37-
compile(fs.readFileSync(command.input, 'utf8')).then(css => {
38-
fs.writeFile(command.output, css, err => {
37+
const build = (input, output) => {
38+
compile(fs.readFileSync(input, 'utf8')).then(css => {
39+
fs.writeFile(output, css, err => {
3940
if (err) throw err
40-
console.log(`File written: ${command.output}\nFrom: ${command.input}`);
41+
console.log(`File written: ${output}\nFrom: ${input}`);
4142
})
4243
});
4344
};
4445

45-
const watch = async path => {
46+
const watch = path => {
4647
console.log(`Currently watching for changes in: ${path}`);
4748

4849
fs.watch(path, {recursive: true}, (eventType, filename) => {
@@ -53,13 +54,12 @@ const watch = async path => {
5354

5455
switch (command.name) {
5556
case 'compile':
56-
build();
57-
57+
build(command.input, command.output);
5858
break
59-
case 'watch':
60-
build();
61-
watch(src).catch(console.error);
6259

60+
case 'watch':
61+
build(command.input, command.output);
62+
watch(path.dirname(command.input));
6363
break
6464

6565
default:

cli/lib/use.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const postcss = require('postcss')
2+
const fs = require('fs')
3+
const path = require('path')
4+
5+
const defaults = {
6+
7+
}
8+
9+
module.exports = postcss.plugin('use', (opts = defaults) => {
10+
const options = Object.assign(defaults, opts)
11+
12+
return css => {
13+
14+
css.walkAtRules('use', rule => {
15+
const fileName = rule.params
16+
const fileDir = path.dirname(css.source.input.file)
17+
const filePath = path.join(fileDir, fileName)
18+
19+
const fileContent = isLocal(filePath)
20+
? fs.readFileSync(filePath, 'utf-8')
21+
: 'download file'
22+
23+
console.log(fileContent)
24+
// rule.replaceWith(fileContent)
25+
})
26+
27+
28+
}
29+
})
30+
31+
const isLocal = path => {
32+
return true
33+
}

0 commit comments

Comments
 (0)