Fix broken rondo add script
fs.copyFileSync used to do mkdir, but apparently does not
This commit is contained in:
parent
8449416366
commit
a59b9032a9
@ -3,13 +3,17 @@ import * as log from '../log'
|
|||||||
import * as path from 'path'
|
import * as path from 'path'
|
||||||
import {argparse, arg} from '@rondo.dev/argparse'
|
import {argparse, arg} from '@rondo.dev/argparse'
|
||||||
|
|
||||||
|
function isDirectory(filename: string) {
|
||||||
|
const stat = fs.statSync(filename)
|
||||||
|
return stat.isDirectory()
|
||||||
|
}
|
||||||
|
|
||||||
async function walk(
|
async function walk(
|
||||||
file: string,
|
file: string,
|
||||||
files: string[] = [],
|
files: string[] = [],
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
files.push(file)
|
files.push(file)
|
||||||
const stat = fs.statSync(file)
|
if (isDirectory(file)) {
|
||||||
if (stat.isDirectory()) {
|
|
||||||
for (const f of fs.readdirSync(file)) {
|
for (const f of fs.readdirSync(file)) {
|
||||||
walk(path.join(file, f), files)
|
walk(path.join(file, f), files)
|
||||||
}
|
}
|
||||||
@ -36,9 +40,6 @@ export async function add(...argv: string[]) {
|
|||||||
|
|
||||||
const destDir = path.join('./packages', args.name)
|
const destDir = path.join('./packages', args.name)
|
||||||
|
|
||||||
log.info('mkdir %s', destDir)
|
|
||||||
fs.mkdirSync(destDir)
|
|
||||||
|
|
||||||
const libraryName = `${args.namespace}/${args.name}`
|
const libraryName = `${args.namespace}/${args.name}`
|
||||||
|
|
||||||
const templateDir = args.template
|
const templateDir = args.template
|
||||||
@ -46,15 +47,20 @@ export async function add(...argv: string[]) {
|
|||||||
const src = file
|
const src = file
|
||||||
const dest = path.join(destDir, path.relative(templateDir, file))
|
const dest = path.join(destDir, path.relative(templateDir, file))
|
||||||
if (dest === path.join(destDir, 'package.json')) {
|
if (dest === path.join(destDir, 'package.json')) {
|
||||||
log.info('Add %s', dest)
|
log.info('add %s', dest)
|
||||||
const libPkg = JSON.parse(fs.readFileSync(src, 'utf8'))
|
const libPkg = JSON.parse(fs.readFileSync(src, 'utf8'))
|
||||||
libPkg.name = libraryName
|
libPkg.name = libraryName
|
||||||
fs.writeFileSync(dest, JSON.stringify(libPkg, null, ' '))
|
fs.writeFileSync(dest, JSON.stringify(libPkg, null, ' '))
|
||||||
} else {
|
} else {
|
||||||
log.info('Copy %s', src)
|
if (isDirectory(src)) {
|
||||||
|
log.info('mkdir %s', src)
|
||||||
|
fs.mkdirSync(dest)
|
||||||
|
} else {
|
||||||
|
log.info('copy %s', src)
|
||||||
fs.copyFileSync(src, dest)
|
fs.copyFileSync(src, dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.info('Update main package.json')
|
log.info('Update main package.json')
|
||||||
const pkgFile = path.join(process.cwd(), 'package.json')
|
const pkgFile = path.join(process.cwd(), 'package.json')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user