buner 1.0.5 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{bin → dist}/buner.js +40 -34
- package/{integration.ts → dist/integration.js} +51 -100
- package/dist/migrate-scss.js +33 -0
- package/dist/prerender.js +158 -0
- package/dist/scripts.js +36 -0
- package/dist/server.js +171 -0
- package/dist/states.js +41 -0
- package/dist/styles.js +165 -0
- package/index.html +1 -1
- package/package.json +3 -12
- package/xpack/alias.ts +3 -2
- package/xpack/hooks/options.ts +2 -2
- package/xpack/hooks/transform-index-html.ts +4 -2
- package/xpack/react-loader-init.tsx +1 -1
- package/cli/README.md +0 -1
- package/cli/buner.ts +0 -264
- package/cli/cli.ts +0 -125
- package/cli/create-app.ts +0 -59
- package/cli/helpers/copy.ts +0 -61
- package/cli/helpers/format-files.ts +0 -197
- package/cli/helpers/git.ts +0 -77
- package/cli/helpers/install.ts +0 -26
- package/cli/helpers/is-folder-empty.ts +0 -40
- package/cli/helpers/is-writeable.ts +0 -14
- package/cli/helpers/make-dir.ts +0 -7
- package/cli/helpers/validate-pkg.ts +0 -17
- package/cli/install-template.ts +0 -72
- package/migrate-scss.ts +0 -42
- package/prerender.ts +0 -229
- package/scripts.ts +0 -56
- package/server.ts +0 -29
- package/states.ts +0 -63
- package/styles.ts +0 -232
package/styles.ts
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import { fileURLToPath, pathToFileURL } from 'url';
|
|
5
|
-
|
|
6
|
-
import { watch } from 'chokidar';
|
|
7
|
-
import * as sass from 'sass';
|
|
8
|
-
import slash from 'slash';
|
|
9
|
-
import debounce from 'debounce';
|
|
10
|
-
import { glob } from 'glob';
|
|
11
|
-
import postcss, { ProcessOptions } from 'postcss';
|
|
12
|
-
import autoprefixer from 'autoprefixer';
|
|
13
|
-
import cssnano from 'cssnano';
|
|
14
|
-
|
|
15
|
-
const isWatch = process.argv.includes('--watch');
|
|
16
|
-
const outDir = './public/assets/css';
|
|
17
|
-
|
|
18
|
-
if (!isWatch && fs.existsSync(outDir)) {
|
|
19
|
-
fs.rmSync(outDir, { force: true, recursive: true });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (!fs.existsSync(outDir)) {
|
|
23
|
-
fs.mkdirSync(outDir, { recursive: true });
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Something to use when events are received.
|
|
27
|
-
const log = console.log.bind(console);
|
|
28
|
-
|
|
29
|
-
const prepareCssFileContent = ({
|
|
30
|
-
srcFile,
|
|
31
|
-
includeMixins = true,
|
|
32
|
-
includeAbstracts = true,
|
|
33
|
-
}: {
|
|
34
|
-
srcFile: string;
|
|
35
|
-
includeMixins?: boolean;
|
|
36
|
-
includeAbstracts?: boolean;
|
|
37
|
-
}) => {
|
|
38
|
-
return [
|
|
39
|
-
includeAbstracts
|
|
40
|
-
? slash(`@use '${path.relative(path.dirname(srcFile), path.resolve('src/assets/styles/00-abstracts/abstracts'))}' as *;\n`)
|
|
41
|
-
: undefined,
|
|
42
|
-
includeMixins ? slash(`@use '${path.relative(path.dirname(srcFile), path.resolve('src/assets/styles/01-mixins/mixins'))}' as *;\n`) : undefined,
|
|
43
|
-
fs.readFileSync(srcFile, 'utf-8'),
|
|
44
|
-
].filter(Boolean);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const stringOptions = (srcFile: string): sass.StringOptions<'sync' | 'async'> => {
|
|
48
|
-
const options: sass.StringOptions<'sync' | 'async'> = {
|
|
49
|
-
sourceMap: true,
|
|
50
|
-
sourceMapIncludeSources: true,
|
|
51
|
-
syntax: 'scss',
|
|
52
|
-
style: 'compressed',
|
|
53
|
-
url: pathToFileURL(path.resolve(srcFile)),
|
|
54
|
-
importer: {
|
|
55
|
-
canonicalize(url) {
|
|
56
|
-
return new URL(url);
|
|
57
|
-
},
|
|
58
|
-
load(canonicalUrl: URL) {
|
|
59
|
-
let filePath = fileURLToPath(canonicalUrl);
|
|
60
|
-
|
|
61
|
-
if (!filePath.endsWith('.scss')) {
|
|
62
|
-
const parentDir = path.dirname(filePath);
|
|
63
|
-
const fileName = path.basename(filePath);
|
|
64
|
-
|
|
65
|
-
filePath = path.join(parentDir, fileName + '.scss');
|
|
66
|
-
|
|
67
|
-
if (!fs.existsSync(filePath)) {
|
|
68
|
-
filePath = path.join(parentDir, '_' + fileName + '.scss');
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!fs.existsSync(filePath)) return null;
|
|
73
|
-
|
|
74
|
-
if (filePath.includes('abstracts') || filePath.includes('_mixins') || filePath.includes('_base') || filePath.includes('xpack'))
|
|
75
|
-
return {
|
|
76
|
-
contents: fs.readFileSync(filePath, 'utf-8'),
|
|
77
|
-
syntax: 'scss',
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
let content = prepareCssFileContent({ srcFile: filePath });
|
|
81
|
-
|
|
82
|
-
if (filePath.includes('mixins')) {
|
|
83
|
-
content = prepareCssFileContent({ srcFile: filePath, includeMixins: false });
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
contents: content.join(''),
|
|
88
|
-
syntax: 'scss',
|
|
89
|
-
};
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return options;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const compile = (srcFile: string, options: { prefix?: string; isReady: boolean }) => {
|
|
98
|
-
if (options.isReady) {
|
|
99
|
-
log('compile:', slash(srcFile));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (path.basename(srcFile).startsWith('_')) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const name =
|
|
107
|
-
path.basename(srcFile) === 'index.scss' ? path.basename(path.dirname(srcFile)) + '.css' : path.basename(srcFile).replace(/\.scss$/gi, '.css');
|
|
108
|
-
|
|
109
|
-
const outFile = (options.prefix ?? '') + name;
|
|
110
|
-
|
|
111
|
-
const cssStrings = srcFile.includes('xpack') ? [fs.readFileSync(srcFile, 'utf-8')] : prepareCssFileContent({ srcFile });
|
|
112
|
-
|
|
113
|
-
if (srcFile.includes('style-base') || srcFile.includes('style-all')) {
|
|
114
|
-
glob.sync('./src/atoms/**/*.scss').forEach((atomPath) => {
|
|
115
|
-
if (!path.basename(atomPath).startsWith('_')) {
|
|
116
|
-
cssStrings.push(sass.compileString(prepareCssFileContent({ srcFile: atomPath }).join(''), stringOptions(atomPath)).css);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
glob.sync('./src/molecules/**/*.scss').forEach((molPath) => {
|
|
121
|
-
if (!path.basename(molPath).startsWith('_')) {
|
|
122
|
-
cssStrings.push(sass.compileString(prepareCssFileContent({ srcFile: molPath }).join(''), stringOptions(molPath)).css);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
sass
|
|
128
|
-
.compileStringAsync(cssStrings.join(''), stringOptions(srcFile))
|
|
129
|
-
.then((result) => postcssProcess(result, srcFile, outFile))
|
|
130
|
-
.catch((error) => {
|
|
131
|
-
log(error);
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
const postcssProcess = (result: sass.CompileResult, from: string, to: string) => {
|
|
136
|
-
const postcssOptions: ProcessOptions = { from: pathToFileURL(from).href, to, map: { prev: result.sourceMap, absolute: false } };
|
|
137
|
-
|
|
138
|
-
postcss([autoprefixer({ grid: true }), cssnano])
|
|
139
|
-
.process(result.css, postcssOptions)
|
|
140
|
-
.then((result) => {
|
|
141
|
-
fs.writeFileSync(path.join(outDir, to), result.css + (result.map ? `\n/*# sourceMappingURL=${to}.map */` : ''));
|
|
142
|
-
|
|
143
|
-
if (result.map) {
|
|
144
|
-
fs.writeFileSync(path.join(outDir, to + '.map'), result.map.toString());
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const styleOrganisms = debounce((isReady: boolean) => {
|
|
150
|
-
const paths = glob.sync('src/organisms/**/*.scss', { nodir: true });
|
|
151
|
-
|
|
152
|
-
[].forEach.call(paths, (p: string) => styleOrganism(p, isReady));
|
|
153
|
-
}, 200);
|
|
154
|
-
|
|
155
|
-
const styleTemplates = debounce((isReady: boolean) => {
|
|
156
|
-
const paths = glob.sync('src/templates/**/*.scss', { nodir: true });
|
|
157
|
-
|
|
158
|
-
[].forEach.call(paths, (p: string) => styleTemplate(p, isReady));
|
|
159
|
-
}, 200);
|
|
160
|
-
|
|
161
|
-
const styleBase = debounce((isReady: boolean) => compile('src/assets/styles/style-base.scss', { isReady }), 200);
|
|
162
|
-
const stylePlState = debounce((isReady: boolean) => compile('xpack/styles/pl-states.scss', { isReady }), 200);
|
|
163
|
-
const styleRoot = debounce((isReady: boolean) => compile('xpack/styles/root.scss', { isReady }), 200);
|
|
164
|
-
const styleOrganism = (srcFile: string, isReady: boolean) => compile(srcFile, { prefix: 'b-', isReady });
|
|
165
|
-
const styleTemplate = (srcFile: string, isReady: boolean) => compile(srcFile, { prefix: 'p-', isReady });
|
|
166
|
-
|
|
167
|
-
const sassCompile = (inputPath: string, isReady: boolean) => {
|
|
168
|
-
const p = slash(inputPath);
|
|
169
|
-
|
|
170
|
-
if (p.startsWith('src/assets/styles/00-abstracts/') || p.startsWith('src/assets/styles/01-mixins/')) {
|
|
171
|
-
styleBase(isReady);
|
|
172
|
-
styleOrganisms(isReady);
|
|
173
|
-
styleTemplates(isReady);
|
|
174
|
-
stylePlState(isReady);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
if (p.startsWith('src/atoms') || p.startsWith('src/molecules') || p.startsWith('src/assets/styles/02-base')) {
|
|
178
|
-
styleBase(isReady);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (p.startsWith('src/organisms')) {
|
|
182
|
-
if (path.basename(p).startsWith('_')) {
|
|
183
|
-
glob
|
|
184
|
-
.sync(path.dirname(p) + '/*.scss', { nodir: true })
|
|
185
|
-
.filter((p) => !path.basename(p).startsWith('_'))
|
|
186
|
-
.forEach((p) => styleOrganism(p, isReady));
|
|
187
|
-
} else {
|
|
188
|
-
styleOrganism(p, isReady);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (p.startsWith('src/templates')) {
|
|
193
|
-
if (path.basename(p).startsWith('_')) {
|
|
194
|
-
glob
|
|
195
|
-
.sync(path.dirname(p) + '/*.scss', { nodir: true })
|
|
196
|
-
.filter((p) => !path.basename(p).startsWith('_'))
|
|
197
|
-
.forEach((p) => styleTemplate(p, isReady));
|
|
198
|
-
} else {
|
|
199
|
-
styleTemplate(p, isReady);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (p.startsWith('xpack/styles/pl-states')) {
|
|
204
|
-
stylePlState(isReady);
|
|
205
|
-
} else if (p.startsWith('xpack/styles')) {
|
|
206
|
-
styleRoot(isReady);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
if (isWatch) {
|
|
211
|
-
const watcher = watch(['src', 'xpack/styles'], { ignored: (path, stats) => !!stats?.isFile() && !path.endsWith('.scss') });
|
|
212
|
-
let isReady = false;
|
|
213
|
-
|
|
214
|
-
watcher
|
|
215
|
-
.on('ready', () => {
|
|
216
|
-
log('SCSS ready!');
|
|
217
|
-
isReady = true;
|
|
218
|
-
})
|
|
219
|
-
.on('add', (path) => sassCompile(path, isReady))
|
|
220
|
-
.on('change', (path) => sassCompile(path, isReady))
|
|
221
|
-
.on('unlink', (path) => log(`File ${path} has been removed`));
|
|
222
|
-
} else {
|
|
223
|
-
styleBase(true);
|
|
224
|
-
stylePlState(true);
|
|
225
|
-
|
|
226
|
-
glob
|
|
227
|
-
.sync(['src/{organisms,templates}/**/*.scss', 'xpack/styles/**/*.scss'])
|
|
228
|
-
.filter((p) => !path.basename(p).startsWith('_'))
|
|
229
|
-
.forEach((path) => sassCompile(path, true));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export {};
|