@@ -5,7 +5,6 @@ const getAllFiles = require('./getAllFiles.js');
55const constants = require ( '../constants.js' ) ;
66
77const local = path . join ( constants . META_DIR , constants . META_LOCAL ) ;
8- const remote = path . join ( constants . META_DIR , constants . META_REMOTE ) ;
98
109/**
1110 * Getting the json form of a file.
@@ -20,7 +19,7 @@ function getFileJSON(file, nameWithoutExtension, extension) {
2019 fs . stat ( file , ( err , stats ) => {
2120 if ( stats . isFile ( ) ) {
2221 // Read local javascript file
23- fs . readFile ( file , 'utf8' , ( err , content ) => {
22+ fs . readFile ( file , 'utf8' , ( err , source ) => {
2423 if ( err ) {
2524 reject ( err ) ;
2625 return ;
@@ -30,7 +29,7 @@ function getFileJSON(file, nameWithoutExtension, extension) {
3029 const fileJSON = {
3130 name : nameWithoutExtension ,
3231 type,
33- source : content ,
32+ source,
3433 } ;
3534 resolve ( fileJSON ) ;
3635 return ;
@@ -53,20 +52,29 @@ function packLocal() {
5352 return new Promise ( ( resolve , reject ) => {
5453 const files = getAllFiles ( '.' ) ;
5554 const promises = [ ] ;
55+ const filenames = [ ] ;
56+
5657 for ( const file of files ) {
5758 const extension = path . parse ( file ) . ext ;
5859 const nameWithoutExtension = path . parse ( file ) . name ;
59- const folder = path . parse ( file ) . dir
60+ const folder = path . parse ( file ) . dir ;
6061
6162 // If extension is correct and file does not start with a dot
6263 if ( ( extension === '.js' || extension === '.html' ) && ( file [ 0 ] !== '.' ) ) {
6364 const filename = path . join ( folder , nameWithoutExtension ) . replace ( `\\` , `/` ) ;
64- promises . push ( getFileJSON ( file , filename , extension ) ) ;
65+ if ( filenames . includes ( filename ) ) {
66+ reject ( `Can't construct a Google Apps Script project with files with the same name: '${ filename } .*'` ) ;
67+ return ;
68+ } else {
69+ filenames . push ( filename ) ;
70+ promises . push ( getFileJSON ( file , filename , extension ) ) ;
71+ }
72+
6573 }
6674 }
6775
6876 // Reject if there are no correct files
69- if ( promises . length === 0 ) {
77+ if ( filenames . length === 0 ) {
7078 reject ( `Can't construct a Google Apps Script project without .js or .html files.` ) ;
7179 return ;
7280 }
0 commit comments