fix: exclude docs from packages

Fixes #11
This commit is contained in:
Karl-Philipp Wulfert
2019-04-15 15:00:03 +02:00
parent 2c70896c1c
commit d7b6ecb734
3 changed files with 48 additions and 10 deletions

View File

@@ -5,7 +5,6 @@
!.editorconfig
!.gitignore
!.npmignore
!docs
!lib
lib/tsconfig.tsbuildinfo
!LICENSE

View File

@@ -16,7 +16,7 @@ import chalk from 'chalk';
import {execSync} from 'child_process';
import * as commander from 'commander';
import {copyFileSync, existsSync, readFileSync, writeFileSync} from 'fs';
import {resolve, sep} from 'path';
import {join, resolve, sep} from 'path';
import {cwd} from 'process';
import {isDeepStrictEqual} from 'util';
import {parse, stringify} from 'yaml';
@@ -56,6 +56,8 @@ function consoleLog(...args: string[]): void {
const currentWorkingDirectory = cwd();
let suggestOverwrite = false;
// configure commander
commander
.version(JSON.parse(readFileSync(resolve(__dirname, '..', 'package.json')).toString()).version)
@@ -120,7 +122,7 @@ NEEDED_FILES.forEach((file) => {
// remove templates directory for destination files
if (destinationFile.indexOf('templates') === 0) {
destinationFile = destinationFile.split(sep).slice(1).join(sep);
file = `templates/template-${destinationFile}`;
file = join('templates', `template-${destinationFile}`);
}
const source = resolve(__dirname, '..', file);
@@ -130,6 +132,37 @@ NEEDED_FILES.forEach((file) => {
if (!existsSync(destination) || commander.replace) {
copyFileSync(source, destination);
consoleInfo(`Copied file "${source}" to "${destination}".`);
} else if (destinationFile === '.npmignore') {
const npmIgnore = readFileSync(destination).toString();
const ignoredPatterns = npmIgnore.split('\n');
let ignoresEverything = false;
let unignoresDocs = false;
for (const ignoredPattern of ignoredPatterns) {
if (ignoredPattern === '/*') {
ignoresEverything = true;
}
if (ignoredPattern === '!docs') {
unignoresDocs = true;
}
}
if (!ignoresEverything) {
consoleWarn(`'.npmignore' should have '/*' as first pattern to ignore everything.`);
suggestOverwrite = true;
}
if (unignoresDocs) {
consoleWarn(`'.npmignore' contains '!docs' and thus the package will contain the documentation.
Please double check that this is desired behavior since the docs can become huge:
https://gitlab.com/openstapps/configuration/issues/11`);
suggestOverwrite = true;
}
}
});
@@ -141,9 +174,11 @@ if (typeof packageJson.devDependencies === 'object' && Object.keys(packageJson.d
packageJsonChanged = true;
consoleInfo(`Added NYC configuration in "${packageJsonPath}".`);
consoleLog(`Added NYC configuration in "${packageJsonPath}".`);
} else if (!isDeepStrictEqual(packageJson.nyc, NYC_CONFIGURATION)) {
consoleLog(`NYC configuration differs from the proposed one. Please check manually...`);
consoleInfo(`NYC configuration in '${packageJsonPath}' differs from the proposed one. Please check manually...`);
suggestOverwrite = true;
}
}
@@ -163,9 +198,9 @@ Object.keys(SCRIPTS).forEach((scriptName) => {
packageJsonChanged = true;
consoleInfo(`Added "${scriptName}" script to "${packageJsonPath}".`);
consoleInfo(`Added '${scriptName}' script to '${packageJsonPath}'.`);
} else if (typeof scriptToCheck === 'string' && scriptToCheck !== SCRIPTS[scriptName]) {
consoleWarn(`NPM script "${scriptName}" should be "${SCRIPTS[scriptName].replace('\n', '\\n')}".`);
consoleWarn(`NPM script '${scriptName}' should be "${SCRIPTS[scriptName].replace('\n', '\\n')}".`);
}
});
@@ -186,7 +221,7 @@ for (let author of execBuffer.toString().split('\n')) {
}));
if (!authorIsAttributed) {
consoleInfo(`'${author}' should be attributed as author or contributor.`);
consoleWarn(`'${author}' should be attributed as author or contributor.`);
}
}
@@ -225,4 +260,9 @@ if (packageJsonChanged) {
consoleLog(`Changes were written to "${packageJsonPath}".`);
}
consoleLog('Done.');
if (suggestOverwrite) {
consoleInfo(`You should consider to overwrite your configuration files and check for intended derivations:
npm run check-configuration -- -r`);
}
consoleLog(`Done checking the configuration in '${path}'.`);

View File

@@ -2,7 +2,6 @@
# See https://stackoverflow.com/a/29932318
/*
# Except these files/folders
!docs
!lib
lib/tsconfig.tsbuildinfo
!LICENSE