-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-builder): update copy command
- Loading branch information
1 parent
324e13d
commit b983220
Showing
11 changed files
with
154 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,49 @@ | ||
import {PdkBuilderCommand} from '../types'; | ||
import debug from 'debug'; | ||
import chalk from 'chalk'; | ||
import createDebug from 'debug'; | ||
import fs from 'fs'; | ||
import glob from 'fast-glob'; | ||
import path from 'path'; | ||
|
||
const log = debug('pdk:copy'); | ||
const debug = createDebug('pdk-builder:copy'); | ||
|
||
export const copy: PdkBuilderCommand = async ({env, config}) => { | ||
const files = glob.sync(config.source); | ||
export const copy: PdkBuilderCommand = async ({env, config, args}) => { | ||
debug.enabled = Boolean(args.debug ?? config.debug); | ||
|
||
debug( | ||
'Copying files from %s to %s for platforms %s', | ||
chalk.yellow(config.source), | ||
chalk.cyan(config.distFolder), | ||
chalk.cyanBright(config.platforms.join(', ')), | ||
); | ||
|
||
console.log({files, config: config}); | ||
if (args.dryRun) { | ||
debug('Dry run is enabled, not actually copying files'); | ||
} | ||
|
||
const files = glob.sync(config.source); | ||
|
||
await Promise.all( | ||
files.map(async (file) => { | ||
const source = path.resolve(env.cwd, file); | ||
const target = path.resolve(env.cwd, config.distFolder, file); | ||
config.platforms.map(async (platform) => { | ||
debug('Copying %s files to %s', chalk.cyan(platform), chalk.cyanBright(platform)); | ||
|
||
return Promise.all( | ||
files.map(async (file) => { | ||
const source = path.resolve(env.cwd, file); | ||
const target = path.resolve(env.cwd, config.distFolder, platform, file); | ||
|
||
log('Copying %s to %s', source, target); | ||
debug( | ||
'%s -> %s', | ||
chalk.yellow(path.relative(env.cwd, file)), | ||
chalk.cyan(path.relative(env.cwd, [config.distFolder, platform, file].join(path.sep))), | ||
); | ||
|
||
await fs.promises.copyFile(source, target); | ||
if (!args.dryRun) { | ||
await fs.promises.mkdir(path.dirname(target), {recursive: true}); | ||
await fs.promises.copyFile(source, target); | ||
} | ||
}), | ||
); | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,44 @@ | ||
export const zip = async (...args: any[]): Promise<void> => {}; | ||
import AdmZip from 'adm-zip'; | ||
import {PdkBuilderCommand} from '../types'; | ||
import chalk from 'chalk'; | ||
import createDebug from 'debug'; | ||
import glob from 'fast-glob'; | ||
import path from 'path'; | ||
import {resolveFileName} from '../utils/resolveFileName'; | ||
|
||
const debug = createDebug('pdk-builder:zip'); | ||
|
||
export const zip: PdkBuilderCommand = async ({env, config, args}) => { | ||
debug.enabled = Boolean(args.debug ?? config.debug); | ||
|
||
debug('Zipping files for platforms %s', chalk.cyanBright(config.platforms.join(', '))); | ||
|
||
if (args.dryRun) { | ||
debug('Dry run is enabled, not actually making zips'); | ||
} | ||
|
||
await Promise.all( | ||
config.platforms.map(async (platform) => { | ||
debug('Zipping %s files', chalk.cyan(platform)); | ||
|
||
const zipFile = resolveFileName(config.zipFileName, config, platform); | ||
|
||
return Promise.all( | ||
// eslint-disable-next-line @typescript-eslint/require-await | ||
glob.sync('./**/*', {cwd: path.resolve(config.distFolder, platform)}).map(async (file) => { | ||
const target = path.resolve(env.cwd, config.distFolder, platform, file); | ||
|
||
console.log(target); | ||
|
||
if (!args.dryRun) { | ||
const zip = new AdmZip(); | ||
|
||
zip.addLocalFile(target); | ||
|
||
zip.writeZip(zipFile); | ||
} | ||
}), | ||
); | ||
}), | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import {PdkBuilderConfig} from '../types'; | ||
|
||
export const resolveFileName = (filename: string, config: PdkBuilderConfig, platform?: string): string => | ||
filename | ||
.replace(':platform', platform ?? '') | ||
.replace(':name', config.name) | ||
.replace(':version', config.version); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import child_process from 'child_process'; | ||
|
||
export const spawnPromise = (command: string, args: string[], options: child_process.SpawnOptions): Promise<void> => { | ||
return new Promise((resolve, reject) => { | ||
const child = child_process.spawn(command, args, options); | ||
|
||
child.on('error', reject); | ||
child.on('close', resolve); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters