Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ typings/
lib/
typescript/
doc_build/
doc_types/
*.tsbuildinfo
11 changes: 10 additions & 1 deletion docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"moduleResolution": "bundler"
"composite": true,
"rootDir": ".",
"outDir": "./doc_types",
"module": "preserve",
"moduleResolution": "bundler",
"allowImportingTsExtensions": false,
"rewriteRelativeImportExtensions": false,
"declaration": true,
"emitDeclarationOnly": true
},
"include": ["**/*"],
"exclude": ["doc_build", "doc_types", "node_modules"],
"mdx": {
"checkMdx": true
}
Expand Down
3 changes: 3 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export default defineConfig(
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/strict-boolean-expressions': 'off',

'import-x/extensions': ['error', 'ignorePackages'],
},
},

Expand All @@ -43,6 +45,7 @@ export default defineConfig(
'**/out/',
'**/lib/',
'**/templates/',
'**/doc_types/',
'**/__fixtures__/',
])
);
11 changes: 0 additions & 11 deletions packages/create-react-native-library/babel.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env node

require('../lib/index');
import '../lib/src/index.js';
16 changes: 9 additions & 7 deletions packages/create-react-native-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
"url": "https://github.com/callstack/react-native-builder-bob/issues"
},
"homepage": "https://oss.callstack.com/react-native-builder-bob/create",
"main": "lib/index.js",
"type": "module",
"exports": {
".": {
"default": "./lib/src/index.js"
}
},
"bin": "bin/create-react-native-library",
"files": [
"lib",
Expand All @@ -37,7 +42,7 @@
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"prepare": "babel --extensions .ts,.tsx src --out-dir lib --ignore '**/__tests__/**' --source-maps --delete-dir-on-start"
"prepare": "tsc"
},
"dependencies": {
"cross-spawn": "^7.0.6",
Expand All @@ -48,14 +53,11 @@
"github-username": "^9.0.0",
"kleur": "^4.1.5",
"ora": "^9.3.0",
"pigment": "^0.4.3",
"pigment": "^0.4.4",
"typescript": "^5.8.3",
"validate-npm-package-name": "^7.0.2"
},
"devDependencies": {
"@babel/cli": "^7.28.6",
"@babel/core": "^7.29.0",
"@babel/preset-env": "^7.29.2",
"@babel/preset-typescript": "^7.28.5",
"@commitlint/config-conventional": "^20.5.0",
"@types/cross-spawn": "^6.0.6",
"@types/dedent": "^0.7.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'path';
import path from 'node:path';
import fs from 'fs-extra';
import sortObjectKeys from '../utils/sortObjectKeys';
import sortObjectKeys from '../utils/sortObjectKeys.ts';

type PackageJson = {
devDependencies?: Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import path from 'node:path';
import dedent from 'dedent';
import fs from 'fs-extra';
import { getLatestVersion } from 'get-latest-version';
import kleur from 'kleur';
import path from 'path';
import {
SUPPORTED_EXPO_SDK_VERSION,
SUPPORTED_MONOREPO_CONFIG_VERSION,
SUPPORTED_REACT_NATIVE_VERSION,
} from '../constants';
import type { TemplateConfiguration } from '../template';
import sortObjectKeys from '../utils/sortObjectKeys';
import { spawn } from '../utils/spawn';
} from '../constants.ts';
import type { TemplateConfiguration } from '../template.ts';
import sortObjectKeys from '../utils/sortObjectKeys.ts';
import { spawn } from '../utils/spawn.ts';

const FILES_TO_DELETE = [
'__tests__',
Expand Down
30 changes: 15 additions & 15 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import pak from '../package.json';
import path from 'node:path';
import fs from 'fs-extra';
import kleur from 'kleur';
import ora from 'ora';
import path from 'path';
import pak from '../package.json' with { type: 'json' };
import {
FALLBACK_BOB_VERSION,
FALLBACK_NITRO_MODULES_VERSION,
} from './constants';
import { alignDependencyVersionsWithExampleApp } from './exampleApp/dependencies';
import generateExampleApp from './exampleApp/generateExampleApp';
import { printLocalLibNextSteps, printNonLocalLibNextSteps } from './inform';
import { prompt } from './prompt';
import { applyTemplates, generateTemplateConfiguration } from './template';
import { assertNpxExists } from './utils/assert';
import { configureTools } from './utils/configureTools';
import { createInitialGitCommit } from './utils/initialCommit';
} from './constants.ts';
import { alignDependencyVersionsWithExampleApp } from './exampleApp/dependencies.ts';
import generateExampleApp from './exampleApp/generateExampleApp.ts';
import { printLocalLibNextSteps, printNonLocalLibNextSteps } from './inform.ts';
import { prompt } from './prompt.ts';
import { applyTemplates, generateTemplateConfiguration } from './template.ts';
import { assertNpxExists } from './utils/assert.ts';
import { configureTools } from './utils/configureTools.ts';
import { createMetadata } from './utils/createMetadata.ts';
import { createInitialGitCommit } from './utils/initialCommit.ts';
import {
addNitroDependencyToLocalLibrary,
linkLocalLibrary,
} from './utils/local';
import { determinePackageManager } from './utils/packageManager';
import { resolveNpmPackageVersion } from './utils/resolveNpmPackageVersion';
import { createMetadata } from './utils/createMetadata';
} from './utils/local.ts';
import { determinePackageManager } from './utils/packageManager.ts';
import { resolveNpmPackageVersion } from './utils/resolveNpmPackageVersion.ts';

async function create() {
// Prefetch bob version in background while asking questions
Expand Down
4 changes: 2 additions & 2 deletions packages/create-react-native-library/src/inform.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import path from 'node:path';
import dedent from 'dedent';
import type { TemplateConfiguration } from './template';
import kleur from 'kleur';
import type { TemplateConfiguration } from './template.ts';

export function printNonLocalLibNextSteps(config: TemplateConfiguration) {
const platforms = {
Expand Down
6 changes: 3 additions & 3 deletions packages/create-react-native-library/src/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from 'node:fs';
import path from 'node:path';
import githubUsername from 'github-username';
import { create } from 'pigment';
import validateNpmPackage from 'validate-npm-package-name';
import { spawn } from './utils/spawn';
import githubUsername from 'github-username';
import { AVAILABLE_TOOLS } from './utils/configureTools';
import { AVAILABLE_TOOLS } from './utils/configureTools.ts';
import { spawn } from './utils/spawn.ts';

export type Answers = NonNullable<Awaited<ReturnType<typeof prompt.show>>>;

Expand Down
101 changes: 73 additions & 28 deletions packages/create-react-native-library/src/template.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import fs from 'fs-extra';
import path from 'node:path';
import ejs from 'ejs';
import type { Answers, ExampleApp, ProjectType } from './prompt';
import fs from 'fs-extra';
import type { Answers, ExampleApp, ProjectType } from './prompt.ts';

export type TemplateVersions = {
bob: string;
Expand Down Expand Up @@ -51,48 +51,93 @@ const BINARIES = [
/\$\.yarn(?![a-z])/,
];

const COMMON_FILES = path.resolve(__dirname, '../templates/common');
const COMMON_LOCAL_FILES = path.resolve(__dirname, '../templates/common-local');
const COMMON_FILES = path.resolve(
import.meta.dirname,
'../../templates/common'
);
const COMMON_LOCAL_FILES = path.resolve(
import.meta.dirname,
'../../templates/common-local'
);
const EXAMPLE_COMMON_FILES = path.resolve(
__dirname,
'../templates/example-common'
import.meta.dirname,
'../../templates/example-common'
);
const EXAMPLE_BARE_FILES = path.resolve(
import.meta.dirname,
'../../templates/example-bare'
);
const EXAMPLE_BARE_FILES = path.resolve(__dirname, '../templates/example-bare');
const EXAMPLE_MODULE_NEW_FILES = path.resolve(
__dirname,
'../templates/example-module-new'
import.meta.dirname,
'../../templates/example-module-new'
);
const EXAMPLE_VIEW_FILES = path.resolve(
import.meta.dirname,
'../../templates/example-view'
);
const EXAMPLE_EXPO_FILES = path.resolve(
import.meta.dirname,
'../../templates/example-expo'
);
const EXAMPLE_VIEW_FILES = path.resolve(__dirname, '../templates/example-view');
const EXAMPLE_EXPO_FILES = path.resolve(__dirname, '../templates/example-expo');

const JS_FILES = path.resolve(__dirname, '../templates/js-library');
const JS_VIEW_FILES = path.resolve(__dirname, '../templates/js-view');
const JS_FILES = path.resolve(
import.meta.dirname,
'../../templates/js-library'
);
const JS_VIEW_FILES = path.resolve(
import.meta.dirname,
'../../templates/js-view'
);
const NATIVE_COMMON_FILES = path.resolve(
__dirname,
'../templates/native-common'
import.meta.dirname,
'../../templates/native-common'
);
const EXAMPLE_NATIVE_COMMON_FILES = path.resolve(
__dirname,
'../templates/example-native-common'
import.meta.dirname,
'../../templates/example-native-common'
);
const NITRO_COMMON_FILES = path.resolve(
import.meta.dirname,
'../../templates/nitro-common'
);
const CPP_FILES = path.resolve(
import.meta.dirname,
'../../templates/cpp-library'
);
const NITRO_COMMON_FILES = path.resolve(__dirname, '../templates/nitro-common');
const CPP_FILES = path.resolve(__dirname, '../templates/cpp-library');

const NATIVE_FILES = {
module_new: path.resolve(__dirname, '../templates/native-library-new'),
view_new: path.resolve(__dirname, '../templates/native-view-new'),
module_nitro: path.resolve(__dirname, '../templates/nitro-module'),
view_nitro: path.resolve(__dirname, '../templates/nitro-view'),
module_new: path.resolve(
import.meta.dirname,
'../../templates/native-library-new'
),
view_new: path.resolve(
import.meta.dirname,
'../../templates/native-view-new'
),
module_nitro: path.resolve(
import.meta.dirname,
'../../templates/nitro-module'
),
view_nitro: path.resolve(import.meta.dirname, '../../templates/nitro-view'),
} as const;

const OBJC_FILES = {
module_common: path.resolve(__dirname, '../templates/objc-library'),
view_new: path.resolve(__dirname, '../templates/objc-view-new'),
module_common: path.resolve(
import.meta.dirname,
'../../templates/objc-library'
),
view_new: path.resolve(import.meta.dirname, '../../templates/objc-view-new'),
} as const;

const KOTLIN_FILES = {
module_new: path.resolve(__dirname, '../templates/kotlin-library-new'),
view_new: path.resolve(__dirname, '../templates/kotlin-view-new'),
module_new: path.resolve(
import.meta.dirname,
'../../templates/kotlin-library-new'
),
view_new: path.resolve(
import.meta.dirname,
'../../templates/kotlin-view-new'
),
} as const;

export function generateTemplateConfiguration({
Expand Down
2 changes: 1 addition & 1 deletion packages/create-react-native-library/src/utils/assert.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import kleur from 'kleur';
import { spawn } from './spawn';
import { spawn } from './spawn.ts';

export async function assertNpxExists() {
try {
Expand Down
11 changes: 7 additions & 4 deletions packages/create-react-native-library/src/utils/configureTools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import path from 'node:path';
import { applyTemplate, type TemplateConfiguration } from '../template';
import sortObjectKeys from './sortObjectKeys';
import fs from 'fs-extra';
import { applyTemplate, type TemplateConfiguration } from '../template.ts';
import sortObjectKeys from './sortObjectKeys.ts';

type PackageJson = {
dependencies?: Record<string, string>;
Expand Down Expand Up @@ -128,7 +128,10 @@ export async function configureTools({
continue;
}

const toolDir = path.resolve(__dirname, `../../templates/tools/${key}`);
const toolDir = path.resolve(
import.meta.dirname,
`../../../templates/tools/${key}`
);

if (fs.existsSync(toolDir)) {
await applyTemplate(config, toolDir, root);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { version } from '../../package.json';
import type { Answers } from '../prompt';
import pack from '../../package.json' with { type: 'json' };
import type { Answers } from '../prompt.ts';

export function createMetadata(answers: Partial<Answers>) {
// Some of the passed args can already be derived from the generated package.json file.
Expand Down Expand Up @@ -27,7 +27,7 @@ export function createMetadata(answers: Partial<Answers>) {
)
);

libraryMetadata.version = version;
libraryMetadata.version = pack.version;

return libraryMetadata;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from './spawn';
import { spawn } from './spawn.ts';

export async function createInitialGitCommit(
folder: string,
Expand Down
4 changes: 2 additions & 2 deletions packages/create-react-native-library/src/utils/local.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path from 'node:path';
import fs from 'fs-extra';
import path from 'path';
import type { TemplateConfiguration } from '../template';
import type { TemplateConfiguration } from '../template.ts';

type PackageJson = {
dependencies?: Record<string, string>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { spawn } from './spawn';
import { spawn } from './spawn.ts';

export async function resolveNpmPackageVersion(
name: string,
Expand Down
Loading
Loading