@@ -50,67 +50,6 @@ function collectUnusedDependencies(pathToProject = process.cwd()) {
5050 } ) ;
5151}
5252
53- /**
54- * `pathToZip` is a `path/to/your/app-name.zip`.
55- * If the `pathToZip` archive does not have a root directory with name `app-name`, it creates one, and move the content from the
56- * archive's root to the new root folder. If the archive already has the desired root folder, calling this function is a NOOP.
57- * If `pathToZip` is not a ZIP, rejects. `targetFolderName` is the destination folder not the new archive location.
58- */
59- function adjustArchiveStructure ( pathToZip , targetFolderName , noCleanup ) {
60- return new Promise ( async ( resolve , reject ) => {
61- if ( ! ( await isZip ( pathToZip ) ) ) {
62- reject ( new Error ( `Expected a ZIP file.` ) ) ;
63- return ;
64- }
65- if ( ! fs . existsSync ( targetFolderName ) ) {
66- reject ( new Error ( `${ targetFolderName } does not exist.` ) ) ;
67- return ;
68- }
69- if ( ! fs . lstatSync ( targetFolderName ) . isDirectory ( ) ) {
70- reject ( new Error ( `${ targetFolderName } is not a directory.` ) ) ;
71- return ;
72- }
73- console . log ( `⏱️ >>> Adjusting ZIP structure ${ pathToZip } ...` ) ;
74-
75- const root = basename ( pathToZip ) ;
76- const resources = await list ( pathToZip ) ;
77- const hasBaseFolder = resources . find ( ( name ) => name === root ) ;
78- if ( hasBaseFolder ) {
79- if (
80- resources . filter ( ( name ) => name . indexOf ( path . sep ) === - 1 ) . length > 1
81- ) {
82- console . warn (
83- `${ pathToZip } ZIP has the desired root folder ${ root } , however the ZIP contains other entries too: ${ JSON . stringify (
84- resources
85- ) } `
86- ) ;
87- }
88- console . log ( `👌 <<< The ZIP already has the desired ${ root } folder.` ) ;
89- resolve ( pathToZip ) ;
90- return ;
91- }
92-
93- const track = temp . track ( ) ;
94- try {
95- const unzipOut = path . join ( track . mkdirSync ( ) , root ) ;
96- fs . mkdirSync ( unzipOut ) ;
97- await unpack ( pathToZip , unzipOut ) ;
98- const adjustedZip = path . join ( targetFolderName , path . basename ( pathToZip ) ) ;
99- await pack ( unzipOut , adjustedZip ) ;
100- console . log (
101- `👌 <<< Adjusted the ZIP structure. Moved the modified ${ basename (
102- pathToZip
103- ) } to the ${ targetFolderName } folder.`
104- ) ;
105- resolve ( adjustedZip ) ;
106- } finally {
107- if ( ! noCleanup ) {
108- track . cleanupSync ( ) ;
109- }
110- }
111- } ) ;
112- }
113-
11453/**
11554 * Returns the `basename` of `pathToFile` without the file extension.
11655 */
@@ -213,7 +152,6 @@ function getChannelFile(platform) {
213152
214153module . exports = {
215154 collectUnusedDependencies,
216- adjustArchiveStructure,
217155 isZip,
218156 unpack,
219157 isNightly,
0 commit comments