1
- var _ = require ( 'lodash' ) ;
2
- var exec = require ( 'child_process' ) . execSync ;
3
- var fs = require ( 'fs-extra' ) ;
4
- var path = require ( 'path' ) ;
5
- var yargs = require ( 'yargs' ) ;
6
-
7
- let args = yargs ( process . argv )
8
- . usage ( "$0 [--bootstrap --minimal]" )
9
- . help ( 'help' )
10
- . boolean ( 'bootstrap' )
11
- . boolean ( 'minimal' )
12
- . argv ;
13
-
14
- if ( args . bootstrap ^ args . minimal == false ) {
15
- console . log ( "ERROR: You must either choose bootstrap or minimal" ) ;
16
- } else {
17
- if ( args . bootstrap ) {
18
- fs . copySync ( "css/useOriginalBootstrap.css" , "css/currentStyle.css" ) ;
19
- let bootstrap = fs . readFileSync ( "css/bootstrap/dist/css/bootstrap.min.css" )
20
- let mainCss = fs . readFileSync ( "css/main.css" )
21
- let str = `<dom-module id="shared-styles"><template><style>${ bootstrap } \n${ mainCss } </style></template></dom-module>` ;
22
- fs . writeFileSync ( "polymer-v2.0.0-non-keyed/src/shared-styles.html" , str ) ;
23
- } else {
24
- fs . copySync ( "css/useMinimalCss.css" , "css/currentStyle.css" ) ;
25
- let minCss = fs . readFileSync ( "css/useMinimalCss.css" )
26
- let str = `<dom-module id="shared-styles"><template><style>${ minCss } </style></template></dom-module>` ;
27
- fs . writeFileSync ( "polymer-v2.0.0-non-keyed/src/shared-styles.html" , str ) ;
28
- }
1
+ const fs = require ( "fs-extra" ) ;
2
+ const yargs = require ( "yargs" ) ;
3
+ const path = require ( "path" ) ;
4
+
5
+ const args = yargs ( process . argv )
6
+ . usage ( "$0 [--bootstrap --minimal]" )
7
+ . help ( "help" )
8
+ . boolean ( "bootstrap" )
9
+ . default ( "bootstrap" , false )
10
+ . boolean ( "minimal" )
11
+ . default ( "minimal" , false ) . argv ;
12
+
13
+ // Function to copy CSS and generate shared-styles.html
14
+ async function copyAndGenerateSharedStyles ( sourceCss , mainCss ) {
15
+ await fs . copy ( sourceCss , path . join ( "css" , "currentStyle.css" ) ) ;
16
+
17
+ // Read the main CSS file
18
+ const mainCssContent = await fs . readFile ( mainCss , "utf8" ) ;
19
+
20
+ // Generate shared-styles.html content
21
+ const sharedStylesContent = `<dom-module id="shared-styles"><template><style>${ mainCssContent } </style></template></dom-module>` ;
22
+
23
+ // Write shared-styles.html
24
+ await fs . writeFile (
25
+ path . join ( "polymer-v2.0.0-non-keyed" , "src" , "shared-styles.html" ) ,
26
+ sharedStylesContent
27
+ ) ;
29
28
}
30
29
31
-
32
- /*
33
- if (fs.existsSync("dist")) fs.removeSync("dist");
34
- fs.mkdirSync("dist");
35
- fs.mkdirSync("dist"+path.sep+"webdriver-ts");
36
- fs.copySync("webdriver-ts"+path.sep+"table.html", "dist"+path.sep+"webdriver-ts"+path.sep+"table.html");
37
-
38
- fs.copySync("index.html", "dist"+path.sep+"index.html");
39
- fs.copySync("css", "dist"+path.sep+"css");
40
-
41
- var excludes = ["node_modules","elm-stuff","project",".DS_Store"]
42
- var excludedDirectories = ['css', 'dist','node_modules','webdriver-ts'];
43
-
44
- // http://stackoverflow.com/questions/13786160/copy-folder-recursively-in-node-js
45
- function copyFileSync( source, target ) {
46
-
47
- var targetFile = target;
48
-
49
- //if target is a directory a new file with the same name will be created
50
- if ( fs.existsSync( target ) ) {
51
- if ( fs.lstatSync( target ).isDirectory() ) {
52
- targetFile = path.join( target, path.basename( source ) );
53
- }
30
+ // Main function
31
+ async function configureStyles ( ) {
32
+ try {
33
+ if ( args . bootstrap ^ args . minimal ) {
34
+ console . log ( "ERROR: You must either choose bootstrap or minimal" ) ;
35
+ return ;
54
36
}
55
37
56
- fs.writeFileSync(targetFile, fs.readFileSync(source));
57
- }
58
-
59
- function include(name) {
60
- if (name.indexOf("binding.scala")>-1) {
61
- if (name.indexOf("/target")>-1) {
62
- return name.indexOf("/target/web")>-1;
63
- }
64
- }
65
- if (excludes.every(ex => name.indexOf(ex)==-1)) {
66
- // console.log("<- filter", name);
67
- return true;
68
- } else {
69
- return false;
70
- }
71
- }
72
-
73
- function copyFolderRecursiveSync( source, target ) {
74
- var files = [];
75
-
76
- //check if folder needs to be created or integrated
77
- var targetFolder = path.join( target, path.basename( source ) );
78
- if ( !fs.existsSync( targetFolder ) ) {
79
- fs.mkdirSync( targetFolder );
80
- }
81
-
82
- //copy
83
- if ( fs.lstatSync( source ).isDirectory() ) {
84
- files = fs.readdirSync( source );
85
- files.forEach( function ( file ) {
86
- if (include(file)) {
87
- var curSource = path.join( source, file );
88
- if ( fs.lstatSync( curSource ).isDirectory() ) {
89
- // console.log("copy dir "+curSource);
90
- copyFolderRecursiveSync( curSource, targetFolder );
91
- } else if ( fs.lstatSync( curSource ).isSymbolicLink() ) {
92
- console.log("**** LINK");
93
- } else {
94
- // console.log("copy file "+curSource);
95
- copyFileSync( curSource, targetFolder );
96
- }
97
- }
98
- } );
38
+ // Read and copy the appropriate CSS file
39
+ if ( args . bootstrap ) {
40
+ await copyAndGenerateSharedStyles (
41
+ path . join ( "css" , "useOriginalBootstrap.css" ) ,
42
+ path . join ( "css" , "bootstrap" , "dist" , "css" , "bootstrap.min.css" )
43
+ ) ;
44
+ } else {
45
+ await copyAndGenerateSharedStyles (
46
+ path . join ( "css" , "useMinimalCss.css" ) ,
47
+ path . join ( "css" , "useMinimalCss.css" )
48
+ ) ;
99
49
}
50
+ } catch ( error ) {
51
+ console . error ( "An error occurred:" , error . message ) ;
52
+ }
100
53
}
101
54
102
- _.each(fs.readdirSync('.'), function(name) {
103
- if(fs.statSync(name).isDirectory() && name[0] !== '.' && excludedDirectories.indexOf(name)==-1) {
104
- console.log("dist"+path.sep+name);
105
- fs.mkdirSync("dist"+path.sep+name);
106
- copyFolderRecursiveSync(name, "dist");
107
-
108
- }
109
- });
110
-
111
- */
55
+ configureStyles ( ) ;
0 commit comments