@@ -21,61 +21,55 @@ const bundleNames = {
2121 'index.scss' : 'primer'
2222}
2323
24- remove ( outDir )
25- . then ( ( ) => mkdirp ( statsDir ) )
26- . then ( ( ) => globby ( [ `${ inDir } /**/index.scss` ] ) )
27- . then ( files => {
28- return loadConfig ( )
29- . then ( ( { plugins, options} ) => {
30- const processor = postcss ( plugins )
31- const bundles = { }
24+ async function dist ( ) {
25+ try {
26+ const bundles = { }
27+ const { plugins, options} = await loadConfig ( )
28+ const processor = postcss ( plugins )
3229
33- const inPattern = new RegExp ( `^${ inDir } /` )
34- const tasks = files . map ( from => {
35- const path = from . replace ( inPattern , '' )
36- const name = bundleNames [ path ] || getPathName ( dirname ( path ) )
30+ await remove ( outDir )
31+ await mkdirp ( statsDir )
32+ const files = await globby ( [ `${ inDir } /**/index.scss` ] )
3733
38- const to = join ( outDir , `${ name } .css` )
39- const meta = {
40- name,
41- source : from ,
42- sass : `@primer/css/${ path } ` ,
43- css : to ,
44- map : `${ to } .map` ,
45- js : join ( outDir , `${ name } .js` ) ,
46- stats : join ( statsDir , `${ name } .json` ) ,
47- legacy : `primer-${ name } /index.scss`
48- }
34+ const inPattern = new RegExp ( `^${ inDir } /` )
35+ const tasks = files . map ( async from => {
36+ const path = from . replace ( inPattern , '' )
37+ const name = bundleNames [ path ] || getPathName ( dirname ( path ) )
4938
50- return readFile ( from , encoding )
51- . then ( scss => {
52- meta . imports = getExternalImports ( scss , path ) . map ( getPathName )
53- return processor . process ( scss , Object . assign ( { from, to} , options ) )
54- } )
55- . then ( result =>
56- Promise . all ( [
57- writeFile ( to , result . css , encoding ) ,
58- writeFile ( meta . stats , JSON . stringify ( cssstats ( result . css ) ) , encoding ) ,
59- writeFile ( meta . js , `module.exports = {cssstats: require('./stats/${ name } .json')}` , encoding ) ,
60- result . map ? writeFile ( meta . map , result . map , encoding ) : null
61- ] )
62- )
63- . then ( ( ) => ( bundles [ name ] = meta ) )
64- } )
39+ const to = join ( outDir , `${ name } .css` )
40+ const meta = {
41+ name,
42+ source : from ,
43+ sass : `@primer/css/${ path } ` ,
44+ css : to ,
45+ map : `${ to } .map` ,
46+ js : join ( outDir , `${ name } .js` ) ,
47+ stats : join ( statsDir , `${ name } .json` ) ,
48+ legacy : `primer-${ name } /index.scss`
49+ }
6550
66- return Promise . all ( tasks ) . then ( ( ) => bundles )
67- } )
68- . then ( bundles => {
69- const meta = { bundles}
70- return writeFile ( join ( outDir , 'meta.json' ) , JSON . stringify ( meta , null , 2 ) , encoding )
71- } )
72- . then ( writeVariableData )
73- . then ( writeDeprecationData )
74- } )
75- . catch ( error => {
51+ const scss = await readFile ( from , encoding )
52+ meta . imports = getExternalImports ( scss , path ) . map ( getPathName )
53+ const result = await processor . process ( scss , Object . assign ( { from, to} , options ) )
54+ await Promise . all ( [
55+ writeFile ( to , result . css , encoding ) ,
56+ writeFile ( meta . stats , JSON . stringify ( cssstats ( result . css ) ) , encoding ) ,
57+ writeFile ( meta . js , `module.exports = {cssstats: require('./stats/${ name } .json')}` , encoding ) ,
58+ result . map ? writeFile ( meta . map , result . map , encoding ) : null
59+ ] )
60+ bundles [ name ] = meta
61+ } )
62+
63+ await Promise . all ( tasks )
64+
65+ const meta = { bundles}
66+ await writeFile ( join ( outDir , 'meta.json' ) , JSON . stringify ( meta , null , 2 ) , encoding )
67+ await writeDeprecationData ( )
68+ } catch ( error ) {
7669 console . error ( error )
7770 process . exitCode = 1
78- } )
71+ }
72+ }
7973
8074function getExternalImports ( scss , relativeTo ) {
8175 const imports = [ ]
@@ -104,9 +98,6 @@ function writeDeprecationData() {
10498 return writeFile ( join ( outDir , 'deprecations.json' ) , JSON . stringify ( data , null , 2 ) )
10599}
106100
107- function writeVariableData ( ) {
108- const analyzeVariables = require ( './analyze-variables' )
109- return analyzeVariables ( 'src/support/index.scss' ) . then ( data =>
110- writeFile ( join ( outDir , 'variables.json' ) , JSON . stringify ( data , null , 2 ) )
111- )
101+ if ( require . main === module ) {
102+ dist ( )
112103}
0 commit comments