Skip to content

Commit

Permalink
When using TypeScript, perform an initial build run
Browse files Browse the repository at this point in the history
Fixes #27
  • Loading branch information
AlCalzone committed Dec 16, 2018
1 parent 5efb180 commit fea113b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## __WORK_IN_PROGRESS__
* (AlCalzone) When using TypeScript, perform an initial build run (fixes #27)
* (AlCalzone) When formatting files, clear lines with only whitespace (fixes #30)
* (AlCalzone) Enable resolveJsonModule for JS files (fixes #26)
* (AlCalzone) Allow choosing quote style in JavaScript (#34)
Expand Down
41 changes: 29 additions & 12 deletions build/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,45 @@ async function ask() {
}
return answers;
}
let currentStep = 0;
let maxSteps = 1;
function logProgress(message) {
console.log(ansi_colors_1.blueBright(`[${++currentStep}/${maxSteps}] ${message}...`));
}
/** Whether dependencies should be installed */
const installDependencies = !yargs.argv.noInstall || !!yargs.argv.install;
/** Whether an initial build should be performed */
let buildTypeScript;
/** CLI-specific functionality for creating the adapter directory */
async function setupProject_CLI({ answers, files }) {
async function setupProject_CLI(answers, files) {
const rootDirName = path.basename(rootDir);
// make sure we are working in a directory called ioBroker.<adapterName>
const targetDir = rootDirName.toLowerCase() === `iobroker.${answers.adapterName.toLowerCase()}`
? rootDir : path.join(rootDir, `ioBroker.${answers.adapterName}`);
await createAdapter_1.writeFiles(targetDir, files);
if (!yargs.argv.noInstall || !!yargs.argv.install) {
console.log(ansi_colors_1.blueBright("[2/2] Installing dependencies..."));
if (installDependencies) {
logProgress("Installing dependencies");
await tools_1.executeCommand(tools_1.isWindows ? "npm.cmd" : "npm", ["install", "--quiet"], { cwd: targetDir });
if (buildTypeScript) {
logProgress("Compiling TypeScript");
await tools_1.executeCommand(tools_1.isWindows ? "npm.cmd" : "npm", ["run", "build"], { cwd: targetDir, stdout: "ignore" });
}
}
console.log();
console.log(ansi_colors_1.blueBright("All done! Have fun programming! ") + ansi_colors_1.red("♥"));
}
ask()
.then(async (answers) => {
console.log(ansi_colors_1.blueBright("[1/2] Generating files..."));
return {
answers,
files: await createAdapter_1.createFiles(answers),
};
})
.then(setupProject_CLI);
(async function main() {
const answers = await ask();
if (installDependencies) {
maxSteps++;
buildTypeScript = answers.language === "TypeScript";
if (buildTypeScript)
maxSteps++;
}
logProgress("Generating files");
const files = await createAdapter_1.createFiles(answers);
await setupProject_CLI(answers, files);
})();
process.on("exit", () => {
if (fs.pathExistsSync("npm-debug.log"))
fs.removeSync("npm-debug.log");
Expand Down
1 change: 1 addition & 0 deletions build/templates/tsconfig.build.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = (answers => {
// Modified config to only compile .ts-files in the src dir
"compilerOptions": {
"allowJs": false,
"checkJs": false,
"noEmit": false,
"declaration": false
},
Expand Down
47 changes: 34 additions & 13 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,32 +55,53 @@ async function ask() {
return answers as Answers;
}

let currentStep: number = 0;
let maxSteps: number = 1;
function logProgress(message: string) {
console.log(blueBright(`[${++currentStep}/${maxSteps}] ${message}...`));
}

/** Whether dependencies should be installed */
const installDependencies = !yargs.argv.noInstall || !!yargs.argv.install;
/** Whether an initial build should be performed */
let buildTypeScript: boolean;

/** CLI-specific functionality for creating the adapter directory */
async function setupProject_CLI({ answers, files }: { answers: Answers, files: File[] }) {
async function setupProject_CLI(answers: Answers, files: File[]) {
const rootDirName = path.basename(rootDir);
// make sure we are working in a directory called ioBroker.<adapterName>
const targetDir = rootDirName.toLowerCase() === `iobroker.${answers.adapterName.toLowerCase()}`
? rootDir : path.join(rootDir, `ioBroker.${answers.adapterName}`)
;
await writeFiles(targetDir, files);

if (!yargs.argv.noInstall || !!yargs.argv.install) {
console.log(blueBright("[2/2] Installing dependencies..."));
if (installDependencies) {
logProgress("Installing dependencies");
await executeCommand(isWindows ? "npm.cmd" : "npm", ["install", "--quiet"], { cwd: targetDir });

if (buildTypeScript) {
logProgress("Compiling TypeScript");
await executeCommand(isWindows ? "npm.cmd" : "npm", ["run", "build"], { cwd: targetDir, stdout: "ignore" });
}
}
console.log();
console.log(blueBright("All done! Have fun programming! ") + red("♥"));
}

ask()
.then(async answers => {
console.log(blueBright("[1/2] Generating files..."));
return {
answers,
files: await createFiles(answers),
};
})
.then(setupProject_CLI)
;
(async function main() {
const answers = await ask();

if (installDependencies) {
maxSteps++;
buildTypeScript = answers.language === "TypeScript";
if (buildTypeScript) maxSteps++;
}

logProgress("Generating files");
const files = await createFiles(answers);

await setupProject_CLI(answers, files);
})();

process.on("exit", () => {
if (fs.pathExistsSync("npm-debug.log")) fs.removeSync("npm-debug.log");
Expand Down
1 change: 1 addition & 0 deletions src/templates/tsconfig.build.json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export = (answers => {
// Modified config to only compile .ts-files in the src dir
"compilerOptions": {
"allowJs": false,
"checkJs": false,
"noEmit": false,
"declaration": false
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Modified config to only compile .ts-files in the src dir
"compilerOptions": {
"allowJs": false,
"checkJs": false,
"noEmit": false,
"declaration": false
},
Expand Down

0 comments on commit fea113b

Please sign in to comment.