npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ti-slag

v0.0.26

Published

Titanium faker API, Titanium app running on Node.js.

Downloads

38

Readme

ti-slag

Titanium faker API, Titanium app running on Node.js.

Build Status Coverage Status Dependency Status devDependency Status

WORKING IN PROGRESS If vm crash, Please feedback with the code you run :smile:

Why

  • Want running code of Titanium on Node.js
  • Want to run a unit test in Node.js only
  • Not required simulator/emulator and iOS/Android device

Tasks

  • ~~Full support of Alloy~~
  • ~~Full support of native module~~
  • gulp plugin
  • ~~Test~~

Programmatically

Setup

$ cd path/to/your_app_project
$ npm install ti-slag --save

Using

var path = require('path'),
	slag = require('ti-slag');

slag(path.join(__dirname, 'Resources', 'app.js'), {
	titanium: '4.0.0.GA',
	platform: 'ios'
});

API

IMPORTANT arguments chenged, since 0.0.7

object <vm.context> slag(string <file path>, object <options>)

Classic

slag(path.join(__dirname, 'Resources', 'app.js'), {
	titanium: '4.0.0.GA',
	platform: 'ios'
});

Alloy

Please be Alloy compiled before. $ alloy compile --config platform=ios or $ alloy compile --config platform=android

	var alloy = require('ti-slag/lib/Alloy'),
		Alloy = alloy.load({
			titanium: '4.0.0.GA',							// optional, default 4.0.0.GA
			platform: 'ios',								// optional, default ios
			alloy: 'path/to/alloy.js',						// optional, default Resources/iphone/alloy/alloy.js
			BaseController: 'path/to/BaseController.js',	// optional, default Resources/iphone/alloy/controllers/BaseController.js
			underscore: 'path/to/underscore.js',			// optional, default Resources/iphone/alloy/underscore.js
			backbone: 'path/to/backbone.js',				// optional, default Resources/iphone/alloy/backbone.js
			constants: 'path/to/constants.js',				// optional, default Resources/iphone/alloy/constants.js
			CFG: 'path/to/CFG.js'							// optional, default Resources/alloy/CFG.js
		}),
		context = slag(path.join(__dirname, 'Resources', 'iphone', 'alloy', 'controllers', 'index.js'), {
			titanium:'4.0.0.GA',
			platform: 'ios',
			module: {
				alloy: Alloy.core,
				'alloy/controllers/BaseController': Alloy.BaseController
			}
		});

	context.Controller(); // This is Alloy controller

~~ti-slag stop the Alloy internal support, since 0.0.14.~~ Alloy loader now support, since 0.0.15.

file path

path/to/example.js

Titanium SDK version
  • 5.2.0.GA
  • 4.1.0.GA
  • 4.0.0.GA
  • 3.5.1.GA
platform
  • ios
  • android
device

Load the device profile.

slag(path.join(__dirname, 'Resources', 'app.js'), {
	titanium: '4.0.0.GA',
	platform: 'ios',
	device: require('ti-slag/lib/device').iPhone5s
});

Your device profile format.

e.g.

var profile = {
	name: 'iPhone OS',
	osname: 'iphone',
	model: 'Simulator',
	version: '8.4',
	architecture: 'x86_64',
	ostype: '64bit',
	displayCaps: {
		density: 'high',
		dpi: 320,
		platformWidth: 320,
		platformHeight: 568
	}
};
module

Native or CommonJS module simulate.

Titanium code
var anymodule = require('be.k0suke.anymodule'),
	anything = anymodule.createAnything();

anything.anyMethod();
ti-slag code
slag('path/to/app.js', {
	titanium: '4.0.0.GA',
	platform: 'ios',
	module: {
		'be.k0suke.anymodule': {
			createAnything: function(){
				return this;
			},
			anyMethod: function(){}
		}
	}
});
strict mode

It throws an exception If you use a custom property.

  • false
  • true (default)
silent

console.*, Ti.API.*, alert quiet.

  • false (default)
  • true
coverage
  • false (default)
  • true

Testing in mocha

And coverage.

Install the mocha, nyc and ti-slag

$ npm install mocha nyc ti-slag --save-dev

Edit the package.json

{
	...
	"scripts": {
		"test": "mocha test.js",
		"coverage": "nyc npm test && nyc report"
	},
	"config": {
		"nyc": {
			"exclude": [
				"test.js",
				"node_modules/",
				"app/"
			]
		}
	},
	...
}

test.js

var assert = require('assert'),
	path = require('path'),
	slag = require('ti-slag');

describe('foo.js', function(){
	it('should does not throw exception', function(){
		assert.doesNotThrow(function(){
			slag(path.join(__dirname, 'Resources', 'foo.js'), {
				titanium: '4.0.0.GA',
				platform: 'ios'
			});
		});
	});
});

Run the test

$ npm test

Result

> [email protected] test /Users/Kosuke/src/Sandbox
> mocha test.js



  foo.js
    ✓ should does not throw exception


  1 passing (18ms)

Coverage

Edit the test.js

var istanbul = require('istanbul'),
	collector = new istanbul.Collector(),
	reporter = new istanbul.Reporter();

describe('example test', function(){
	it('should does not throw exception', function(){
		assert.doesNotThrow(function(){
			var context = slag('path/to/app.js', {
				titanium: '4.0.0.GA',
				platform: 'ios',
				coverage: true
			});
			collector.add(context.__coverage__);

			reporter.add('text');
			reporter.addAll([ 'lcov', 'clover' ]);
			reporter.write(collector, true);
		});
	});
});

CLI

Install

$ npm install ti-slag -g

Usage

$ cd path/to/your_app_project
$ slag --sdk 4.0.0.GA --platform ios

Generate the faker API

If you want other Titanium SDK version, See the furnace.js. And required api.json.

License

MIT