-
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.
feat(app-builder): finalize clean, copy and zip scripts
- Loading branch information
1 parent
3f850c6
commit e9be04f
Showing
23 changed files
with
538 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/usr/bin/env node | ||
import('../dist/main.js'); |
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,30 @@ | ||
import {PdkBuilderCommand} from '../types'; | ||
import chalk from 'chalk'; | ||
import {createDebugger} from '../utils/createDebugger'; | ||
import {exists} from '../utils/exists'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {reportDryRun} from '../utils/reportDryRun'; | ||
|
||
export const clean: PdkBuilderCommand = async ({env, config, args}) => { | ||
const debug = createDebugger('clean'); | ||
|
||
if (args.dryRun) reportDryRun(debug, 'No files will be deleted.'); | ||
|
||
const dist = path.resolve(env.cwd, config.outDir); | ||
|
||
const relativePath = path.relative(env.cwd, config.outDir); | ||
|
||
if (!(await exists(dist))) { | ||
debug('Dist folder %s does not exist, skipping...', chalk.greenBright(relativePath)); | ||
return; | ||
} | ||
|
||
debug('Deleting %s folder', chalk.cyan(path.relative(env.cwd, config.outDir))); | ||
|
||
if (!args.dryRun) { | ||
await fs.promises.rm(dist, {recursive: true, force: true}); | ||
} | ||
|
||
debug('Done'); | ||
}; |
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,45 @@ | ||
import {PdkBuilderCommand} from '../types'; | ||
import chalk from 'chalk'; | ||
import {createArchive} from '../utils/createArchive'; | ||
import {createDebugger} from '../utils/createDebugger'; | ||
import {exists} from '../utils/exists'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import {reportDryRun} from '../utils/reportDryRun'; | ||
import {resolveFileName} from '../utils/resolveFileName'; | ||
|
||
export const compress: PdkBuilderCommand = async ({env, config, args}) => { | ||
const debug = createDebugger('compress'); | ||
|
||
if (args.dryRun) reportDryRun(debug, 'No archive will be created.'); | ||
|
||
debug('Compressing files for platforms %s', chalk.cyanBright(config.platforms.join(', '))); | ||
|
||
await Promise.all( | ||
config.platforms.map(async (platform) => { | ||
const archiveFilename = resolveFileName(config.archiveFilename, config, platform); | ||
const platformFolderName = resolveFileName(config.platformFolderName, config, platform); | ||
const platformDistPath = path.resolve(env.cwd, config.outDir, platformFolderName); | ||
|
||
if (!(await exists(platformDistPath))) { | ||
throw new Error(`Platform dist folder ${platformDistPath} does not exist. Run the "copy" command first.`); | ||
} | ||
|
||
const archivePath = path.resolve(env.cwd, config.outDir, archiveFilename); | ||
|
||
if (await exists(archivePath)) { | ||
debug('Removing existing file %s...', chalk.greenBright(path.relative(env.cwd, archivePath))); | ||
await fs.promises.rm(archivePath); | ||
} | ||
|
||
const archive = createArchive(archivePath, debug); | ||
|
||
debug('Compressing %s...', chalk.greenBright(path.relative(env.cwd, platformDistPath))); | ||
archive.directory(platformDistPath, platformFolderName); | ||
|
||
await archive.finalize(); | ||
}), | ||
); | ||
|
||
debug('Done'); | ||
}; |
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,49 +1,59 @@ | ||
import {PdkBuilderCommand} from '../types'; | ||
import {PdkBuilderCommand, Verbosity} from '../types'; | ||
import chalk from 'chalk'; | ||
import createDebug from 'debug'; | ||
import {createDebugger} from '../utils/createDebugger'; | ||
import fs from 'fs'; | ||
import glob from 'fast-glob'; | ||
import path from 'path'; | ||
|
||
const debug = createDebug('pdk-builder:copy'); | ||
import {reportDryRun} from '../utils/reportDryRun'; | ||
import {resolveFileName} from '../utils/resolveFileName'; | ||
|
||
export const copy: PdkBuilderCommand = async ({env, config, args}) => { | ||
debug.enabled = Boolean(args.debug ?? config.debug); | ||
const debug = createDebugger(`copy`); | ||
|
||
if (args.dryRun) reportDryRun(debug, 'No files will be copied.'); | ||
|
||
const files = glob.sync(config.source); | ||
|
||
debug( | ||
'Copying files from %s to %s for platforms %s', | ||
'Copying %s files from %s to %s for output "%s"', | ||
chalk.greenBright(files.length), | ||
chalk.yellow(config.source), | ||
chalk.cyan(config.distFolder), | ||
chalk.cyan(path.relative(env.cwd, config.outDir)), | ||
chalk.cyanBright(config.platforms.join(', ')), | ||
); | ||
|
||
if (args.dryRun) { | ||
debug('Dry run is enabled, not actually copying files'); | ||
} | ||
|
||
const files = glob.sync(config.source); | ||
|
||
await Promise.all( | ||
config.platforms.map(async (platform) => { | ||
debug('Copying %s files to %s', chalk.cyan(platform), chalk.cyanBright(platform)); | ||
const platformFolderPath = `${config.outDir}/${resolveFileName(config.platformFolderName, config, platform)}`; | ||
const relativeDistFolderPath = path.relative(env.cwd, platformFolderPath); | ||
|
||
return Promise.all( | ||
debug('Copying files to %s', chalk.greenBright(relativeDistFolderPath)); | ||
|
||
const promises = await Promise.all( | ||
files.map(async (file) => { | ||
const source = path.resolve(env.cwd, file); | ||
const target = path.resolve(env.cwd, config.distFolder, platform, file); | ||
|
||
debug( | ||
'%s -> %s', | ||
chalk.yellow(path.relative(env.cwd, file)), | ||
chalk.cyan(path.relative(env.cwd, [config.distFolder, platform, file].join(path.sep))), | ||
); | ||
const target = path.resolve(env.cwd, platformFolderPath, file); | ||
|
||
if (args.verbose >= Verbosity.VERY_VERY_VERBOSE) { | ||
debug( | ||
'%s -> %s', | ||
chalk.yellow(path.relative(env.cwd, file)), | ||
chalk.cyan(path.relative(env.cwd, [platformFolderPath, file].join(path.sep))), | ||
); | ||
} | ||
|
||
if (!args.dryRun) { | ||
await fs.promises.mkdir(path.dirname(target), {recursive: true}); | ||
await fs.promises.copyFile(source, target); | ||
} | ||
}), | ||
); | ||
|
||
debug('Finished copying files to %s', chalk.greenBright(relativeDistFolderPath)); | ||
|
||
return promises; | ||
}), | ||
); | ||
|
||
debug('Done'); | ||
}; |
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,3 +1,3 @@ | ||
export * from './zip'; | ||
export * from './compress'; | ||
export * from './copy'; | ||
export * from './rename'; |
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 +1,16 @@ | ||
export const rename = async (...args: any[]): Promise<void> => {}; | ||
import {PdkBuilderCommand} from '../types'; | ||
import chalk from 'chalk'; | ||
import {createDebugger} from '../utils/createDebugger'; | ||
import {reportDryRun} from '../utils/reportDryRun'; | ||
|
||
export const rename: PdkBuilderCommand = async ({env, config, args}) => { | ||
const debug = createDebugger('rename'); | ||
|
||
if (args.dryRun) reportDryRun(debug, 'No files will be renamed.'); | ||
|
||
debug('Renaming files for platforms %s', chalk.cyanBright(config.platforms.join(', '))); | ||
|
||
debug(chalk.red('(Not actually doing anything, this is not implemented yet.)')); | ||
|
||
debug('Done'); | ||
}; |
This file was deleted.
Oops, something went wrong.
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,5 +1,3 @@ | ||
import {start} from './start'; | ||
export type {PdkBuilderConfig, PdkBuilderContext} from './types'; | ||
|
||
export type {PdkBuilderConfig} from './types'; | ||
|
||
start(); | ||
export {start as pdkBuilder} from './start'; |
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,3 @@ | ||
import {start} from './start'; | ||
|
||
start(); |
Oops, something went wrong.