Skip to content

Commit

Permalink
Merge pull request #135 from theodo-group/update
Browse files Browse the repository at this point in the history
✨ Upgrade create bifrost app
  • Loading branch information
Jeremie-Chauvel authored Mar 12, 2023
2 parents ea0a9c2 + 0da92e9 commit 36d4373
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 216 deletions.
6 changes: 3 additions & 3 deletions bifrost.code-workspace
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"settings": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
Expand All @@ -25,8 +25,8 @@
"[dotenv][ignore][properties][shellscript]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"[html][javascript][json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"[html][javascript][typescript][json]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[markdown][mdx]": {
"editor.wordWrap": "on"
Expand Down
7 changes: 3 additions & 4 deletions examples/bifrost-starter/bifrost-starter.code-workspace
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"settings": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
Expand Down Expand Up @@ -29,8 +29,8 @@
"[dotenv][ignore][properties][shellscript]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"[html][javascript][json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
"[html][javascript][typescript][json]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
},
"[markdown][mdx]": {
"editor.wordWrap": "on"
Expand Down Expand Up @@ -63,7 +63,6 @@
"type": "node",
"request": "attach",
"name": "Debug: nest",
"protocol": "inspector",
"port": 9229,
"restart": true,
"skipFiles": [
Expand Down
18 changes: 17 additions & 1 deletion packages/create-bifrost-app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,25 @@ Run the following command
pnpx create bifrost-app
```

TODO
Check out [the docs](https://theodo-group.github.io/bifrost/) for more info.

## Acknowledge

Thank you to [swarmion](https://github.com/swarmion/swarmion) that inspired our work on this create package

## Contributing

Install the packages as usual with `pnpm i`. Then run:

```sh
pnpm dev
```

create a random directory to test the CLI in:

```sh
mkdir ../../sandbox
cd ../../sandbox
```

Then run the app locally, you should disable the telem
11 changes: 6 additions & 5 deletions packages/create-bifrost-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-bifrost-app",
"description": "Create an app based on the Bifrost template.",
"version": "0.0.1",
"version": "0.0.2",
"contributors": [],
"license": "MIT",
"homepage": "https://theodo-group.github.io/bifrost/",
Expand All @@ -23,7 +23,8 @@
],
"scripts": {
"build": "ncc build ./src/index.ts -o ./dist/ --minify --no-cache --no-source-map-register",
"dev": "ncc build ./src/index.ts -w -o dist/",
"dev": "ncc build ./src/indexNoTelemetry.ts -w -o dist/",
"dev:enable:telemetry": "ncc build ./src/index.ts -w -o dist/",
"lint": "eslint",
"lint:fix": "pnpm lint --fix",
"test": "pnpm test:lint && pnpm test:type && pnpm test:unit && pnpm test:circular",
Expand All @@ -36,27 +37,27 @@
},
"bin": "./dist/index.js",
"devDependencies": {
"@clack/prompts": "0.6.3",
"@types/async-retry": "1.4.5",
"@types/cross-spawn": "6.0.2",
"@types/node": "18.8.3",
"@types/prompts": "2.4.1",
"@types/rimraf": "3.0.2",
"@types/tar": "6.1.3",
"@types/validate-npm-package-name": "4.0.0",
"@vercel/ncc": "0.34.0",
"@vitest/coverage-c8": "0.24.0",
"async-retry": "1.3.3",
"babel-plugin-module-resolver": "4.1.0",
"chalk": "5.1.0",
"commander": "9.4.1",
"concurrently": "7.4.0",
"cross-spawn": "7.0.3",
"dependency-cruiser": "11.16.1",
"dependency-cruiser-config-custom": "workspace:*",
"eslint-config-custom": "workspace:*",
"got": "12.5.1",
"node-fetch": "3.3.1",
"picocolors": "1.0.0",
"prettier": "2.7.1",
"prompts": "2.4.2",
"rimraf": "3.0.2",
"tar": "4.4.19",
"ts-node": "10.9.1",
Expand Down
35 changes: 21 additions & 14 deletions packages/create-bifrost-app/src/create-app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import retry from 'async-retry';
import chalk from 'chalk';
import { execSync } from 'child_process';
import path from 'path';
import pico from 'picocolors';

import {
downloadAndExtractRepo,
Expand Down Expand Up @@ -36,7 +36,7 @@ export const createApp = async ({

if (!found) {
console.error(
`Could not locate the repository for ${chalk.red(
`Could not locate the repository for ${pico.red(
`"${example}"`,
)}. Please check that the repository exists and try again.`,
);
Expand All @@ -62,7 +62,7 @@ export const createApp = async ({
process.exit(1);
}

console.log(`Creating a new Bifrost app in ${chalk.green(root)}.`);
console.log(pico.bold(`Creating a new Bifrost app in ${pico.green(root)}.`));
console.log();

const originalDirectory = process.cwd();
Expand All @@ -73,9 +73,8 @@ export const createApp = async ({
*/
try {
console.log(
`Downloading files from repo ${chalk.cyan(
example,
)}. This might take a moment.`,
pico.bold(`Downloading files from repo ${pico.cyan(example)}.`) +
'\n This might take a moment...',
);
console.log();
await retry(() => downloadAndExtractRepo(root, repoInfo), {
Expand All @@ -96,33 +95,41 @@ export const createApp = async ({
);
}

console.log('Initializing a git repository...');
console.log(pico.bold('Initializing a git repository...'));
if (tryGitInit(root)) {
console.log();
}

console.log('Installing packages. This might take a couple of minutes.');
console.log(
`${pico.bold(
'Installing packages.',
)}\n This might take a couple of minutes...`,
);
console.log();

await install(root);

console.log();
console.log();
console.log('Linting your project...');
console.log(
pico.bold('Linting your project.') + '\n This might take a moment...',
);
console.log();
execSync(`pnpm lint:fix:all`, { stdio: 'ignore', cwd: root });

console.log();

console.log(`${chalk.green('Success!')} Created ${appName} at ${appPath}`);
console.log(
`${pico.bold(pico.green('Success 🎉'))} Created ${appName} at ${appPath}`,
);
console.log();
console.log();
console.log('Inside that directory, you can run several commands:');

console.log('change directory and launch the development server:');
console.log();
const cdpath =
path.join(originalDirectory, appName) === appPath ? appName : appPath;

console.log(chalk.cyan(' cd'), cdpath);
console.log(` ${chalk.cyan(`pnpm dev`)}`);
console.log(pico.cyan(' cd'), cdpath);
console.log(` ${pico.cyan(`pnpm dev`)}`);
console.log(' Starts the development servers for backend and frontend.');
};
1 change: 1 addition & 0 deletions packages/create-bifrost-app/src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './is-writeable';
export * from './make-dir';
export * from './renameProject';
export * from './validate-pkg';
export * from './telemetry';
6 changes: 3 additions & 3 deletions packages/create-bifrost-app/src/helpers/is-folder-empty.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk';
import fs from 'fs';
import path from 'path';
import pico from 'picocolors';

export const isFolderEmpty = (root: string, name: string): boolean => {
const validFiles = [
Expand Down Expand Up @@ -32,14 +32,14 @@ export const isFolderEmpty = (root: string, name: string): boolean => {

if (conflicts.length > 0) {
console.log(
`The directory ${chalk.green(name)} contains files that could conflict:`,
`The directory ${pico.green(name)} contains files that could conflict:`,
);
console.log();
conflicts.map(file => {
try {
const stats = fs.lstatSync(path.join(root, file));
if (stats.isDirectory()) {
console.log(` ${chalk.blue(file)}/`);
console.log(` ${pico.blue(file)}/`);
} else {
console.log(` ${file}`);
}
Expand Down
35 changes: 35 additions & 0 deletions packages/create-bifrost-app/src/helpers/telemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fetch from 'node-fetch';

import packageJson from '../../package.json';

const TELEMETRY_WEBHOOK =
'https://hook.eu1.make.com/4x7gy2rim0cr25qxmaf83km863xp2eju';

export const telemetryConfig = {
forceDisableTelemetry: false,
};
const isTelemetryDisabled = (): boolean =>
process.env.BIFROST_TELEMETRY === '0' ||
telemetryConfig.forceDisableTelemetry;

export const logCreateApp = async (projectName: string): Promise<void> => {
const body = {
version: packageJson.version,
appName: projectName,
initializedExample:
'https://github.com/theodo-group/bifrost/tree/main/examples/bifrost-starter',
};
if (isTelemetryDisabled()) {
return;
}

try {
await fetch(TELEMETRY_WEBHOOK, {
method: 'POST',
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' },
});
} catch (e) {
return;
}
};
Loading

0 comments on commit 36d4373

Please sign in to comment.