Skip to content

Commit

Permalink
Merge pull request #54 from emulsify-ds/develop
Browse files Browse the repository at this point in the history
Deploy
  • Loading branch information
patrickocoffeyo authored Dec 9, 2021
2 parents f3801e0 + 142ef21 commit a7bf491
Show file tree
Hide file tree
Showing 22 changed files with 287 additions and 86 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: daily
2 changes: 1 addition & 1 deletion .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npm run husky:pre-push
npm run husky:pre-push
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14.15
16.13
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Command line interface for Emulsify.

This project is deployed to [npm](https://www.npmjs.com/package/@emulsify/cli). In order to use this CLI, install it as a global dependency:

## Usage

For more information on how to use emulsify-cli, please see the [usage documentation](USAGE.md).

```bash
npm install -g @emulsify/cli
```

## Usage

For more information on how to use emulsify-cli, please see the [usage documentation](USAGE.md).

## Development

Emulsify-cli is developed using TypeScript. You can find all of the source files in the `src` directory, which is organized in the following manner:
Expand Down
2 changes: 1 addition & 1 deletion USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Example usage:

```bash
cd ~/projects/my-drupal-codebase
emuslify init "Theme Name"
emulsify init "Theme Name"

# If you are not relying on the cli to detect the platform, and use a starter:
emulsify init "Theme Name" ./web/themes/custom/theme-name --starter https://github.com/emulsify-ds/emulsify-drupal.git --checkout 2.x --platform drupal
Expand Down
86 changes: 75 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "GPL-2.0",
"private": false,
"engines": {
"node": ">=14.15"
"node": ">=16.13"
},
"bin": {
"emulsify": "dist/index.js"
Expand Down Expand Up @@ -62,13 +62,15 @@
"semantic-release": "^17.3.8",
"ts-jest": "^26.5.1",
"ts-node": "^9.1.1",
"typescript": "^4.1.4"
"typescript": "^4.5.2"
},
"dependencies": {
"@types/progress": "^2.0.5",
"ajv": "^7.1.1",
"ajv": "^7.2.4",
"ajv-formats": "^2.1.1",
"chalk": "^4.1.0",
"commander": "^7.0.0",
"consola": "^2.15.3",
"fs-extra": "^9.1.0",
"progress": "^2.0.3",
"ramda": "^0.27.1",
Expand Down
37 changes: 9 additions & 28 deletions src/handlers/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import R from 'ramda';
import { join } from 'path';
import { existsSync, promises as fs } from 'fs';
import simpleGit from 'simple-git';
import { cyan } from 'chalk';
import ProgressBar from 'progress';

import type { EmulsifyProjectConfiguration } from '@emulsify-cli/config';
Expand All @@ -18,6 +17,7 @@ import writeToJsonFile from '../util/fs/writeToJsonFile';
import strToMachineName from '../util/strToMachineName';
import installDependencies from '../util/project/installDependencies';
import executeScript from '../util/fs/executeScript';
import getInitSuccessMessageForPlatform from '../util/platform/getInitSuccessMessageForPlatform';
import log from '../lib/log';
import { EXIT_ERROR } from '../lib/constants';

Expand Down Expand Up @@ -111,9 +111,6 @@ export default function init(progress: InstanceType<typeof ProgressBar>) {
: {}
);

// Remove the .git directory, as this is a starter kit.
await fs.rmdir(join(target, '.git'), { recursive: true });

// Construct an Emulsify configuration object.
await writeToJsonFile<EmulsifyProjectConfiguration>(
join(target, EMULSIFY_PROJECT_CONFIG_FILE),
Expand Down Expand Up @@ -149,35 +146,19 @@ export default function init(progress: InstanceType<typeof ProgressBar>) {
await executeScript(initPath);
}

// Remove the .git directory, as this is a starter kit. This step
// should happen after dependencies are installed, and init scripts are
// executed, otherwise git-reliant dev deps in the starter may eror out.
await fs.rmdir(join(target, '.git'), { recursive: true });

progress.tick(10, {
message: 'init script executed, initialization complete',
});

log('success', `Created an Emulsify project in ${target}.`);
log(
'info',
`Make sure you install the modules your Emulsify-based theme requires in order to function.`
);
log(
'verbose',
`
- composer require drupal/components
- composer require drupal/emulsify_twig
- drush en components emulsify_twig -y
`
);
log(
'info',
`Once the requirements have been installed, you will need to select a system to use, as Emulsify does not come with components by default.`
);
log(
'verbose',
`
${cyan('List systems')}: emulsify system list
${cyan('Install a system')}: emulsify system install "system-name"
${cyan('Install default system')}: emulsify system install compound
`
);
getInitSuccessMessageForPlatform(
platformName
).map(({ method, message }) => log(method, message));
} catch (e) {
log(
'error',
Expand Down
53 changes: 52 additions & 1 deletion src/handlers/systemInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ import type { GitCloneOptions } from '@emulsify-cli/git';
import type { EmulsifySystem } from '@emulsify-cli/config';

import R from 'ramda';
import { EXIT_ERROR, EMULSIFY_SYSTEM_CONFIG_FILE } from '../lib/constants';
import Ajv from 'ajv';
import addFormats from 'ajv-formats';
import { join } from 'path';
import { existsSync } from 'fs';
import {
EXIT_ERROR,
EMULSIFY_SYSTEM_CONFIG_FILE,
EMULSIFY_PROJECT_HOOK_FOLDER,
EMULSIFY_PROJECT_HOOK_SYSTEM_INSTALL,
} from '../lib/constants';
import log from '../lib/log';
import getAvailableSystems from '../util/system/getAvailableSystems';
import getGitRepoNameFromUrl from '../util/getGitRepoNameFromUrl';
Expand All @@ -14,6 +23,10 @@ import installGeneralAssetsFromCache from '../util/project/installGeneralAssetsF
import getJsonFromCachedFile from '../util/cache/getJsonFromCachedFile';
import setEmulsifyConfig from '../util/project/setEmulsifyConfig';
import getEmulsifyConfig from '../util/project/getEmulsifyConfig';
import findFileInCurrentPath from '../util/fs/findFileInCurrentPath';
import executeScript from '../util/fs/executeScript';
import systemSchema from '../schemas/system.json';
import variantSchema from '../schemas/variant.json';

/**
* Helper function that uses InstallSystemHandlerOptions input to determine what
Expand Down Expand Up @@ -117,6 +130,31 @@ export default async function systemInstall(
);
}

// Validate the system configuration file.
try {
const ajv = new Ajv();
// This is unfortunate...
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore The ajv-formats typing is bad :(
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
addFormats(ajv, ['uri']);
ajv.addSchema(variantSchema, 'variant.json');
const validate = ajv.compile(systemSchema);

if (!validate(systemConf)) {
throw validate.errors;
}
} catch (e) {
// We're logging to the console here instead of our normal logging mechanism
// in order to have more readable output from the AJV validation.
console.error('System configuration errors:', e);
return log(
'error',
`The system install failed due to the validation errors reported above. Please fix the the errors in the "${systemConf.name}" configuration and try again.`,
EXIT_ERROR
);
}

// Extract the variant name, and error if no variant is determinable.
const variantName: string | void =
options.variant || projectConfig.project.platform;
Expand Down Expand Up @@ -185,6 +223,19 @@ export default async function systemInstall(

// Install all global files and folders.
await installGeneralAssetsFromCache(systemConf, variantConf);

// Execute system install hook.
const path = findFileInCurrentPath(EMULSIFY_SYSTEM_CONFIG_FILE);
const hookPath = path
? join(
path,
EMULSIFY_PROJECT_HOOK_FOLDER,
EMULSIFY_PROJECT_HOOK_SYSTEM_INSTALL
)
: undefined;
if (hookPath && existsSync(hookPath)) {
await executeScript(hookPath);
}
} catch (e) {
return log(
'error',
Expand Down
1 change: 1 addition & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const EXIT_ERROR = 1;
export const EMULSIFY_PROJECT_CONFIG_FILE = 'project.emulsify.json';
export const EMULSIFY_PROJECT_HOOK_FOLDER = '.cli';
export const EMULSIFY_PROJECT_HOOK_INIT = 'init.js';
export const EMULSIFY_PROJECT_HOOK_SYSTEM_INSTALL = 'systemInstall.js';
export const EMULSIFY_SYSTEM_CONFIG_FILE = 'system.emulsify.json';
export const UTIL_DIR = join(homedir(), '.emulsify');
export const CACHE_DIR = join(UTIL_DIR, 'cache');
Loading

0 comments on commit a7bf491

Please sign in to comment.