Skip to content

Commit

Permalink
fix: creation apps
Browse files Browse the repository at this point in the history
  • Loading branch information
cha0s committed Jan 20, 2024
1 parent 919759f commit 9bfa481
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion packages/core/build/add-fleck-to-yml.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
} = process.env;

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');
let yml = loadYml(await readFile(ymlPath));
yml = Object.fromEntries(Object.entries(yml).concat([[key, {}]]));
Expand Down
4 changes: 2 additions & 2 deletions packages/create-app/build/build.js
Original file line number Diff line number Diff line change
@@ -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}));
if (0 !== code) {
return code;
Expand Down
24 changes: 13 additions & 11 deletions packages/create-app/build/cli.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
#!/usr/bin/env node

import {join} from 'path';
const {join} = require('path');

import {
dumpYml,
loadYml,
const {
Option,
program,
} = require('@flecks/core/build/commands');
const {
dumpYml,
loadYml,
transform,
} from '@flecks/core/server';
import validate from 'validate-npm-package-name';
} = require('@flecks/core/server');
const validate = require('validate-npm-package-name');

import build from './build';
import move, {testDestination} from './move';
const build = require('./build');
const {move, testDestination} = require('./move');

const {
FLECKS_CORE_ROOT = process.cwd(),
Expand Down Expand Up @@ -40,15 +42,15 @@ const {
error.code = 129;
throw error;
}
const fileTree = await move(name, join(__dirname, 'template'));
const fileTree = await move(name, join(__dirname, '..', 'template'));
fileTree.pipe(
'build/flecks.yml',
transform((chunk, encoding, done, stream) => {
const yml = loadYml(chunk);
yml['@flecks/core'] = {id: app};
if ('npm' !== packageManager) {
yml['@flecks/core/server'] = {packageManager};
yml['@flecks/core'].packageManager = packageManager;
}
yml['@flecks/core'] = {id: app};
stream.push(dumpYml(yml, {forceQuotes: true, sortKeys: true}));
done();
}),
Expand Down
12 changes: 6 additions & 6 deletions packages/create-app/build/move.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {stat} from 'fs/promises';
import {basename, dirname, join} from 'path';
const {stat} = require('fs/promises');
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 {
await stat(destination);
return false;
Expand All @@ -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);
// Renamed to avoid conflicts.
const {files} = fileTree;
Expand Down
14 changes: 7 additions & 7 deletions packages/create-app/build/tree.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {createReadStream, createWriteStream} from 'fs';
import {mkdir, stat} from 'fs/promises';
const {createReadStream, createWriteStream} = require('fs');
const {mkdir, stat} = require('fs/promises');

import {glob} from '@flecks/core/server';
import minimatch from 'minimatch';
import {dirname, join} from 'path';
const {glob} = require('@flecks/core/server');
const minimatch = require('minimatch');
const {dirname, join} = require('path');

export default class FileTree {
module.exports = class FileTree {

constructor(files = {}) {
this.files = files;
Expand Down Expand Up @@ -63,4 +63,4 @@ export default class FileTree {
);
}

}
};
3 changes: 1 addition & 2 deletions packages/create-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"version": "3.0.0",
"bin": {
"create-app": "./cli.js"
"create-app": "./build/cli.js"
},
"scripts": {
"build": "flecks build",
Expand All @@ -20,7 +20,6 @@
"test": "flecks test"
},
"files": [
"cli.js",
"server.js",
"template"
],
Expand Down
10 changes: 5 additions & 5 deletions packages/create-fleck/build/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const {stat} = require('fs/promises');
const {join} = require('path');

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 move = require('@flecks/create-app/build/move');
const testDestination = require('@flecks/create-app/build/testDestination');
const {move, testDestination} = require('@flecks/create-app/build/move');
const {validate} = require('@flecks/create-app/server');

const {
Expand All @@ -29,7 +29,7 @@ const checkIsMonorepo = async () => {

const monorepoScope = async () => {
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('/');
return scope;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ const target = async (fleck) => {
error.code = 129;
throw error;
}
const fileTree = await move(name, join(__dirname, 'template'));
const fileTree = await move(name, join(__dirname, '..', 'template'));
// Write the tree.
await fileTree.writeTo(destination);
await build(packageManager, destination);
Expand Down
2 changes: 1 addition & 1 deletion packages/create-fleck/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"version": "3.0.0",
"bin": {
"create-fleck": "./cli.js"
"create-fleck": "./build/cli.js"
},
"scripts": {
"build": "flecks build",
Expand Down
Empty file.

0 comments on commit 9bfa481

Please sign in to comment.