Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 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
10 changes: 7 additions & 3 deletions packages/cli/src/lib/plugins/fingerprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ export async function nativeFingerprintCommand(
function validateOptions(options: NativeFingerprintCommandOptions) {
if (!options.platform) {
throw new RockError(
'The --platform flag is required. Please specify either "ios" or "android".',
'The --platform flag is required. Please specify either "ios", "android" or "harmony".',
);
}
if (options.platform !== 'ios' && options.platform !== 'android') {
if (
options.platform !== 'ios' &&
options.platform !== 'android' &&
options.platform !== 'harmony'
) {
throw new RockError(
`Unsupported platform "${options.platform}". Please specify either "ios" or "android".`,
`Unsupported platform "${options.platform}". Please specify either "ios", "android" or "harmony".`,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/plugins/logConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const logConfigPlugin =
options: [
{
name: '-p, --platform <string>',
description: 'Select platform, e.g. ios or android',
description: 'Select platform, e.g. ios, android, or harmony',
},
],
});
Expand Down
3 changes: 3 additions & 0 deletions packages/create-app/src/lib/__tests__/bin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ test('should format config without plugins', () => {
.toMatchInlineSnapshot(`
"import { platformIOS } from '@rock-js/platform-ios';
import { platformAndroid } from '@rock-js/platform-android';
import { platformHarmony } from '@rock-js/platform-harmony';
import { pluginMetro } from '@rock-js/plugin-metro';

export default {
bundler: pluginMetro(),
platforms: {
ios: platformIOS(),
android: platformAndroid(),
harmony: platformHarmony(),
},
};
"
Expand All @@ -25,6 +27,7 @@ test('should format config with plugins', () => {
{
type: 'npm',
name: 'test',
displayName: 'test',
packageName: '@rock-js/plugin-test',
version: 'latest',
directory: 'template',
Expand Down
11 changes: 11 additions & 0 deletions packages/create-app/src/lib/__tests__/templates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ test('resolveTemplateName with built-in templates', () => {
expect(resolveTemplate(TEMPLATES, 'default')).toEqual({
type: 'npm',
name: 'default',
displayName: 'default',
packageName: '@rock-js/template-default',
version: 'latest',
directory: '.',
Expand All @@ -16,6 +17,7 @@ test('resolveTemplateName with local paths', () => {
expect(resolveTemplate(TEMPLATES, './directory/template-1')).toEqual({
type: 'local',
name: 'template-1',
displayName: 'template-1',
localPath: path.resolve('./directory/template-1'),
directory: '.',
packageName: 'template-1',
Expand All @@ -24,6 +26,7 @@ test('resolveTemplateName with local paths', () => {
expect(resolveTemplate(TEMPLATES, '../../up/up/away/template-2')).toEqual({
type: 'local',
name: 'template-2',
displayName: 'template-2',
localPath: path.resolve('../../up/up/away/template-2'),
directory: '.',
packageName: 'template-2',
Expand All @@ -32,6 +35,7 @@ test('resolveTemplateName with local paths', () => {
expect(resolveTemplate(TEMPLATES, '/absolute/path/template-3')).toEqual({
type: 'local',
name: 'template-3',
displayName: 'template-3',
localPath: '/absolute/path/template-3',
directory: '.',
packageName: 'template-3',
Expand All @@ -42,6 +46,7 @@ test('resolveTemplateName with local paths', () => {
).toEqual({
type: 'local',
name: 'template-4',
displayName: 'template-4',
localPath: '/url-based/path/template-4',
directory: '.',
packageName: 'template-4',
Expand All @@ -50,6 +55,7 @@ test('resolveTemplateName with local paths', () => {
expect(resolveTemplate(TEMPLATES, './directory/template-5.tgz')).toEqual({
type: 'local',
name: 'template-5',
displayName: 'template-5',
localPath: path.resolve('./directory/template-5.tgz'),
directory: '.',
packageName: 'template-5',
Expand All @@ -58,6 +64,7 @@ test('resolveTemplateName with local paths', () => {
expect(resolveTemplate(TEMPLATES, '../up/template-6.tar')).toEqual({
type: 'local',
name: 'template-6',
displayName: 'template-6',
localPath: path.resolve('../up/template-6.tar'),
directory: '.',
packageName: 'template-6',
Expand All @@ -66,6 +73,7 @@ test('resolveTemplateName with local paths', () => {
expect(resolveTemplate(TEMPLATES, '/root/directory/template-7.tgz')).toEqual({
type: 'local',
name: 'template-7',
displayName: 'template-7',
localPath: '/root/directory/template-7.tgz',
directory: '.',
packageName: 'template-7',
Expand All @@ -76,20 +84,23 @@ test('resolveTemplateName with npm packages', () => {
expect(resolveTemplate(TEMPLATES, 'package-name')).toEqual({
type: 'npm',
name: 'package-name',
displayName: 'package-name',
directory: '.',
packageName: 'package-name',
version: 'latest',
});
expect(resolveTemplate(TEMPLATES, '[email protected]')).toEqual({
type: 'npm',
name: 'package-name',
displayName: 'package-name',
directory: '.',
packageName: 'package-name',
version: '1.2.3',
});
expect(resolveTemplate(TEMPLATES, '@scoped/[email protected]')).toEqual({
type: 'npm',
name: '@scoped/package-name',
displayName: '@scoped/package-name',
directory: '.',
packageName: '@scoped/package-name',
version: '1.2.3',
Expand Down
19 changes: 16 additions & 3 deletions packages/create-app/src/lib/bin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ export async function run() {
for (const platform of platforms) {
await extractPackage(absoluteTargetDir, platform);
}
await extractPackage(absoluteTargetDir, bundler);
// Skip metro.config.js for Harmony platform as it's included in the platform template
const skipFiles = platforms
.map((platform) => platform.name)
.includes('harmony')
? ['metro.config.js']
: undefined;
await extractPackage(absoluteTargetDir, bundler, skipFiles);
for (const plugin of plugins ?? []) {
await extractPackage(absoluteTargetDir, plugin);
}
Expand Down Expand Up @@ -252,7 +258,11 @@ async function installDependencies(
loader.stop(`Installed dependencies with ${pkgManager}`);
}

async function extractPackage(absoluteTargetDir: string, pkg: TemplateInfo) {
async function extractPackage(
absoluteTargetDir: string,
pkg: TemplateInfo,
skipFiles?: string[],
) {
let tarballPath: string | null = null;
// NPM package: download tarball file
if (pkg.type === 'npm') {
Expand Down Expand Up @@ -282,7 +292,9 @@ async function extractPackage(absoluteTargetDir: string, pkg: TemplateInfo) {
fs.unlinkSync(tarballPath);
}

copyDirSync(path.join(localPath, pkg.directory ?? ''), absoluteTargetDir);
copyDirSync(path.join(localPath, pkg.directory ?? ''), absoluteTargetDir, {
skipFiles,
});
removeDirSync(localPath);

return;
Expand All @@ -292,6 +304,7 @@ async function extractPackage(absoluteTargetDir: string, pkg: TemplateInfo) {
copyDirSync(
path.join(pkg.localPath, pkg.directory ?? ''),
absoluteTargetDir,
{ skipFiles },
);

return;
Expand Down
20 changes: 20 additions & 0 deletions packages/create-app/src/lib/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type TemplateInfo = NpmTemplateInfo | LocalTemplateInfo;
export type NpmTemplateInfo = {
type: 'npm';
name: string;
displayName: string;
version: string;
packageName: string;
/** Directory inside package that contains the template */
Expand All @@ -21,6 +22,7 @@ export type LocalTemplateInfo = {
type: 'local';
name: string;
localPath: string;
displayName: string | undefined;
packageName: string;
directory: string | undefined;
importName?: string;
Expand All @@ -31,6 +33,7 @@ export const TEMPLATES: TemplateInfo[] = [
{
type: 'npm',
name: 'default',
displayName: 'default',
packageName: '@rock-js/template-default',
version: 'latest',
directory: '.',
Expand All @@ -41,6 +44,7 @@ export const PLUGINS: TemplateInfo[] = [
{
type: 'npm',
name: 'brownfield-ios',
displayName: 'Brownfield iOS',
packageName: '@rock-js/plugin-brownfield-ios',
hint: 'Setup packaging React Native app as a XCFramework',
version: 'latest',
Expand All @@ -50,6 +54,7 @@ export const PLUGINS: TemplateInfo[] = [
{
type: 'npm',
name: 'brownfield-android',
displayName: 'Brownfield Android',
packageName: '@rock-js/plugin-brownfield-android',
hint: 'Setup packaging React Native app as an AAR',
version: 'latest',
Expand All @@ -62,6 +67,7 @@ export const BUNDLERS: TemplateInfo[] = [
{
type: 'npm',
name: 'metro',
displayName: 'Metro',
packageName: '@rock-js/plugin-metro',
version: 'latest',
directory: 'template',
Expand All @@ -70,6 +76,7 @@ export const BUNDLERS: TemplateInfo[] = [
{
type: 'npm',
name: 'repack',
displayName: 'Re.Pack',
packageName: '@rock-js/plugin-repack',
version: 'latest',
directory: 'template',
Expand All @@ -81,6 +88,7 @@ export const PLATFORMS: TemplateInfo[] = [
{
type: 'npm',
name: 'ios',
displayName: 'iOS',
packageName: '@rock-js/platform-ios',
version: 'latest',
directory: 'template',
Expand All @@ -89,11 +97,21 @@ export const PLATFORMS: TemplateInfo[] = [
{
type: 'npm',
name: 'android',
displayName: 'Android',
packageName: '@rock-js/platform-android',
version: 'latest',
directory: 'template',
importName: 'platformAndroid',
},
{
type: 'npm',
name: 'harmony',
displayName: 'Harmony (experimental)',
packageName: '@rock-js/platform-harmony',
version: 'latest',
directory: 'template',
importName: 'platformHarmony',
},
];

export function remoteCacheProviderToImportTemplate(
Expand Down Expand Up @@ -175,6 +193,7 @@ export function resolveTemplate(
return {
type: 'local',
name: basename.slice(0, basename.length - ext.length),
displayName: basename.slice(0, basename.length - ext.length),
localPath: resolveAbsolutePath(name),
directory: '.',
packageName: basename.slice(0, basename.length - ext.length),
Expand All @@ -187,6 +206,7 @@ export function resolveTemplate(
return {
type: 'npm',
name: getNpmLibraryName(name),
displayName: getNpmLibraryName(name),
packageName: getNpmLibraryName(name),
directory: '.',
version: getNpmLibraryVersion(name) ?? 'latest',
Expand Down
13 changes: 10 additions & 3 deletions packages/create-app/src/lib/utils/edit-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ const PLACEHOLDER_NAME = 'HelloWorld';
*/
export function renameCommonFiles(projectPath: string) {
const sourceGitIgnorePath = path.join(projectPath, 'gitignore');
if (!fs.existsSync(sourceGitIgnorePath)) {
return;
if (fs.existsSync(sourceGitIgnorePath)) {
fs.renameSync(sourceGitIgnorePath, path.join(projectPath, '.gitignore'));
}

fs.renameSync(sourceGitIgnorePath, path.join(projectPath, '.gitignore'));
// Harmony platform has a separate gitignore file.
const harmonyGitIgnorePath = path.join(projectPath, 'harmony', 'gitignore');
if (fs.existsSync(harmonyGitIgnorePath)) {
fs.renameSync(
harmonyGitIgnorePath,
path.join(projectPath, 'harmony', '.gitignore'),
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/src/lib/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function copyDirSync(
} else {
if (nodePath.basename(srcFile) === 'package.json') {
mergePackageJsons(srcFile, distFile);
} else {
} else if (!skipFiles?.includes(nodePath.basename(srcFile))) {
fs.copyFileSync(srcFile, distFile);
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/create-app/src/lib/utils/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export async function promptTemplate(
// @ts-expect-error todo
options: templates.map((template) => ({
value: template,
label: template.name,
label: template.displayName,
})),
});
}
Expand All @@ -118,7 +118,7 @@ export function promptPlatforms(
// @ts-expect-error todo
options: platforms.map((platform) => ({
value: platform,
label: platform.name,
label: platform.displayName,
})),
});
}
Expand All @@ -135,7 +135,7 @@ export function promptPlugins(
// @ts-expect-error todo fixup type
options: plugins.map((plugin) => ({
value: plugin,
label: plugin.name,
label: plugin.displayName,
hint: plugin.hint,
})),
required: false,
Expand All @@ -155,7 +155,7 @@ export function promptBundlers(
// @ts-expect-error todo fixup type
options: bundlers.map((bundler) => ({
value: bundler,
label: bundler.name,
label: bundler.displayName,
})),
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const androidProject: AndroidProjectConfig = {
const fingerprintOptions = {
extraSources: [],
ignorePaths: [],
env: [],
};

const spinnerMock = vi.hoisted(() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export async function tryInstallAppOnDevice(
let deviceId: string;
if (!device.deviceId) {
logger.debug(
`No device with id "${device.deviceId}", skipping launching the app.`,
`No "deviceId" for ${device}, skipping launching the app`,
);
return;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function tryLaunchAppOnDevice(
let deviceId;
if (!device.deviceId) {
logger.debug(
`No device with id "${device.deviceId}", skipping launching the app.`,
`No "deviceId" for ${device}, skipping launching the app`,
);
return {};
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/platform-harmony/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
1 change: 1 addition & 0 deletions packages/platform-harmony/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @rock-js/platform-harmony
7 changes: 7 additions & 0 deletions packages/platform-harmony/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @rock-js/platform-harmony

HarmonyOS Next platform integration for Rock. This package is part of the Rock ecosystem and provides HarmonyOS-specific build and development tools.

## Documentation

For detailed documentation about Rock and its tools, visit [Rock Documentation](https://rockjs.dev)
Loading
Loading