Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare extension for localization #15

Merged
merged 13 commits into from
Feb 18, 2020
10 changes: 1 addition & 9 deletions .azure-pipelines/common/build.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
steps:
- task: NodeTool@0
displayName: 'Use Node 10.x'
inputs:
versionSpec: 10.x

- task: Npm@1
displayName: 'npm install'

- task: Npm@1
displayName: 'Build'
inputs:
command: custom
customCommand: run build
customCommand: run ci-build
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
steps:
- task: Npm@1
displayName: 'Lint'
inputs:
command: custom
customCommand: run lint

- task: ComponentGovernanceComponentDetection@0
displayName: 'Component Detection'
condition: ne(variables['System.PullRequest.IsFork'], 'True')
2 changes: 1 addition & 1 deletion .azure-pipelines/common/publish-vsix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ steps:
displayName: 'Package'
inputs:
command: custom
customCommand: run package
customCommand: run ci-package

- task: CopyFiles@2
displayName: 'Copy vsix to staging directory'
Expand Down
8 changes: 8 additions & 0 deletions .azure-pipelines/common/setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
steps:
- task: NodeTool@0
displayName: 'Use Node 12.x'
inputs:
versionSpec: 12.x

- task: Npm@1
displayName: 'Install Dependencies'
8 changes: 4 additions & 4 deletions .azure-pipelines/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ jobs:
pool:
vmImage: windows-latest
steps:
- template: common/setup.yml
- template: common/build.yml
- template: common/lint.yml

- job: Linux
pool:
vmImage: ubuntu-latest
steps:
- template: common/build.yml
- template: common/setup.yml
- template: common/publish-vsix.yml # Only publish vsix from linux build since we use this to release and want to stay consistent
- template: common/lint.yml
- template: common/governance.yml

- job: macOS
pool:
vmImage: macOS-latest
steps:
- template: common/setup.yml
- template: common/build.yml
- template: common/lint.yml
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
gulpfile.ts
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
out
node_modules
.vscode-test/
package.nls.*.json
*.vsix
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Run Extension (Pseudo)",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"env": {
"VSCODE_DAPR_LOCALE": "pseudo"
},
"sourceMaps": true,
"stopOnEntry": false,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
},
{
"name": "Extension Tests",
"type": "extensionHost",
Expand Down
5 changes: 2 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
"tasks": [
{
"type": "npm",
"script": "watch",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"script": "build",
"problemMatcher": "$gulp-tsc",
"presentation": {
"reveal": "never"
},
Expand Down
21 changes: 21 additions & 0 deletions gulp-eslint.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
declare module 'gulp-eslint' {

interface ESLintResults {
errorCount: number;
length: number;
warningCount: number;
}

type ResultsCallback = (results: ESLintResults) => void;

interface ESLintFunc {
(): NodeJS.ReadWriteStream;
failAfterError(): NodeJS.ReadWriteStream;
format(): NodeJS.ReadWriteStream;
results(callback: ResultsCallback): NodeJS.ReadWriteStream;
}

const eslint: ESLintFunc;

export = eslint;
}
91 changes: 91 additions & 0 deletions gulpfile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import * as del from 'del';
import * as eslint from 'gulp-eslint';
import * as gulp from 'gulp';
import * as nls from 'vscode-nls-dev';
import * as sourcemaps from 'gulp-sourcemaps';
import * as ts from 'gulp-typescript';
import * as vsce from 'vsce';

const languages: nls.Language[] = [
{ folderName: 'jpn', id: 'ja' }
];

const tsProject = ts.createProject('./tsconfig.json');

function getOutDir(): string {
if (!tsProject.options.outDir) {
throw new Error('outDir is not defined in tsconfig.json.');
}

return tsProject.options.outDir;
}

function wrapThroughStream(stream: nls.ThroughStream): NodeJS.ReadWriteStream {
return (stream as unknown) as NodeJS.ReadWriteStream;
}

function cleanTask(): Promise<string[]> {
return del([getOutDir(), 'package.nls.*.json', 'vscode-dapr-*.vsix']);
}

function lintTaskFactory(warningsAsErrors?: boolean) {
return function lintTask() {
let pipeline = gulp.src(['src/**/*.ts'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());

if (warningsAsErrors) {
pipeline = pipeline
.pipe(eslint.results(
results => {
if (results.warningCount) {
throw new Error('ESLint generated warnings.');
}
}));
}

return pipeline;
}
}

function compileTask(): NodeJS.ReadWriteStream {
const outDir = getOutDir();

return tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject()).js
.pipe(wrapThroughStream(nls.rewriteLocalizeCalls()))
.pipe(wrapThroughStream(nls.createAdditionalLanguageFiles(languages, 'i18n', outDir)))
.pipe(sourcemaps.write('.', { includeContent: false, sourceRoot: './' }))
.pipe(gulp.dest(outDir));
}

function addI18nTask() {
return gulp.src(['package.nls.json'])
.pipe(wrapThroughStream(nls.createAdditionalLanguageFiles(languages, 'i18n')))
.pipe(gulp.dest('.'));
}

function vscePackageTask() {
return vsce.createVSIX();
}

const buildTask = gulp.series(cleanTask, compileTask, addI18nTask);

gulp.task('clean', cleanTask);

gulp.task('lint', lintTaskFactory());

gulp.task('build', buildTask);

gulp.task('package', gulp.series(buildTask, vscePackageTask));

gulp.task('ci-build', gulp.series(buildTask, lintTaskFactory(/* warningsAsErrors: */ true)));

gulp.task('ci-package', gulp.series(buildTask, lintTaskFactory(/* warningsAsErrors: */ true), vscePackageTask));

gulp.task('default', buildTask);
7 changes: 7 additions & 0 deletions i18n/jpn/package.i18n.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"vscode-dapr.applications.invoke-get.title": "(Japanese) Invoke (GET) application method",
"vscode-dapr.applications.invoke-post.title": "(Japanese) Invoke (POST) application method",
"vscode-dapr.applications.publish-message.title": "(Japanese) Publish message to application",
"vscode-dapr.tasks.scaffoldDaprTasks.title": "(Japanese) Scaffold Dapr Tasks",
"vscode-dapr.views.applications.name": "(Japanese) Applications"
}
Loading