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

feat(rosetta): extract and compile samples into "tablets" #925

Merged
merged 24 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d990d68
feat(rosetta): extract and compile samples into "tablets"
rix0rrr Oct 31, 2019
7a0bd5c
Update some expectations
Nov 1, 2019
b90923f
WIP
Nov 1, 2019
2c6f2a3
Make `extract` use worker threads if available
Nov 1, 2019
78cbf8f
Update README
Nov 4, 2019
b34d736
Review comments
rix0rrr Nov 7, 2019
51a6bae
Try to make Python build succeed from a dirty state
rix0rrr Nov 7, 2019
d3b82c0
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 11, 2019
224037f
Missing &&
Nov 11, 2019
8a0d470
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 11, 2019
5380991
Fix pacmak unified build sanity
Nov 12, 2019
6efc55c
Render HTML comments as-is
Nov 12, 2019
965848f
Add backwards compatible support for literate examples
Nov 12, 2019
db49b0e
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 12, 2019
b059c5c
Fix dependencies on packages outside the compile set
Nov 12, 2019
c489266
Use the right output dir for source-only mode
Nov 12, 2019
d30c3ef
Add test for different pacmak build modes
Nov 12, 2019
9e97489
Only include existing directories
Nov 13, 2019
4eb11e3
Satisfy eslint
Nov 13, 2019
c81f1cc
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 13, 2019
42512e2
Handle @ signs in examples
Nov 13, 2019
34a397a
Merge remote-tracking branch 'origin/master' into huijbers/extract-sa…
Nov 13, 2019
9f597f3
Satisfy eslint
Nov 13, 2019
a63e55e
Don't report diagnostics originating from hidden source
Nov 13, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ tsconfig.tsbuildinfo
dist/
.vscode
*.tsbuildinfo
.jsii-samples.tabl
3 changes: 2 additions & 1 deletion packages/jsii-calc-base-of-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta extract",
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
"test": "diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
"devDependencies": {
"jsii": "^0.20.0",
"jsii-rosetta": "^0.20.0",
"jsii-build-tools": "^0.20.0"
},
"jsii": {
Expand Down
5 changes: 3 additions & 2 deletions packages/jsii-calc-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta extract",
"test": "diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
Expand All @@ -36,6 +36,7 @@
},
"devDependencies": {
"jsii": "^0.20.0",
"jsii-rosetta": "^0.20.0",
"jsii-build-tools": "^0.20.0"
},
"jsii": {
Expand All @@ -59,4 +60,4 @@
},
"versionFormat": "short"
}
}
}
5 changes: 3 additions & 2 deletions packages/jsii-calc-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta extract",
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
"test": "diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
},
Expand All @@ -38,6 +38,7 @@
},
"devDependencies": {
"jsii": "^0.20.0",
"jsii-rosetta": "^0.20.0",
"jsii-build-tools": "^0.20.0"
},
"jsii": {
Expand All @@ -63,4 +64,4 @@
},
"versionFormat": "short"
}
}
}
17 changes: 12 additions & 5 deletions packages/jsii-calc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

This library is used to demonstrate and test the features of JSII

## Sphinx
## How to use running sum API:

This file will be incorporated into the sphinx documentation.
First, create a calculator:

If this file starts with an "H1" line (in our case `# jsii Calculator`), this
heading will be used as the Sphinx topic name. Otherwise, the name of the module
(`jsii-calc`) will be used instead.
```ts
const calculator = new calc.Calculator();
```

Then call some operations:


```ts fixture=with-calculator
calculator.add(10);
```

## Code Samples

Expand Down
5 changes: 3 additions & 2 deletions packages/jsii-calc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
"build": "jsii",
"build": "jsii && jsii-rosetta extract --compile",
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
"watch": "jsii -w",
"test": "node test/test.calc.js && diff-test test/assembly.jsii .jsii",
"test:update": "npm run build && UPDATE_DIFF=1 npm run test"
Expand All @@ -43,6 +43,7 @@
},
"devDependencies": {
"jsii": "^0.20.0",
"jsii-rosetta": "^0.20.0",
"jsii-build-tools": "^0.20.0"
},
"jsii": {
Expand Down Expand Up @@ -100,4 +101,4 @@
]
}
]
}
}
3 changes: 3 additions & 0 deletions packages/jsii-calc/rosetta/default.ts-fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import calc = require('.');

/// here
4 changes: 4 additions & 0 deletions packages/jsii-calc/rosetta/with-calculator.ts-fixture
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import calc = require('.');
const calculator = new calc.Calculator();

/// here
4 changes: 2 additions & 2 deletions packages/jsii-calc/test/assembly.jsii
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@
},
"name": "jsii-calc",
"readme": {
"markdown": "# jsii Calculator\n\nThis library is used to demonstrate and test the features of JSII\n\n## Sphinx\n\nThis file will be incorporated into the sphinx documentation.\n\nIf this file starts with an \"H1\" line (in our case `# jsii Calculator`), this\nheading will be used as the Sphinx topic name. Otherwise, the name of the module\n(`jsii-calc`) will be used instead.\n\n## Code Samples\n\n```ts\n/* This is totes a magic comment in here, just you wait! */\nconst foo = 'bar';\n```\n"
"markdown": "# jsii Calculator\n\nThis library is used to demonstrate and test the features of JSII\n\n## How to use running sum API:\n\nFirst, create a calculator:\n\n```ts\nconst calculator = new calc.Calculator();\n```\n\nThen call some operations:\n\n\n```ts fixture=with-calculator\ncalculator.add(10);\n```\n\n## Code Samples\n\n```ts\n/* This is totes a magic comment in here, just you wait! */\nconst foo = 'bar';\n```\n"
},
"repository": {
"directory": "packages/jsii-calc",
Expand Down Expand Up @@ -10328,5 +10328,5 @@
}
},
"version": "0.20.0",
"fingerprint": "Gk2mbYSx8tmjrVf/JBPBkNEFEEG9i7jx9ptKC/0sCpE="
"fingerprint": "WJ8fpBsH7sWh1h86kE1fgaNJf6nLjw6uq0p/aTcpoJY="
}
23 changes: 21 additions & 2 deletions packages/jsii-pacmak/bin/jsii-pacmak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import path = require('path');
import process = require('process');
import yargs = require('yargs');
import { Rosetta } from 'jsii-rosetta';
import logging = require('../lib/logging');
import { Timers } from '../lib/timer';
import { VERSION_DESC } from '../lib/version';
Expand Down Expand Up @@ -78,6 +79,15 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';
desc: 'Auto-update .npmignore to exclude the output directory and include the .jsii file',
default: true
})
.option('samples-tablet', {
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
eladb marked this conversation as resolved.
Show resolved Hide resolved
type: 'string',
desc: 'Location of a jsii-rosetta tablet with sample translations (created using \'jsii-rosetta extract\')'
rix0rrr marked this conversation as resolved.
Show resolved Hide resolved
})
.option('live-translation', {
type: 'boolean',
desc: 'Translate code samples on-the-fly if they can\'t be found in the samples tablet',
default: true
})
.version(VERSION_DESC)
.strict()
.argv;
Expand All @@ -89,6 +99,11 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';

const timers = new Timers();

const rosetta = new Rosetta({ liveConversion: argv['live-translation'] });
if (argv['samples-tablet']) {
await rosetta.loadTabletFromFile(argv['samples-tablet']);
}

const modulesToPackage = await findJsiiModules(argv._, argv.recurse);
logging.info(`Found ${modulesToPackage.length} modules to package`);
if (modulesToPackage.length === 0) {
Expand All @@ -114,9 +129,12 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';
});

await timers.recordAsync('load jsii', () => {
logging.info('Loading jsii assemblies');
logging.info('Loading jsii assemblies and translations');
return Promise.all(modulesToPackage
.map(m => m.load()));
.map(async m => {
await m.load();
await rosetta.addAssembly(m.assembly.spec, m.moduleDirectory);
}));
});

try {
Expand Down Expand Up @@ -163,6 +181,7 @@ import { ALL_BUILDERS, TargetName } from '../lib/targets';
await builder.buildModules(modules, {
clean: argv.clean,
codeOnly: argv['code-only'],
rosetta,
force: argv.force,
fingerprint: argv.fingerprint,
arguments: argv,
Expand Down
9 changes: 8 additions & 1 deletion packages/jsii-pacmak/lib/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import logging = require('./logging');
import { JsiiModule } from './packaging';
import { TargetConstructor, Target } from './target';
import { Scratch } from './util';
import { Rosetta } from 'jsii-rosetta';

export interface BuildOptions {
/**
Expand Down Expand Up @@ -36,6 +37,11 @@ export interface BuildOptions {
* Whether to add an additional subdirectory for the target language
*/
languageSubdirectory?: boolean;

/**
* The Rosetta instance to load examples from
*/
rosetta: Rosetta;
}

/**
Expand Down Expand Up @@ -110,7 +116,8 @@ export class OneByOneBuilder implements TargetBuilder {
assembly: module.assembly,
fingerprint: options.fingerprint,
force: options.force,
arguments: options.arguments
arguments: options.arguments,
rosetta: options.rosetta,
});
}

Expand Down
6 changes: 6 additions & 0 deletions packages/jsii-pacmak/lib/target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path = require('path');
import { IGenerator } from './generator';
import logging = require('./logging');
import { resolveDependencyDirectory } from './util';
import { Rosetta } from 'jsii-rosetta';


export abstract class Target {
Expand All @@ -15,12 +16,14 @@ export abstract class Target {
protected readonly arguments: { [name: string]: any };
protected readonly targetName: string;
protected readonly assembly: reflect.Assembly;
protected readonly rosetta: Rosetta;

protected abstract readonly generator: IGenerator;

public constructor(options: TargetOptions) {
this.packageDir = options.packageDir;
this.assembly = options.assembly;
this.rosetta = options.rosetta;
this.fingerprint = options.fingerprint != null ? options.fingerprint : true;
this.force = options.force != null ? options.force : false;
this.arguments = options.arguments;
Expand Down Expand Up @@ -173,6 +176,9 @@ export interface TargetOptions {
/** The JSII-reflect assembly for this JSII assembly */
assembly: reflect.Assembly;

/** The Rosetta instance */
rosetta: Rosetta;

/**
* Whether to fingerprint the produced artifacts.
* @default true
Expand Down
3 changes: 2 additions & 1 deletion packages/jsii-pacmak/lib/targets/java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ export class JavaBuilder implements TargetBuilder {
assembly: module.assembly,
fingerprint: options.fingerprint,
force: options.force,
arguments: options.arguments
arguments: options.arguments,
rosetta: options.rosetta,
});
}

Expand Down
Loading