fix: creation apps

This commit is contained in:
cha0s 2024-01-20 04:59:13 -06:00
parent 919759f691
commit 9bfa481731
9 changed files with 37 additions and 36 deletions

View File

@ -11,7 +11,7 @@ const {
} = process.env; } = process.env;
module.exports = async (fleck, path) => { module.exports = async (fleck, path) => {
const key = [fleck].concat(path ? `.${sep}${join('packages', path, 'src')}` : []).join(':'); const key = [fleck].concat(path ? `.${sep}${join('packages', path)}` : []).join(':');
const ymlPath = join(FLECKS_CORE_ROOT, 'build', 'flecks.yml'); const ymlPath = join(FLECKS_CORE_ROOT, 'build', 'flecks.yml');
let yml = loadYml(await readFile(ymlPath)); let yml = loadYml(await readFile(ymlPath));
yml = Object.fromEntries(Object.entries(yml).concat([[key, {}]])); yml = Object.fromEntries(Object.entries(yml).concat([[key, {}]]));

View File

@ -1,6 +1,6 @@
import {processCode, spawnWith} from '@flecks/core/server'; const {processCode, spawnWith} = require('@flecks/core/build/commands');
export default async (packageManager, cwd) => { module.exports = async (packageManager, cwd) => {
const code = await processCode(spawnWith([packageManager, 'install'], {cwd})); const code = await processCode(spawnWith([packageManager, 'install'], {cwd}));
if (0 !== code) { if (0 !== code) {
return code; return code;

View File

@ -1,18 +1,20 @@
#!/usr/bin/env node #!/usr/bin/env node
import {join} from 'path'; const {join} = require('path');
import { const {
dumpYml,
loadYml,
Option, Option,
program, program,
} = require('@flecks/core/build/commands');
const {
dumpYml,
loadYml,
transform, transform,
} from '@flecks/core/server'; } = require('@flecks/core/server');
import validate from 'validate-npm-package-name'; const validate = require('validate-npm-package-name');
import build from './build'; const build = require('./build');
import move, {testDestination} from './move'; const {move, testDestination} = require('./move');
const { const {
FLECKS_CORE_ROOT = process.cwd(), FLECKS_CORE_ROOT = process.cwd(),
@ -40,15 +42,15 @@ const {
error.code = 129; error.code = 129;
throw error; throw error;
} }
const fileTree = await move(name, join(__dirname, 'template')); const fileTree = await move(name, join(__dirname, '..', 'template'));
fileTree.pipe( fileTree.pipe(
'build/flecks.yml', 'build/flecks.yml',
transform((chunk, encoding, done, stream) => { transform((chunk, encoding, done, stream) => {
const yml = loadYml(chunk); const yml = loadYml(chunk);
if ('npm' !== packageManager) {
yml['@flecks/core/server'] = {packageManager};
}
yml['@flecks/core'] = {id: app}; yml['@flecks/core'] = {id: app};
if ('npm' !== packageManager) {
yml['@flecks/core'].packageManager = packageManager;
}
stream.push(dumpYml(yml, {forceQuotes: true, sortKeys: true})); stream.push(dumpYml(yml, {forceQuotes: true, sortKeys: true}));
done(); done();
}), }),

View File

@ -1,11 +1,11 @@
import {stat} from 'fs/promises'; const {stat} = require('fs/promises');
import {basename, dirname, join} from 'path'; const {basename, dirname, join} = require('path');
import {JsonStream, transform} from '@flecks/core/server'; const {JsonStream, transform} = require('@flecks/core/server');
import FileTree from './tree'; const FileTree = require('./tree');
export const testDestination = async (destination) => { exports.testDestination = async (destination) => {
try { try {
await stat(destination); await stat(destination);
return false; return false;
@ -18,7 +18,7 @@ export const testDestination = async (destination) => {
} }
}; };
export default async (name, source) => { exports.move = async (name, source) => {
const fileTree = await FileTree.loadFrom(source); const fileTree = await FileTree.loadFrom(source);
// Renamed to avoid conflicts. // Renamed to avoid conflicts.
const {files} = fileTree; const {files} = fileTree;

View File

@ -1,11 +1,11 @@
import {createReadStream, createWriteStream} from 'fs'; const {createReadStream, createWriteStream} = require('fs');
import {mkdir, stat} from 'fs/promises'; const {mkdir, stat} = require('fs/promises');
import {glob} from '@flecks/core/server'; const {glob} = require('@flecks/core/server');
import minimatch from 'minimatch'; const minimatch = require('minimatch');
import {dirname, join} from 'path'; const {dirname, join} = require('path');
export default class FileTree { module.exports = class FileTree {
constructor(files = {}) { constructor(files = {}) {
this.files = files; this.files = files;
@ -63,4 +63,4 @@ export default class FileTree {
); );
} }
} };

View File

@ -10,7 +10,7 @@
}, },
"version": "3.0.0", "version": "3.0.0",
"bin": { "bin": {
"create-app": "./cli.js" "create-app": "./build/cli.js"
}, },
"scripts": { "scripts": {
"build": "flecks build", "build": "flecks build",
@ -20,7 +20,6 @@
"test": "flecks test" "test": "flecks test"
}, },
"files": [ "files": [
"cli.js",
"server.js", "server.js",
"template" "template"
], ],

View File

@ -4,10 +4,10 @@ const {stat} = require('fs/promises');
const {join} = require('path'); const {join} = require('path');
const addFleckToYml = require('@flecks/core/build/add-fleck-to-yml'); const addFleckToYml = require('@flecks/core/build/add-fleck-to-yml');
const {Server, program} = require('@flecks/core/server'); const {program} = require('@flecks/core/build/commands');
const Server = require('@flecks/core/build/server');
const build = require('@flecks/create-app/build/build'); const build = require('@flecks/create-app/build/build');
const move = require('@flecks/create-app/build/move'); const {move, testDestination} = require('@flecks/create-app/build/move');
const testDestination = require('@flecks/create-app/build/testDestination');
const {validate} = require('@flecks/create-app/server'); const {validate} = require('@flecks/create-app/server');
const { const {
@ -29,7 +29,7 @@ const checkIsMonorepo = async () => {
const monorepoScope = async () => { const monorepoScope = async () => {
try { try {
const {name} = __non_webpack_require__(join(FLECKS_CORE_ROOT, 'package.json')); const {name} = require(join(FLECKS_CORE_ROOT, 'package.json'));
const [scope] = name.split('/'); const [scope] = name.split('/');
return scope; return scope;
} }
@ -82,7 +82,7 @@ const target = async (fleck) => {
error.code = 129; error.code = 129;
throw error; throw error;
} }
const fileTree = await move(name, join(__dirname, 'template')); const fileTree = await move(name, join(__dirname, '..', 'template'));
// Write the tree. // Write the tree.
await fileTree.writeTo(destination); await fileTree.writeTo(destination);
await build(packageManager, destination); await build(packageManager, destination);

View File

@ -10,7 +10,7 @@
}, },
"version": "3.0.0", "version": "3.0.0",
"bin": { "bin": {
"create-fleck": "./cli.js" "create-fleck": "./build/cli.js"
}, },
"scripts": { "scripts": {
"build": "flecks build", "build": "flecks build",