Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mlm creating pushing app #412

Draft
wants to merge 49 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
177b286
add command which allow to create react app based on npm package nad …
robhil Nov 9, 2021
6f244bd
add creating app, package.json tmp directory, installing peer depende…
robhil Nov 9, 2021
76a022b
creating config file
robhil Nov 9, 2021
8ad2287
overwrite uxpin.config.js during executing command
robhil Nov 9, 2021
0e3717e
pushing library from npm package
robhil Nov 18, 2021
9555b0e
remove temporary files, improve integrate-package script
robhil Nov 19, 2021
73158c4
add types
robhil Nov 19, 2021
25bbf9c
eslint fixes
robhil Nov 19, 2021
b8a986a
eslint fixes
robhil Nov 19, 2021
262608e
refactor
robhil Nov 19, 2021
6c4378d
temporary switch off test
robhil Nov 19, 2021
03ff340
add comment
robhil Nov 19, 2021
4104ea7
revert changes
robhil Nov 19, 2021
51670b2
allot to attach external css files
robhil Nov 19, 2021
9553e5f
Merge branch 'mlm' into mlm-creating-app-push-to-library
robhil Nov 19, 2021
5f43bcc
generate wrapper files for components, remove imports from uxpin.conf…
robhil Nov 22, 2021
e8d942a
refactor
robhil Nov 22, 2021
5b0167d
tslint fixes
robhil Nov 22, 2021
2fae33f
fix webpack config
robhil Nov 22, 2021
07d66d4
move integrate-package script to node script for consistency
robhil Nov 22, 2021
4a43ffc
add package version parameter, show logs during executing command
robhil Nov 29, 2021
5f7e83c
remove redundant condition
robhil Nov 29, 2021
570c1f8
change styles to externalCssUrl, command refactor
robhil Nov 29, 2021
d14b3c2
remove setTimeout
robhil Nov 29, 2021
1dc251d
eslint fixes
robhil Nov 29, 2021
c7270e4
creating npmrc file
robhil Nov 30, 2021
efeb7aa
eslint fixes
robhil Nov 30, 2021
667179d
fixes after cr
robhil Dec 1, 2021
9a40c65
add uxpin-domain parameter to be able to test it on local env
robhil Dec 1, 2021
2bf03d4
Exit with status code of 1 when uxpin-integrate-package fails
naohiro-t Feb 7, 2022
3e194c8
handle multiple css resource, packages nad component names instead of…
robhil Mar 1, 2022
f4de68d
Merge branch 'mlm-creating-pushing-app' of github.com:UXPin/uxpin-mer…
robhil Mar 1, 2022
ad3eade
remove unused imports
robhil Mar 1, 2022
48da63a
handle namespaced components
robhil May 26, 2022
3ba6aa0
Merge branch 'master' into mlm-creating-pushing-app
robhil May 26, 2022
05e12ff
render broken element when name of component is invalid
robhil Jun 27, 2022
7953a8b
add key property
robhil Aug 3, 2022
89881f9
fix adding key property
robhil Aug 3, 2022
e6a81e0
handle chakra-ui
robhil Sep 30, 2022
e3980b5
tslint fix
robhil Sep 30, 2022
15db6ef
set proper version of babel-loader
robhil Oct 28, 2022
3398180
update version without formatting code
robhil Oct 28, 2022
ad24164
Merge branch 'master' into mlm-creating-pushing-app
robhil Dec 13, 2022
c26b510
eslint fixes
robhil Dec 13, 2022
f73f246
Merge branch 'master' into mlm-creating-pushing-app
robhil Sep 14, 2023
066c9bc
lint fixes after merge
robhil Sep 14, 2023
ee84dd2
lint fixes after merge
robhil Sep 14, 2023
c9b22ce
lint fixes after merge
robhil Sep 14, 2023
47f0b57
lint fixes after merge
robhil Sep 14, 2023
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
1 change: 1 addition & 0 deletions packages/uxpin-merge-cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
!/test/resources/repos/.gitkeep
/reports/*
!/reports/.gitkeep
/tmp/**

!/test/resources/configs/*.js
!/test/resources/components/**/*.js
Expand Down
76 changes: 76 additions & 0 deletions packages/uxpin-merge-cli/bin/uxpin-integrate-package
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env node

const program = require('commander');
const cp = require('child_process');
const path = require('path');
const fs = require('fs-extra');
const pMapSeries = require("p-map-series");

program
.option('--token <string>', 'Library token')
.option('--packages <string>', 'NPM Package name')
.option('--components <string>', 'List of imported components and categories')
.option('--css-resources <url>', 'Urls or paths to CSS Styles')
.option('--npmrc <string>', 'Content of .npmrc')
.option('--uxpin-domain <string>', 'Can be used to set a UXPin private cloud domain. Default: `uxpin.com`');

program.parse(process.argv);

const uxpinMergePath = path.resolve(__dirname, './uxpin-merge');
const appPath = path.resolve(process.cwd(), program.token);
const commands = [
spawn.bind(spawn, [
'create-app',
`--packages=${program.packages}`,
program.npmrc ? `--npmrc=${program.npmrc}` : '',
`--app-name=${program.token}`,
`--components=${program.components}`
].filter(Boolean)),
spawn.bind(spawn, [
'push',
'--webpack-config=webpack.config.js',
`--disable-version-control`,
program.uxpinDomain ? `--uxpin-domain=${program.uxpinDomain}` : '',
`--token=${program.token}`,
program.cssResources ? `--css-resources=${program.cssResources}` : ''
].filter(Boolean), { cwd: appPath })
];

async function spawn(args, options = {}) {
return new Promise((resolve, reject) => {
const child = cp.spawn(uxpinMergePath, args, options);

child.stdout.on('data', (data) => {
console.log(String(data));
});

child.stderr.on('data', function (data) {
console.log(String(data));
});

child.on('close', function (code) {
if (code !== 0) {
reject(`Exited with code ${code}`);
return;
}
resolve();
});
});
}

async function executeCommands() {
let exitCode = 0;
try {
await pMapSeries(commands, (command) => command());
} catch (e) {
console.error(e);
exitCode = 1;
} finally {
if (fs.pathExistsSync(appPath)) {
fs.removeSync(appPath);
}
process.exit(exitCode);
}
}

executeCommands();
11 changes: 11 additions & 0 deletions packages/uxpin-merge-cli/bin/uxpin-merge
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ program
.option('--component-path <path>', 'path to a component path, relative to the current working directory')
.action(() => {});

program
.command(Command.CREATE_APP)
.description('Create app based on package name')
.option('--app-name <string>', 'App name')
.option('--components <string>', 'list of imports statements')
.option('--packages <string>', 'names and versions of npm packages')
.option('--npmrc <string>', 'Content of .npmrc')
.action(() => {});


program
.command(Command.PUSH)
Expand All @@ -42,6 +51,8 @@ program
.option('--token <token>', 'auth token for the library. Default: `UXPIN_AUTH_TOKEN` env variable')
.option('--branch <branch>', 'branch to use when uploading. Default: master')
.option('--tag <tag>', 'tag this push with a specific name or number. The provided name/number is unique and can be used only once.')
.option('--css-resources <string>', 'Attach external css styles to pushed js bundle')
.option('--disable-version-control', 'Turn off version control')
.option('--force', 'ignore the last commit saved in uxpin db and push the library without checking history. It could break old prototypes if components were created before 07.2021')
.action(() => {});

Expand Down
1 change: 1 addition & 0 deletions packages/uxpin-merge-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"main": "src/index.js",
"bin": {
"uxpin-integrate-package": "bin/uxpin-integrate-package",
"uxpin-merge": "bin/uxpin-merge"
},
"typings": "src/types.d.ts",
Expand Down
13 changes: 13 additions & 0 deletions packages/uxpin-merge-cli/src/program/args/ProgramArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export interface ConfigEnabledProgramArgs {
uxpinDomain?: string;
}

export type WatchProgramArgs = ExperimentProgramArgs;

export type ProgramArgs =
| CreateAppProgramArgs
| DumpProgramArgs
| ExperimentProgramArgs
| InitProgramArgs
Expand Down Expand Up @@ -66,6 +69,8 @@ export interface PushProgramArgs {
// https://github.com/UXPin/uxpin-merge-tools/issues/206
branch?: string;
tag?: string;
disableVersionControl?: boolean;
cssResources?: string;
}

export interface DeleteVersionArgs {
Expand All @@ -85,6 +90,14 @@ export interface GeneratePresetsProgramArgs {
config?: string;
}

export interface CreateAppProgramArgs {
command: Command.CREATE_APP;
components?: string;
packages: string;
appName: string;
npmrc?: string;
}

export interface ServerProgramArgs {
command: Command.SERVER;
cwd: string;
Expand Down
20 changes: 16 additions & 4 deletions packages/uxpin-merge-cli/src/program/args/getProgramArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const defaultArgs: { [key in Command]: ProgramArgs } = {
config: DEFAULT_CONFIG_PATH,
cwd: process.cwd(),
},
[Command.CREATE_APP]: {
appName: 'react-app',
command: Command.CREATE_APP,
npmrc: '',
packages: '',
},
[Command.DUMP]: {
command: Command.DUMP,
config: DEFAULT_CONFIG_PATH,
Expand Down Expand Up @@ -63,10 +69,16 @@ const defaultArgs: { [key in Command]: ProgramArgs } = {
export function getProgramArgs(program: RawProgramArgs): ProgramArgs {
const command: Command = getCommand(program);
const cliArgs: ProgramArgs = getCLIArgs(program, command);
const configArgs: ConfigEnabledProgramArgs = pickConfigArgs(
getConfigPath({ ...defaultArgs[command], ...cliArgs }),
command
);

if (command === Command.CREATE_APP) {
return {
...defaultArgs[command],
...cliArgs,
} as ProgramArgs;
}

const { cwd = '', config = undefined } = { ...defaultArgs[command], ...cliArgs };
const configArgs: ConfigEnabledProgramArgs = pickConfigArgs(getConfigPath({ cwd, config }), command);
return {
...defaultArgs[command],
...configArgs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('getConfigPath', () => {
};

// then
expect(getConfigPath(args as ProgramArgs)).toEqual('/project/root/directory/file.js');
expect(getConfigPath({ cwd: args.cwd, config: args.config })).toEqual('/project/root/directory/file.js');
});
});

Expand All @@ -23,6 +23,6 @@ describe('getConfigPath', () => {
};

// then
expect(getConfigPath(args as ProgramArgs)).toEqual('/absolute/directory/file.js');
expect(getConfigPath({ cwd: args.cwd, config: args.config })).toEqual('/absolute/directory/file.js');
});
});
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { resolve } from 'path';
import { ProgramArgs } from '../../ProgramArgs';

export function getConfigPath({ cwd, config }: ProgramArgs): string {
export function getConfigPath({ cwd, config }: { cwd: string | undefined; config: string | undefined }): string {
if (!cwd) {
return '';
}
return resolve(cwd, config || '');
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ProjectPaths } from '../../../../steps/discovery/paths/ProjectPaths';
import { ProgramArgs } from '../../ProgramArgs';
import { CreateAppProgramArgs, ProgramArgs } from '../../ProgramArgs';
import { getConfigPath } from './getConfigPath';
import { getProjectRoot } from './getProjectRoot';

export function getProjectPaths(programArgs: ProgramArgs): ProjectPaths {
export function getProjectPaths(programArgs: Exclude<ProgramArgs, CreateAppProgramArgs>): ProjectPaths {
const { cwd, config } = programArgs;
return {
configPath: getConfigPath(programArgs),
configPath: getConfigPath({ cwd, config }),
projectRoot: getProjectRoot(programArgs),
};
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isAbsolute, resolve } from 'path';
import { ProgramArgs } from '../../ProgramArgs';
import { CreateAppProgramArgs, ProgramArgs } from '../../ProgramArgs';

export function getProjectRoot({ cwd }: Pick<ProgramArgs, 'cwd'>): string {
export function getProjectRoot({ cwd }: Pick<Exclude<ProgramArgs, CreateAppProgramArgs>, 'cwd'>): string {
if (isAbsolute(cwd)) {
return cwd;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { join } from 'path';
import { TEMP_DIR_PATH } from '../../../../steps/building/config/getConfig';
import { ProgramArgs } from '../../ProgramArgs';
import { CreateAppProgramArgs, ProgramArgs } from '../../ProgramArgs';
import { getProjectRoot } from './getProjectRoot';

export function getTempDirPath(args: Pick<ProgramArgs, 'cwd'>): string {
export function getTempDirPath(args: Pick<Exclude<ProgramArgs, CreateAppProgramArgs>, 'cwd'>): string {
return join(getProjectRoot(args), TEMP_DIR_PATH);
}
1 change: 1 addition & 0 deletions packages/uxpin-merge-cli/src/program/command/Command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export enum Command {
DUMP = 'dump',
EXPERIMENT = 'experiment',
INIT = 'init',
CREATE_APP = 'create-app',
GENERATE_PRESETS = 'generate-presets',
PUSH = 'push',
DELETE_VERSION = 'delete-version',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { CreateAppProgramArgs } from '../../args/ProgramArgs';
import { Step } from '../Step';
import { createAppDirectory } from './steps/createAppDirectory';
import { createComponentsFiles } from './steps/createComponentsFiles';
import { createNpmrcFile } from './steps/createNpmrcFile';
import { createPackageJsonFile } from './steps/createPackageJsonFile';
import { createUXPinConfigFile } from './steps/createUXPinConfigFile';
import { createWebpackConfigFile } from './steps/createWebpackConfigFile';
import { installPackages } from './steps/installPackages';
import { installPeerDependencies } from './steps/installPeerDependencies';

export function createApp(args: CreateAppProgramArgs): Step[] {
return [
createAppDirectory(args),
createPackageJsonFile(args),
createNpmrcFile(args),
installPackages(args),
installPeerDependencies(args),
createComponentsFiles(args),
createWebpackConfigFile(args),
createUXPinConfigFile(args),
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { mkdir, pathExists } from 'fs-extra';
import { resolve } from 'path';
import { printLine, printWarning } from '../../../../utils/console/printLine';
import { PrintColor } from '../../../../utils/console/PrintOptions';
import { CreateAppProgramArgs } from '../../../args/ProgramArgs';
import { Step } from '../../Step';

export let APP_DIRECTORY = '';

export function createAppDirectory(args: CreateAppProgramArgs): Step {
return { exec: thunkCreateAppDirectory(args), shouldRun: true };
}

export function thunkCreateAppDirectory(args: CreateAppProgramArgs): () => Promise<void> {
return async () => {
if (!args.appName) {
throw new Error('🛑 Invalid app name');
}

const appDirectory = resolve(process.cwd(), args.appName);
APP_DIRECTORY = appDirectory;
if (!(await pathExists(appDirectory))) {
await mkdir(appDirectory);
printLine(`✅ App directory "${appDirectory}" created`, { color: PrintColor.GREEN });
} else {
printWarning(`👉 App directory "${appDirectory}" exists`);
}
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { mkdir, pathExists } from 'fs-extra';
import pMapSeries = require('p-map-series');
import { resolve } from 'path';
import { printLine } from '../../../../utils/console/printLine';
import { PrintColor } from '../../../../utils/console/PrintOptions';
import { writeToFile } from '../../../../utils/fs/writeToFile';
import { CreateAppProgramArgs } from '../../../args/ProgramArgs';
import { Step } from '../../Step';
import { APP_DIRECTORY } from './createAppDirectory';

export function createComponentsFiles(args: CreateAppProgramArgs): Step {
return { exec: thunkCreateComponentsFiles(args), shouldRun: true };
}

const SUFFIX = 'El';

export const components: Array<{ name: string; include: string[] }> = [];

function getComponentContent(name: string, packageName: string): string {
const normalizedName: string = name.replace(/\./g, '');
return [
`import React from 'react';`,
`import PropTypes from 'prop-types'`,
`const packageData = require('${packageName}') || {};`,
`let ${normalizedName}${SUFFIX} = null;`,
`try {`,
`${normalizedName}${SUFFIX} = packageData.${name} ? packageData.${name} : packageData.default;`,
'} catch (e) {}',
`const ${normalizedName} = (props) => {`,
`const key = (Math.random() + 1).toString(36).substring(3);`,
`if (!${normalizedName}${SUFFIX}) return <div class="el-broken" style={{ width: 150, height: 75 }}></div>;`,
`return <${normalizedName}${SUFFIX} key={key} {...props} />`,
`};`,
`export default ${normalizedName};`,
].join('\n');
}

export function thunkCreateComponentsFiles(args: CreateAppProgramArgs): () => Promise<void> {
return async () => {
let componentsList: Array<{ categoryName: string; components: Array<{ name: string; packageName: string }> }> = [];

try {
componentsList = JSON.parse(args.components || '');
} catch (e) {
console.log(e);
// do nothing
}

const componentsPath: string = resolve(APP_DIRECTORY, 'components');
if (!(await pathExists(componentsPath))) {
mkdir(componentsPath);
}

await pMapSeries(componentsList, async (componentData) => {
components.push({ name: componentData.categoryName, include: [] });
await pMapSeries(componentData.components, async ({ name, packageName }) => {
const normalizedName: string = name.replace(/\./g, '');
const componentFile = `${componentsPath}/${normalizedName}.jsx`;

await writeToFile(componentFile, getComponentContent(name, packageName));
components[components.length - 1].include.push(`components/${normalizedName}.jsx`);
printLine(`✅ File ${componentFile} created`, { color: PrintColor.GREEN });
});
});
};
}
Loading