project initialized

This commit is contained in:
crusader 2020-12-02 16:25:54 +09:00
commit 0f951c1c11
24 changed files with 3488 additions and 0 deletions

2
.eslintignore Normal file
View File

@ -0,0 +1,2 @@
build/
dist/

3
.eslintrc.json Normal file
View File

@ -0,0 +1,3 @@
{
"extends": "./node_modules/gts/"
}

4
.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
node_modules
build/
dist/
pack/

4
.npmignore Normal file
View File

@ -0,0 +1,4 @@
node_modules
build/
dist/
pack/

3
.prettierrc.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
...require('gts/.prettierrc.json'),
};

14
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.autoClosingBrackets": "languageDefined",
"editor.trimAutoWhitespace": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
"files.watcherExclude": {
"**/dist": true
}
}

3196
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

32
package.json Normal file
View File

@ -0,0 +1,32 @@
{
"name": "typescript-skeleton",
"version": "0.0.0",
"private": true,
"description": "",
"license": "Apache-2.0",
"keywords": [],
"scripts": {
"lint": "gts lint",
"clean": "gts clean",
"fix": "gts fix",
"build:lib1": "ts-node ./scripts/build.ts lib1",
"build:lib2": "ts-node ./scripts/build.ts lib2"
},
"peerDependencies": {
"lodash": "^4.17.20",
"rxjs": "^6.6.3"
},
"devDependencies": {
"@types/fs-extra": "^9.0.4",
"@types/lodash": "^4.14.165",
"@types/node": "^14.11.2",
"cross-env": "^7.0.2",
"fs-extra": "^9.0.1",
"gts": "^3.0.2",
"husky": "^4.3.0",
"npm-run-all": "^4.1.5",
"rimraf": "^3.0.2",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
}
}

View File

@ -0,0 +1,7 @@
{
"name": "lib1",
"version": "0.0.1",
"peerDependencies": {
}
}

View File

@ -0,0 +1,6 @@
{
"dest": "../../dist/lib1",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@ -0,0 +1,3 @@
export class Lib1 {
constructor() {}
}

View File

@ -0,0 +1 @@
export * from './lib/lib1';

View File

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"lib": ["dom"]
},
"exclude": ["src/test.ts", "**/*.spec.ts"]
}

View File

@ -0,0 +1,3 @@
{
"extends": "./tsconfig.lib.json"
}

View File

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": ["jasmine", "node"]
},
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}

View File

@ -0,0 +1,5 @@
{
"name": "lib2",
"version": "0.0.1",
"peerDependencies": {}
}

View File

@ -0,0 +1,6 @@
{
"dest": "../../dist/lib2",
"lib": {
"entryFile": "src/public-api.ts"
}
}

View File

@ -0,0 +1,3 @@
export class Lib2 {
constructor() {}
}

View File

@ -0,0 +1 @@
export * from './lib/lib2';

View File

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"lib": ["dom"]
},
"exclude": ["src/test.ts", "**/*.spec.ts"]
}

View File

@ -0,0 +1,3 @@
{
"extends": "./tsconfig.lib.json"
}

View File

@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": ["jasmine", "node"]
},
"files": ["src/test.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}

148
scripts/build.ts Normal file
View File

@ -0,0 +1,148 @@
import * as path from 'path';
import {execSync} from 'child_process';
import * as fse from 'fs-extra';
async function build(args: string[]): Promise<any[]> {
const rootPath = path.join(__dirname, '..');
const packPath = path.join(rootPath, 'pack');
const projectName = args[0];
const projectPath = path.join(rootPath, 'projects', projectName);
const packageJson = require(path.join(projectPath, 'package.json'));
const projectJson = require(path.join(projectPath, 'project.json'));
const tsconfigJsonPath = path.join(projectPath, 'tsconfig.lib.prod.json');
const distPath = path.join(projectPath, projectJson.dest);
const clean = () =>
new Promise<void>((resolve, reject) => {
try {
console.log(`Cleaning is started.`);
execSync(`rimraf ${distPath}`, {stdio: 'inherit'});
console.log(`Cleaning is completed.`);
resolve();
} catch (e) {
reject(e);
}
});
const declaration = () =>
new Promise<void>((resolve, reject) => {
try {
const outDir = path.join(distPath, 'types');
console.log(`Generating typescript declaration files is started.`);
execSync(
`tsc --project ${tsconfigJsonPath} --module commonjs --target es5 --declaration true --emitDeclarationOnly --outDir ${outDir}`,
{stdio: 'inherit'}
);
console.log(`Generating typescript declaration files is completed.`);
resolve();
} catch (e) {
reject(e);
}
});
const transpile = (
name: string,
dirName: string,
moduleName: string,
targetName: string
) =>
new Promise<void>((resolve, reject) => {
try {
let out = '';
switch (moduleName.toLowerCase()) {
case 'amd':
case 'system':
out = `--outFile ${path.join(distPath, dirName, 'public-api.js')}`;
break;
default:
out = `--outDir ${path.join(distPath, dirName)}`;
break;
}
const outDir = path.join(distPath, dirName);
console.log(`Generating typescript ${name} module is started.`);
execSync(
`tsc --project ${tsconfigJsonPath} --module ${moduleName} --target ${targetName} ${out}`,
{stdio: 'inherit'}
);
console.log(`Generating typescript ${name} module is completed.`);
resolve();
} catch (e) {
reject(e);
}
});
const packagejson = () =>
new Promise<void>((resolve, reject) => {
try {
console.log(`Generating project package.json is started.`);
const projectPackageJson = {
...packageJson,
main: `cjs/public-api.js`,
module: `esm5/public-api.js`,
es2015: `es2015/public-api.js`,
types: `types/public-api.d.ts`,
sideEffects: false,
};
fse.writeFileSync(
path.join(distPath, 'package.json'),
JSON.stringify(projectPackageJson, null, 2)
);
console.log(`Generating project package.json is completed.`);
resolve();
} catch (e) {
reject(e);
}
});
const install2Local = () =>
new Promise<void>((resolve, reject) => {
try {
console.log(`Installing to local is started.`);
const distPackageJson = require(path.join(distPath, 'package.json'));
const packFileName = `${projectName}-${distPackageJson.version}.tgz`;
const distFilePath = path.join(distPath, packFileName);
const packFilePath = path.join(packPath, packFileName);
process.chdir(path.join(distPath));
execSync(`npm pack`, {stdio: 'inherit'});
fse.moveSync(distFilePath, packFilePath, {
overwrite: true,
});
process.chdir(path.join(rootPath));
execSync(`npm install -D ${packFilePath}`, {
stdio: 'inherit',
});
console.log(`Installing to local is completed.`);
resolve();
} catch (e) {
reject(e);
}
});
return Promise.all([
clean(),
declaration(),
transpile('commonjs', 'cjs', 'commonjs', 'es5'),
transpile('amd', 'amd', 'amd', 'es5'),
transpile('umd', 'umd', 'umd', 'es5'),
transpile('ESM5', 'esm5', 'es2015', 'es5'),
transpile('ES2015', 'es2015', 'es2015', 'es2015'),
packagejson(),
install2Local(),
]);
}
build(process.argv.slice(2))
.then()
.catch(reason => {
console.error(reason);
});

8
tsconfig.json Normal file
View File

@ -0,0 +1,8 @@
{
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"baseUrl": "./",
"declaration": false,
"moduleResolution": "node"
}
}