Skip to content

Commit

Permalink
Initial version.
Browse files Browse the repository at this point in the history
  • Loading branch information
aloisdeniel committed Oct 4, 2018
1 parent 531f95c commit 47b4797
Show file tree
Hide file tree
Showing 29 changed files with 1,628 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

# Created by https://www.gitignore.io/api/node

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless


# End of https://www.gitignore.io/api/node

temp
3 changes: 3 additions & 0 deletions DETAILS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Flutter

This extension contains several tasks for **Flutter** projects.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# vsts-flutter-tasks

Flutter build tasks for Azure DevOps Pipelines/TFS.
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions package-lock.json

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

Binary file added tasks/build/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions tasks/build/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
100 changes: 100 additions & 0 deletions tasks/build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const task = require("vsts-task-lib/task");
const FLUTTER_TOOL_PATH_ENV_VAR = 'FlutterToolPath';
function main() {
return __awaiter(this, void 0, void 0, function* () {
// 1. Check flutter environment
var flutterPath = task.getVariable(FLUTTER_TOOL_PATH_ENV_VAR) || process.env[FLUTTER_TOOL_PATH_ENV_VAR];
flutterPath = path.join(flutterPath, "flutter");
if (!flutterPath) {
throw new Error(`The '${FLUTTER_TOOL_PATH_ENV_VAR}' environment variable must be set before using this task (you can use 'flutterinstall' task).`);
}
// 2. Clean if requested
let shouldClean = task.getBoolInput('clean', false);
if (shouldClean) {
task.debug(`Cleaning`);
clean(flutterPath);
}
// 3. Get target
let target = task.getInput('target', true);
// 4. Move current working directory to project
let projectDirectory = task.getPathInput('projectDirectory', false, false);
if (projectDirectory) {
task.debug(`Moving to ${projectDirectory}`);
task.cd(projectDirectory);
}
// 5. Get common input
let buildName = task.getInput('buildName', false);
let buildNumber = task.getInput('buildNumber', false);
// 6. Builds
if (target === "all" || target === "ios") {
let targetPlatform = task.getInput('iosTargetPlatform', false);
let codesign = task.getBoolInput('iosCodesign', false);
buildIpa(flutterPath, targetPlatform == "simulator", codesign, buildName, buildNumber);
}
if (target === "all" || target === "apk") {
let targetPlatform = task.getInput('apkTargetPlatform', false);
buildApk(flutterPath, targetPlatform, buildName, buildNumber);
}
});
}
function clean(flutter) {
return task.exec(flutter, ["clean"]);
}
function buildApk(flutter, targetPlatform, buildName, buildNumber) {
var args = [
"build",
"apk",
"--pub",
"--release"
];
if (targetPlatform) {
args.push("--target-platform");
args.push(targetPlatform);
}
if (buildName) {
args.push("--build-name");
args.push(buildName);
}
if (buildNumber) {
args.push("--build-number");
args.push(buildNumber);
}
return task.exec(flutter, args);
}
function buildIpa(flutter, simulator, codesign, buildName, buildNumber) {
var args = [
"build",
"ios",
"--pub",
"--release"
];
if (simulator) {
args.push("--simulator");
}
else if (codesign) {
args.push("--codesign");
}
if (buildName) {
args.push("--build-name");
args.push(buildName);
}
if (buildNumber) {
args.push("--build-number");
args.push(buildNumber);
}
return task.exec(flutter, args);
}
main().catch(error => {
task.setResult(task.TaskResult.Failed, error);
});
121 changes: 121 additions & 0 deletions tasks/build/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import * as path from "path";
import * as task from "vsts-task-lib/task";

const FLUTTER_TOOL_PATH_ENV_VAR: string = 'FlutterToolPath';

async function main(): Promise<void> {
try {
// 1. Check flutter environment
var flutterPath = task.getVariable(FLUTTER_TOOL_PATH_ENV_VAR) || process.env[FLUTTER_TOOL_PATH_ENV_VAR];
flutterPath = path.join(flutterPath, "flutter")
if(!flutterPath) {
throw new Error(`The '${FLUTTER_TOOL_PATH_ENV_VAR}' environment variable must be set before using this task (you can use 'flutterinstall' task).`);
}

// 2. Clean if requested
let shouldClean = task.getBoolInput('clean', false);
if(shouldClean) {
task.debug(`Cleaning`);
clean(flutterPath);
}

// 3. Get target
let target = task.getInput('target', true);

// 4. Move current working directory to project
let projectDirectory = task.getPathInput('projectDirectory', false, false);
if(projectDirectory) {
task.debug(`Moving to ${projectDirectory}`);
task.cd(projectDirectory);
}

// 5. Get common input
let buildName = task.getInput('buildName', false);
let buildNumber = task.getInput('buildNumber', false);

// 6. Builds
if(target === "all" || target === "ios") {
let targetPlatform = task.getInput('iosTargetPlatform', false);
let codesign = task.getBoolInput('iosCodesign', false);
buildIpa(flutterPath, targetPlatform == "simulator", codesign, buildName, buildNumber);
}

if(target === "all" || target === "apk") {
let targetPlatform = task.getInput('apkTargetPlatform', false);
buildApk(flutterPath, targetPlatform, buildName, buildNumber);
}

task.setResult(task.TaskResult.Succeeded, "Application built");
}
catch(err) {
task.setResult(task.TaskResult.Failed, err);
}
}

function clean(flutter: string) {
return task.exec(flutter, ["clean"]);
}

function buildApk(flutter: string, targetPlatform?: string, buildName?: string, buildNumber?: string) {

var args = [
"build",
"apk",
"--pub",
"--release"
];

if(targetPlatform) {
args.push("--target-platform");
args.push(targetPlatform);
}

if(buildName) {
args.push("--build-name");
args.push(buildName);
}

if(buildNumber) {
args.push("--build-number");
args.push(buildNumber);
}

if(task.exec(flutter, args) !== 0) {
throw new Error("apk build failed");
}
}

function buildIpa(flutter: string, simulator?: boolean, codesign?: boolean,buildName?: string, buildNumber?: string) {

var args = [
"build",
"ios",
"--pub",
"--release"
];

if(simulator) {
args.push("--simulator");
}
else if(codesign) {
args.push("--codesign");
}

if(buildName) {
args.push("--build-name");
args.push(buildName);
}

if(buildNumber) {
args.push("--build-number");
args.push(buildNumber);
}

if(task.exec(flutter, args) !== 0) {
throw new Error("ios build failed");
}
}

main().catch(error => {
task.setResult(task.TaskResult.Failed, error);
});
Loading

0 comments on commit 47b4797

Please sign in to comment.