1- const path = require ( 'path' ) ;
21const webpack = require ( 'webpack' ) ;
32const { terminal } = require ( 'terminal-kit' ) ;
43// eslint-disable-next-line import/no-extraneous-dependencies
@@ -7,11 +6,9 @@ const webpackConfig = require('./build/webpack');
76
87const spinner = ora ( ) ;
98
10- const { findAllProjectPaths, validateProject } = require ( './../utils/projectpaths' ) ;
11- const { getPackage } = require ( './../utils/get-package' ) ;
129const { getFilteredEntryPoints } = require ( './../utils/get-filtered-entrypoints' ) ;
13- const dirsExist = require ( '../utils/dirs-exist' ) ;
1410const getProjectConfig = require ( '../utils/get-project-config' ) ;
11+ const getPackagesForCommand = require ( '../utils/get-packages-for-command' ) ;
1512
1613global . buildCount = 0 ;
1714
@@ -56,66 +53,16 @@ exports.handler = async ({
5653 once = false ,
5754 quiet = false ,
5855} ) => {
59- const currentLocation = path . basename ( process . cwd ( ) ) ;
60-
6156 const mode = production ? 'production' : 'development' ;
62- // Use env variables if working on Webpack >=5.
63- const projectsList = projects . split ( ',' ) . map ( ( item ) => item . split ( '@' ) [ 0 ] ) . filter ( ( item ) => item . length > 0 ) ;
64- const hasTargetDirs = dirsExist ( targetDirs ) ;
65- const isAllProjects = ( site || hasTargetDirs ) && ( ! projects || projectsList . length === 0 ) ;
66-
67- let packages = [ ] ;
68-
69- try {
70- if ( projectsList . length === 0 && ! isAllProjects ) {
71- // Is project root - a standalone build.
72- terminal ( `\x1b[1mCompiling \x1b[4msingle\x1b[0m\x1b[1m project in ${ mode } mode.\x1b[0m\n` ) ;
73- packages . push ( getPackage ( path . resolve ( './' ) ) ) ;
74- } else if ( isAllProjects ) {
75- // Find all projects through-out the site.
76- terminal ( `\x1b[1mCompiling \x1b[4mall\x1b[0m\x1b[1m projects in ${ mode } mode.\x1b[0m\n` ) ;
77- packages = findAllProjectPaths ( targetDirs ) . map ( ( path ) => getPackage ( path ) ) ;
78- } else {
79- // List of projects.
80- terminal ( `\x1b[1mCompiling \x1b[4mlist\x1b[0m\x1b[1m of projects in ${ mode } mode.\x1b[0m\n` ) ;
81- packages = findAllProjectPaths ( targetDirs , projectsList ) . map ( ( path ) => getPackage ( path ) ) ;
82-
83- const packageNames = packages . map ( ( pkg ) => pkg . name ) ;
84- projectsList . map ( ( projectName ) => {
85- if ( ! packageNames . includes ( projectName ) ) {
86- terminal . red ( `Error: Project ${ projectName } does not exist.\n` ) ;
87- }
88- packageNames . includes ( projectName ) ;
89- } ) ;
90- }
91- } catch ( e ) {
92- terminal . red ( e ) ;
93- process . exit ( 1 ) ;
94- }
95-
96- const validProjects = packages . filter ( ( pkg ) => validateProject ( pkg ) ) ;
97-
98- if ( ! quiet ) {
99- const invalidProjects = packages . filter ( ( pkg ) => ! validateProject ( pkg ) ) ;
100- invalidProjects . map ( ( invalidProject ) =>
101- terminal . red ( `[${ invalidProject . relativePath } ] no entrypoints\n` ) ,
102- ) ;
103- }
104-
105- if ( validProjects . length === 0 ) {
106- terminal . red ( `Error: No projects found\n` ) ;
107- process . exit ( 1 ) ;
108- }
10957
110- terminal ( 'Processing the following projects:\n' ) ;
111- validProjects . forEach ( ( pkg ) => {
112- terminal . defaultColor ( ` * %s ` , pkg . name ) . dim ( `[%s]\n` , pkg . relativePath ) ;
58+ const packages = await getPackagesForCommand ( {
59+ projects ,
60+ site ,
11361 } ) ;
114- terminal ( '\n' ) ;
11562
11663 spinner . start ( 'Building webpack configs.\n' ) ;
11764
118- const configMap = validProjects . map ( ( packageObject ) => {
65+ const configMap = packages . map ( ( packageObject ) => {
11966 // Empty array means all entrypoints.
12067 let filteredEntrypoints = [ ] ;
12168
0 commit comments