@caweb/cli 1.4.3 → 1.4.5

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.
@@ -1,144 +0,0 @@
1
- /**
2
- * External dependencies
3
- */
4
- import path from 'path';
5
- import fs from 'fs';
6
- import HtmlWebpackPlugin from 'html-webpack-plugin';
7
- import jsdom from 'jsdom';
8
- import { fileURLToPath } from 'url';
9
-
10
- /**
11
- * Internal dependencies
12
- */
13
- import {
14
- generatePages
15
- } from './parser.js';
16
-
17
- /*import {
18
- projectPath,
19
- appPath
20
- } from '../lib/index.js';
21
- */
22
- const currentPath = path.dirname(fileURLToPath(import.meta.url));
23
- const projectPath = path.resolve( currentPath, '..' );
24
- const appPath = path.resolve( process.cwd() );
25
- const samplePath = path.join( appPath, 'sample');
26
- const srcPath = path.join( appPath, 'src');
27
- const dataPath = path.join( srcPath, 'data');
28
- //const assetsPath = path.join( srcPath, 'assets');
29
-
30
- // default meta used for site generation when no meta is passed
31
- const meta = {
32
- "Author": "CAWebPublishing",
33
- "Description": "State of California",
34
- "Keywords": "California,government",
35
- "viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0"
36
- }
37
-
38
-
39
- /**
40
- * Returns an object containing all data from site.json and src/data/examples.json
41
- *
42
- * @returns {Object}
43
- */
44
- function getSiteData(){
45
-
46
- // grab any sample data if it exists.
47
- let sample = fs.existsSync( path.join(dataPath, 'examples.json') ) ? JSON.parse( fs.readFileSync( path.join(dataPath, 'examples.json') ) ) : {};
48
-
49
- // grab any site data if it exists.
50
- let site = fs.existsSync( path.join(appPath, 'site.json') ) ? JSON.parse( fs.readFileSync( path.join(appPath, 'site.json') ) ) : {};
51
-
52
- // merge datasets together
53
- let siteData = {
54
- ...sample,
55
- ...site
56
- };
57
-
58
- return siteData;
59
- }
60
-
61
- export default (webpackConfig) => {
62
- // we only proceed if and index.html exists
63
- if( ! fs.existsSync( path.join( samplePath, 'index.html' )) ){
64
- return;
65
- }
66
-
67
- // we only want to display errors and warnings
68
- webpackConfig.stats = 'errors-warnings';
69
-
70
- // get site data
71
- let siteData = getSiteData();
72
-
73
- /**
74
- * Favicon
75
- *
76
- * Locations:
77
- * - ./favicon.ico - root of the project
78
- * - ./src/favicon.ico - src directory
79
- * - favicon.ico - default icon
80
- */
81
- let favicon = fs.existsSync(path.join(appPath, 'favicon.ico')) ?
82
- path.join(appPath, 'favicon.ico') :
83
- (
84
- fs.existsSync(path.join(srcPath, 'favicon.ico')) ?
85
- path.join(srcPath, 'favicon.ico') :
86
- path.join(projectPath, 'assets', 'logo.ico')
87
- );
88
-
89
- let defaultPage = {
90
- minify: false,
91
- favicon,
92
- meta: siteData.meta || meta,
93
- }
94
-
95
- // add html
96
- webpackConfig.plugins = [
97
- ...webpackConfig.plugins,
98
- new HtmlWebpackPlugin({
99
- filename: path.join( appPath, 'public', 'index.html'),
100
- template: path.join(samplePath, 'index.html'),
101
- //templateContent: generatePages(siteData),
102
- title: 'Test Site',
103
- ...defaultPage
104
- })
105
- ]
106
-
107
- // add devServer
108
- webpackConfig.devServer = {
109
- devMiddleware: {
110
- writeToDisk: true,
111
- },
112
- hot: false,
113
- allowedHosts: 'auto',
114
- host: 'localhost',
115
- port: 9000,
116
- compress: true,
117
- static: [
118
- {
119
- directory: path.join( appPath, 'build'),
120
- },
121
- {
122
- directory: path.join(appPath, 'node_modules'),
123
- },
124
- {
125
- directory: path.join(appPath, 'public'),
126
- },
127
- {
128
- directory: path.join(appPath, 'src'),
129
- }
130
- ],
131
- proxy: [
132
- {
133
- context: ['/node_modules'],
134
- target: 'http://localhost:9000',
135
- pathRewrite: { '^/node_modules': '' },
136
- },
137
- {
138
- context: ['/src'],
139
- target: 'http://localhost:9000',
140
- pathRewrite: { '^/src': '' },
141
- }
142
- ],
143
- }
144
- };