-
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.
- Loading branch information
Showing
10 changed files
with
159 additions
and
109 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 |
---|---|---|
|
@@ -117,6 +117,8 @@ dist | |
|
||
# local | ||
/yarn.lock | ||
/bun.lockb | ||
|
||
# package-locals | ||
/packages/*/yarn.lock | ||
/packages/*/bun.lockb |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import {processCode, spawnWith} from '@flecks/core/server'; | ||
|
||
export default async (cwd) => { | ||
const code = await processCode(spawnWith(['yarn'], {cwd})); | ||
export default async (packageManager, cwd) => { | ||
const code = await processCode(spawnWith([packageManager, 'install'], {cwd})); | ||
if (0 !== code) { | ||
return code; | ||
} | ||
return processCode(spawnWith(['yarn', 'build'], {cwd})); | ||
return processCode(spawnWith([packageManager, 'run', 'build'], {cwd})); | ||
}; |
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,39 +1,72 @@ | ||
import {join, normalize} from 'path'; | ||
import {join} from 'path'; | ||
|
||
import {Flecks} from '@flecks/core/server'; | ||
import { | ||
dumpYml, | ||
Flecks, | ||
loadYml, | ||
Option, | ||
program, | ||
transform, | ||
} from '@flecks/core/server'; | ||
import validate from 'validate-npm-package-name'; | ||
|
||
import build from './build'; | ||
import move from './move'; | ||
import move, {testDestination} from './move'; | ||
|
||
const { | ||
FLECKS_CORE_ROOT = process.cwd(), | ||
} = process.env; | ||
|
||
const cwd = normalize(FLECKS_CORE_ROOT); | ||
|
||
const create = async (flecks) => { | ||
let name = process.argv[2]; | ||
const {errors} = validate(name); | ||
if (errors) { | ||
throw new Error(`@flecks/create-app: invalid app name: ${errors.join(', ')}`); | ||
} | ||
const destination = join(cwd, name); | ||
if (!name.startsWith('@')) { | ||
name = `@${name}/monorepo`; | ||
} | ||
await move(name, join(__dirname, 'template'), destination, 'app', flecks); | ||
await build(destination); | ||
}; | ||
|
||
(async () => { | ||
const flecks = await Flecks.bootstrap(); | ||
try { | ||
await create(flecks); | ||
} | ||
catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error.message); | ||
process.exitCode = 1; | ||
} | ||
program.argument('<app>', 'name of the app to create'); | ||
program.addOption( | ||
new Option('--package-manager <binary>', 'package manager binary') | ||
.choices(['npm', 'bun', 'yarn']) | ||
.default('npm'), | ||
); | ||
program.action(async (app, {packageManager}) => { | ||
const flecks = await Flecks.bootstrap({ | ||
config: { | ||
'@flecks/core': {}, | ||
'@flecks/core/server': {packageManager}, | ||
'@flecks/create-app': {}, | ||
'@flecks/fleck': {}, | ||
}, | ||
}); | ||
try { | ||
const {errors} = validate(app); | ||
if (errors) { | ||
throw new Error(`@flecks/create-app: invalid app name: ${errors.join(', ')}`); | ||
} | ||
const destination = join(FLECKS_CORE_ROOT, app); | ||
if (!app.startsWith('@')) { | ||
app = `@${app}/monorepo`; | ||
} | ||
if (!await testDestination(destination)) { | ||
const error = new Error( | ||
`@flecks/create-app: destination '${destination} already exists: aborting`, | ||
); | ||
error.code = 129; | ||
throw error; | ||
} | ||
const fileTree = await move(app, join(__dirname, 'template'), 'app', flecks); | ||
fileTree.pipe( | ||
'build/flecks.yml', | ||
transform((chunk, encoding, done, stream) => { | ||
const yml = loadYml(chunk); | ||
yml['@flecks/core/server'] = {packageManager}; | ||
stream.push(dumpYml(yml, {sortKeys: true})); | ||
done(); | ||
}), | ||
); | ||
// Write the tree. | ||
await fileTree.writeTo(destination); | ||
await build(packageManager, destination); | ||
} | ||
catch (error) { | ||
// eslint-disable-next-line no-console | ||
console.error(error); | ||
} | ||
}); | ||
await program.parseAsync(process.argv); | ||
})(); |
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,5 +1,5 @@ | ||
export {default as validate} from 'validate-npm-package-name'; | ||
|
||
export {default as build} from './build'; | ||
export {default as move} from './move'; | ||
export {default as move, testDestination} from './move'; | ||
export {default as FileTree} from './tree'; |
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
Oops, something went wrong.