Skip to content
Permalink
Browse files

fix(scripts): postinstall adjustment and cleanup

  • Loading branch information...
NathanWalker committed Jul 31, 2019
1 parent 46c718d commit 423aa499fd78d5353d35238dd075ba71b1f238df
@@ -1,6 +1,6 @@
{
"name": "@nstudio/xplat-source",
"version": "8.0.0",
"version": "8.0.1",
"description": "Cross-platform (xplat) tools for Nx workspaces.",
"homepage": "https://nstudio.io/xplat",
"private": true,
@@ -23,6 +23,7 @@
"documentation": "./scripts/documentation/documentation.sh && yarn format && ./scripts/documentation/check-documentation.sh",
"debug": "node --debug-brk ./node_modules/@angular/cli/bin/ng g command",
"publish-local": "./scripts/publish_local.sh",
"publish-npm": "./scripts/publish.sh",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"reset.changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"contributors": "githubcontrib --owner nstudio --repo $(basename $(pwd)) --cols 6 --showlogin true --filter gitter-badger --sortOrder desc | pbcopy"
@@ -38,7 +38,7 @@ export default function(options: Schema) {
missingArgument(
'name',
'Provide a name for your app.',
'ng g @nstudio/angular:app my-app'
'nx g @nstudio/angular:app my-app'
)
);
}
@@ -36,7 +36,7 @@ let componentSymbolList: string;
let htmlElements: string;
export default function(options: ElementsOptions) {
if (!options.builderModule) {
const example = `ng g @nstudio/angular:elements menu --barrel=@mycompany/ui --components=menu,footer`;
const example = `nx g @nstudio/angular:elements menu --barrel=@mycompany/ui --components=menu,footer`;
if (!options.name) {
throw new SchematicsException(
missingArgument(
@@ -17,7 +17,7 @@ export default function(options: IHelperSchema) {
missingArgument(
'name',
'Provide the name of the helper to generate.',
'ng g @nstudio/angular:helpers applitools --target=web-myapp'
'nx g @nstudio/angular:helpers applitools --target=web-myapp'
)
);
}
@@ -15,7 +15,7 @@
},
"target": {
"type": "string",
"description": "Some helpers support targeting to generate the helper for a specific target. ie: ng g @nstudio/angular:helpers applitools --target=web-myapp"
"description": "Some helpers support targeting to generate the helper for a specific target. ie: nx g @nstudio/angular:helpers applitools --target=web-myapp"
}
},
"required": []
@@ -44,7 +44,7 @@ export default function(options: XplatElectrontHelpers.SchemaApp) {
missingArgument(
'name',
'Provide a name for your Electron app.',
'ng g @nstudio/electron-angular:app name'
'nx g @nstudio/electron-angular:app name'
)
);
}
@@ -53,7 +53,7 @@ export default function(options: XplatElectrontHelpers.SchemaApp) {
missingArgument(
'target',
'Provide the name of the web app in your workspace to use inside the electron app.',
'ng g @nstudio/electron-angular:app name --target web-myapp'
'nx g @nstudio/electron-angular:app name --target web-myapp'
)
);
}
@@ -43,7 +43,7 @@ export default function(options: XplatElectrontHelpers.SchemaApp) {
missingArgument(
'name',
'Provide a name for your Electron app.',
'ng g @nstudio/electron:app name'
'nx g @nstudio/electron:app name'
)
);
}
@@ -37,7 +37,7 @@ export default function(options: ApplicationOptions) {
missingArgument(
'name',
'Provide a name for your Ionic app.',
'ng g @nstudio/ionic-angular:app name'
'nx g @nstudio/ionic-angular:app name'
)
);
}
@@ -32,7 +32,7 @@ export default function(options: Schema) {
missingArgument(
'name',
'Provide a name for your Ionic app.',
'ng g @nstudio/ionic:app name'
'nx g @nstudio/ionic:app name'
)
);
}
@@ -38,7 +38,7 @@ export default function(options: Schema) {
missingArgument(
'name',
'Provide a name for your NativeScript app.',
'ng g @nstudio/nativescript-angular:app name'
'nx g @nstudio/nativescript-angular:app name'
)
);
}
@@ -34,7 +34,7 @@ export default function(options: Schema) {
missingArgument(
'name',
'Provide a name for your NativeScript app.',
'ng g @nstudio/nativescript:app name'
'nx g @nstudio/nativescript:app name'
)
);
}
@@ -18,7 +18,7 @@ export default function(options: IHelperSchema) {
missingArgument(
'name',
'Provide the name of the helper to generate.',
'ng g @nstudio/nativescript:helpers imports'
'nx g @nstudio/nativescript:helpers imports'
)
);
}
@@ -15,7 +15,7 @@
},
"target": {
"type": "string",
"description": "Some helpers support targeting to generate the helper for a specific target. ie: ng g @nstudio/nativescript:helpers imports"
"description": "Some helpers support targeting to generate the helper for a specific target. ie: nx g @nstudio/nativescript:helpers imports"
}
},
"required": []
@@ -29,6 +29,9 @@
"requirements": {},
"migrations": "./migrations.json"
},
"dependencies": {
"@nrwl/web": "^8.0.0"
},
"peerDependencies": {
"@nstudio/xplat": "*"
}
@@ -3,5 +3,6 @@ export * from './errors';
export * from './feature';
export * from './general';
export * from './helpers';
export * from './output';
export * from './postinstall';
export * from './xplat';
@@ -0,0 +1,193 @@
import chalk from 'chalk';

export interface CLIErrorMessageConfig {
title: string;
bodyLines?: string[];
slug?: string;
}

export interface CLIWarnMessageConfig {
title: string;
bodyLines?: string[];
slug?: string;
}

export interface CLILogMessageConfig {
title: string;
bodyLines?: string[];
}

export interface CLINoteMessageConfig {
title: string;
bodyLines?: string[];
}

export interface CLISuccessMessageConfig {
title: string;
}

/**
* Automatically disable styling applied by chalk if CI=true
*/
if (process.env.CI === 'true') {
chalk.level = 0;
}

class CLIOutput {
private readonly XPLAT_PREFIX = `${chalk.bold.bgKeyword('orange')(
'>'
)} ${chalk.bold.bgKeyword('orange')(' XPLAT ')}`;
/**
* Longer dash character which forms more of a continuous line when place side to side
* with itself, unlike the standard dash character
*/
private readonly VERTICAL_SEPARATOR =
'———————————————————————————————————————————————';

/**
* Expose some color and other utility functions so that other parts of the codebase that need
* more fine-grained control of message bodies are still using a centralized
* implementation.
*/
colors = {
gray: chalk.gray
};
bold = chalk.bold;
underline = chalk.underline;

private writeToStdOut(str: string) {
process.stdout.write(str);
}

private writeOutputTitle({
label,
title
}: {
label?: string;
title: string;
}): void {
let outputTitle: string;
if (label) {
outputTitle = `${this.XPLAT_PREFIX} ${label} ${title}\n`;
} else {
outputTitle = `${this.XPLAT_PREFIX} ${title}\n`;
}
this.writeToStdOut(outputTitle);
}

private writeOptionalOutputBody(bodyLines?: string[]): void {
if (!bodyLines) {
return;
}
this.addNewline();
bodyLines.forEach(bodyLine => this.writeToStdOut(' ' + bodyLine + '\n'));
}

addNewline() {
this.writeToStdOut('\n');
}

addVerticalSeparator() {
this.writeToStdOut(`\n${chalk.gray(this.VERTICAL_SEPARATOR)}\n\n`);
}

error({ title, slug, bodyLines }: CLIErrorMessageConfig) {
this.addNewline();

this.writeOutputTitle({
label: chalk.reset.inverse.bold.red(' ERROR '),
title: chalk.bold.red(title)
});

this.writeOptionalOutputBody(bodyLines);

/**
* Optional slug to be used in an error message redirect URL
*/
if (slug && typeof slug === 'string') {
this.addNewline();
this.writeToStdOut(
chalk.grey(' ' + 'Learn more about this error: ') +
'https://nstudio.io/xplat/errors' +
slug +
'\n'
);
}

this.addNewline();
}

warn({ title, slug, bodyLines }: CLIWarnMessageConfig) {
this.addNewline();

this.writeOutputTitle({
label: chalk.reset.inverse.bold.yellow(' WARNING '),
title: chalk.bold.yellow(title)
});

this.writeOptionalOutputBody(bodyLines);

/**
* Optional slug to be used in an warning message redirect URL
*/
if (slug && typeof slug === 'string') {
this.addNewline();
this.writeToStdOut(
chalk.grey(' ' + 'Learn more about this warning: ') +
'https://nstudio.io/xplat/errors' +
slug +
'\n'
);
}

this.addNewline();
}

note({ title, bodyLines }: CLINoteMessageConfig) {
this.addNewline();

this.writeOutputTitle({
label: chalk.reset.inverse.bold.keyword('orange')(' NOTE '),
title: chalk.bold.keyword('orange')(title)
});

this.writeOptionalOutputBody(bodyLines);

this.addNewline();
}

success({ title }: CLISuccessMessageConfig) {
this.addNewline();

this.writeOutputTitle({
label: chalk.reset.inverse.bold.green(' SUCCESS '),
title: chalk.bold.green(title)
});

this.addNewline();
}

logSingleLine(message: string) {
this.addNewline();

this.writeOutputTitle({
title: message
});

this.addNewline();
}

log({ title, bodyLines }: CLIWarnMessageConfig) {
this.addNewline();

this.writeOutputTitle({
title: chalk.white(title)
});

this.writeOptionalOutputBody(bodyLines);

this.addNewline();
}
}

export const output = new CLIOutput();
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import * as path from 'path';
import { promisify } from 'util';
import { output } from './output';

const fsExists = promisify(fs.exists);
const fsWriteFile = promisify(fs.writeFile);
@@ -121,7 +122,6 @@ export async function makePrettierIgnore() {
);

const prettierIgnore = `.DS_Store
**/webpack.config.js
**/package.json
**/package-lock.json
**/tslint.json
@@ -131,7 +131,7 @@ export async function makePrettierIgnore() {
**/xplat/*/.xplatframework
`;

if (!(await fsExists(prettierIgnorePath))) {
if (await fsExists(prettierIgnorePath)) {
console.log(`"${prettierIgnorePath}" already exists`);

// determine if extra rules are needed
@@ -140,9 +140,12 @@ export async function makePrettierIgnore() {
prettierContent.indexOf('**/apps/**/platforms/**/*') === -1 ||
prettierContent.indexOf('**/xplat/**/.xplatframework') === -1
) {
console.log(
`xplat is updating "${prettierIgnorePath}" with a few important extra rules. You may double-check the contents afterwards to ensure they meet your satisfaction`
);
output.log({
title: 'Note:',
bodyLines: [
`xplat is updating "${prettierIgnorePath}" with a few important extra rules. You may double-check the contents afterwards to ensure they meet your satisfaction.`
]
});
// update prettier to include the rules
await fsWriteFile(
prettierIgnorePath,

0 comments on commit 423aa49

Please sign in to comment.
You can’t perform that action at this time.