Skip to content

Commit

Permalink
Merge pull request #26 from fossamagna/support-typescript
Browse files Browse the repository at this point in the history
Add Support TypeScript
  • Loading branch information
fossamagna committed Aug 12, 2018
2 parents dccc1fc + 47922a5 commit f9297bc
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# generator-gas [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage percentage][coveralls-image]][coveralls-url]
>
> Generator for Google Apps Script Project.
You can choose transpiler to local development which of the following:

- TypeScript
- Babel

## Installation

Expand Down
8 changes: 6 additions & 2 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ const helpers = require('yeoman-test');
describe('generator-gas:app', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../generators/app'))
.withPrompts({someAnswer: true});
.run(path.join(__dirname, '../generators/app'))
.withPrompts({
appName: 'test-app',
githubUsername: 'fossamagna',
transpiler: 'babel'
});
});

it('creates files', () => {
Expand Down
39 changes: 39 additions & 0 deletions __tests__/babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

describe('generator-gas:babel', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../generators/babel'))
.withOptions({
appName: 'test-app',
githubUsername: 'fossamagna',
name: 'Full Name',
email: 'fossamagna2@gmail.com'
});
});

it('creates files', () => {
assert.file([
'.babelrc',
'.gitignore',
'package.json',
'.clasp.json',
'.eslintrc.json',
'README.md',
'src/index.js',
'src/hello.js'
]);

assert.jsonFileContent('package.json', {
name: 'test-app',
repository: 'fossamagna/test-app',
author: {
name: 'Full Name',
email: 'fossamagna2@gmail.com'
}
});
});
});
39 changes: 39 additions & 0 deletions __tests__/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

describe('generator-gas:typescript', () => {
beforeAll(() => {
return helpers
.run(path.join(__dirname, '../generators/typescript'))
.withOptions({
appName: 'test-app',
githubUsername: 'fossamagna',
name: 'Full Name',
email: 'fossamagna2@gmail.com'
});
});

it('creates files', () => {
assert.file([
'.gitignore',
'package.json',
'.clasp.json',
'README.md',
'src/index.ts',
'src/hello.ts',
'src/shim.d.ts',
'tsconfig.json',
]);

assert.jsonFileContent('package.json', {
name: 'test-app',
repository: 'fossamagna/test-app',
author: {
name: 'Full Name',
email: 'fossamagna2@gmail.com'
}
});
});
});
19 changes: 18 additions & 1 deletion generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ module.exports = class extends Generator {
validate: val => {
return val.length > 0 ? true : 'You have to provide a username';
}
},
{
type: 'list',
name: 'transpiler',
message: 'What do the transpiler use in your app?',
default: 'typescript',
choices: [
{
name: 'TypeScript',
value: 'typescript'
},
{
name: 'Babel',
value: 'babel'
}
]
}
];

Expand All @@ -36,7 +52,8 @@ module.exports = class extends Generator {
}

configuring() {
this.composeWith(require.resolve('../babel'), {
const transpiler = this.props.transpiler;
this.composeWith(require.resolve(`../${transpiler}`), {
appName: this.props.appName,
githubUsername: this.props.githubUsername,
name: this.user.git.name(),
Expand Down
38 changes: 38 additions & 0 deletions generators/typescript/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict';
const Generator = require('yeoman-generator');

module.exports = class extends Generator {

constructor(args, opts) {
super(args, opts);
}

writing() {
this.fs.copyTpl(
this.templatePath('**'),
this.destinationPath(),
{
appName: this.options.appName,
githubUsername: this.options.githubUsername,
name: this.options.name,
email: this.options.email
}
);
this.fs.move(
this.destinationPath('_package.json'),
this.destinationPath('package.json')
);
this.fs.move(
this.destinationPath('_gitignore'),
this.destinationPath('.gitignore')
);
this.fs.move(
this.destinationPath('_clasp.json'),
this.destinationPath('.clasp.json')
);
}

install() {
this.installDependencies({bower: false});
}
};
26 changes: 26 additions & 0 deletions generators/typescript/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# <%= appName %>

Google Apps Script Application with [Browserify](http://browserify.org) + [TypeScript](https://www.typescriptlang.org/).

# For Local Development

For Apps Script local development, You need to be enable Apps Script API: https://script.google.com/home/usersettings. This project will be use [clasp](https://github.com/google/clasp) to push Apps Script Project.

.clasp.json:
```json
{
"scriptId": "<YOUR_SCRIPT_ID>",
"rootDir": "dist"
}
```

Please see [clasp](https://github.com/google/clasp) and [Command Line Interface using clasp](https://developers.google.com/apps-script/guides/clasp) for details.

# Deploy

```sh
$ npm run deploy
```

* Server JavaScript files will be compiled by Browserify and [gasify](https://www.npmjs.com/package/gasify).
* Sync compiled `Code.js` to Google Apps Script Project in Google Drive by clasp.
4 changes: 4 additions & 0 deletions generators/typescript/templates/_clasp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"scriptId": "<YOUR_SCRIPT_ID>",
"rootDir": "dist"
}
2 changes: 2 additions & 0 deletions generators/typescript/templates/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
dist
46 changes: 46 additions & 0 deletions generators/typescript/templates/_package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "<%= appName %>",
"version": "1.0.0",
"description": "Google Apps Script Application with Browserify + TypeScript",
"main": "index.js",
"scripts": {
"test": "eslint src",
"clean": "rimraf dist",
"initialize": "mkdirp dist",
"watch": "npm-run-all initialize -p watch:gs",
"prefetch:manifest": "npm-run-all initialize",
"fetch:manifest": "clasp pull",
"postfetch:manifest": "cpx ./dist/appsscript.json ./src/appsscript.json",
"prebuild:gs": "cpx ./src/appsscript.json ./dist/appsscript.json",
"build:gs":
"browserify ./src/index.ts -p tsify -p gasify -o ./dist/Code.js",
"watch:gs": "watchify ./src/index.ts -p tsify -p gasify -o ./dist/Code.js",
"build": "npm-run-all clean initialize build:gs",
"upload": "claps push",
"deploy": "npm-run-all build upload"
},
"keywords": ["google", "apps-script"],
"author": {
"name": "<%= name %>",
"email": "<%= email %>"
},
"repository": "<%= githubUsername %>/<%= appName %>",
"license": "MIT",
"devDependencies": {
"@types/google-apps-script": "0.0.27",
"@google/clasp": "1.4.0",
"browserify": "16.2.2",
"browserify-shim": "3.8.13",
"cpx": "1.5.0",
"eslint": "5.2.0",
"gasify": "0.1.2",
"mkdirp": "0.5.1",
"npm-run-all": "4.1.3",
"onchange": "4.1.0",
"rimraf": "2.4.4",
"tsify": "4.0.0",
"typescript": "3.0.1",
"watch": "1.0.2",
"watchify": "3.6.1"
}
}
4 changes: 4 additions & 0 deletions generators/typescript/templates/src/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export default function helloWorldMessage() {
Logger.log('hello world');
}

2 changes: 2 additions & 0 deletions generators/typescript/templates/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import hello from './hello';
global.hello = hello;
1 change: 1 addition & 0 deletions generators/typescript/templates/src/shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare var global: any;
17 changes: 17 additions & 0 deletions generators/typescript/templates/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"outDir": "./dist",
"target": "es3",
"module": "commonjs",
"declaration": true,
"sourceMap": true,
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true
},
"compileOnSave": true,
"rootDir": "src",
"include": ["./src/**/*"]
}

0 comments on commit f9297bc

Please sign in to comment.