Commit e9e15ee8 authored by Zhexuan Chen's avatar Zhexuan Chen

Setup project structure

parents
node_modules/
/.vscode/
/.idea/
/dist/*
!/dist/tcb/
/dist/tcb/*
!/dist/tcb/.keep
.DS_Store
{
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
}
# TCB for Cocos Creator 3.0
import path from 'path';
import fs from 'fs';
import gulp from 'gulp';
import ts from 'gulp-typescript';
import sass from 'gulp-sass';
import yarn from 'gulp-yarn';
import del from 'del';
import sourcemaps from 'gulp-sourcemaps';
import terser from 'gulp-terser';
const gulpif = require('gulp-if');
const javascriptObfuscator = require('gulp-javascript-obfuscator');
const packageJson = require('./package.json');
const resources = [
'./resource/**/*',
'./resource/**/.*',
'./src/**/*.html',
'./upgrade.js',
];
const scssFiles = './src/**/*.scss';
const serviceName = packageJson.name.replace('service-', '');
const distDir = `./dist/${serviceName}`;
const cleanGlobs = [`${distDir}/**/*`, `!${distDir}/.keep`];
const isProdEnv = (process.env.NODE_ENV || 'development') === 'production';
export function clean() {
return del(cleanGlobs);
}
export function cleanWithoutNodeModules() {
return del([...cleanGlobs, `!${distDir}/node_modules`]);
}
function copyResources() {
return gulp
.src(resources, {
base: './',
})
.pipe(gulp.dest(distDir));
}
function compileScss() {
return gulp
.src(scssFiles, {
base: './',
})
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(distDir));
}
function compileTs() {
const tsProject = ts.createProject('./tsconfig.json');
return tsProject
.src()
.pipe(gulpif(!isProdEnv, sourcemaps.init()))
.pipe(tsProject())
.js.pipe(sourcemaps.write('./'))
.pipe(gulpif(isProdEnv, terser()))
.pipe(gulpif(isProdEnv, javascriptObfuscator()))
.pipe(gulp.dest(distDir));
}
function installDeps() {
return gulp
.src(['./package.json', './yarn.lock'])
.pipe(gulp.dest(distDir))
.pipe(
yarn({
// Don't install dev deps.
production: true,
})
);
}
async function removeVueDep() {
// Remove Vue and .yarn-integrity from node_modules, force Vue to be re-installed.
// For the reason, see also: removeUnusedVueDistFiles.
return Promise.all([
fs.promises.rmdir(path.join(distDir, './node_modules/vue'), {
recursive: true,
}),
fs.promises
.unlink(path.join(distDir, './node_modules/.yarn-integrity'))
.catch((e) => {}),
]);
}
async function enableVueRuntimeCompiler() {
const packagePath = path.join(distDir, './node_modules/vue/package.json');
const fileContent = await fs.promises.readFile(packagePath, 'utf8');
return fs.promises.writeFile(
packagePath,
fileContent.replace(
/"main":.*,/,
`"main": "dist/${isProdEnv ? 'vue.min.js' : 'vue.js'}",`
)
);
}
async function removeUnusedVueDistFiles() {
const vueDistPath = path.join(distDir, './node_modules/vue/dist');
const fileNeeded = isProdEnv ? 'vue.min.js' : 'vue.js';
const files = await fs.promises.readdir(vueDistPath);
const filesToBeRemoved = files.filter((filePath) => filePath != fileNeeded);
const removeFilePromises = filesToBeRemoved.map((file) => {
return fs.promises.unlink(path.join(vueDistPath, file));
});
return Promise.all(removeFilePromises);
}
export default async function defaultTask(done: (error?: any) => void) {
// Writing in this strange way is due to #2512.
// See: https://github.com/gulpjs/gulp/issues/2512
return gulp.series(
cleanWithoutNodeModules,
gulp.parallel(copyResources, compileTs, compileScss),
removeVueDep,
installDeps,
enableVueRuntimeCompiler,
removeUnusedVueDistFiles
)(done);
}
export function watch() {
gulp.watch(resources, copyResources);
gulp.watch(require('./tsconfig.json').include, compileTs);
gulp.watch(scssFiles, compileScss);
}
'use strict';
const trMap = {
'info-title': 'Info',
};
export = trMap;
'use strict';
const trMap = {
'info-title': '提示',
};
export = trMap;
'use-strict';
const fs = require('fs');
const archiver = require('archiver');
const packageJson = require('./package.json');
const name = packageJson.name.replace('service-', '');
const version = packageJson.version;
const releaseDir = './dist';
const releaseFile = `${releaseDir}/${name}_${version}.zip`;
const targetDir = `${releaseDir}/${name}`;
if (fs.existsSync(releaseFile)) {
console.log(`Remove previous release file: ${releaseFile} ...`);
fs.unlinkSync(releaseFile);
}
const output = fs.createWriteStream(releaseFile);
let archive = archiver('zip', {
zlib: { level: 9 },
});
output.on('close', () => {
console.log(`Release archive has been created: ${releaseFile}`);
console.log(archive.pointer() + ' total bytes');
});
output.on('end', function () {
console.log('Data has been drained');
});
archive.pipe(output);
archive.directory(targetDir, false);
archive.finalize();
{
"name": "service-tcb",
"version": "3.0.0_1.3.3",
"author": "zhexuan.chen@chukong-inc.com",
"upgrade": "./upgrade.js",
"contents": {
"detail": {
"main": "./src/detail/detail.js",
"disables": []
}
},
"builder": {
"main": "./src/builder/builder.js",
"native": true
},
"scripts": {
"build": "gulp",
"clean": "gulp clean",
"watch": "gulp && gulp watch",
"release": "cross-env NODE_ENV=production gulp && node ./pack.js"
},
"devDependencies": {
"@types/gulp": "^4.0.8",
"@types/gulp-sass": "^4.0.0",
"@types/gulp-sourcemaps": "^0.0.34",
"@types/gulp-terser": "^1.2.1",
"del": "^6.0.0",
"gulp": "^4.0.2",
"gulp-if": "^3.0.0",
"gulp-javascript-obfuscator": "^1.1.6",
"gulp-sass": "^4.1.0",
"gulp-sourcemaps": "^3.0.0",
"gulp-terser": "^2.0.1",
"gulp-typescript": "^6.0.0-alpha.1",
"gulp-yarn": "^2.0.0",
"ts-node": "^9.1.1",
"typescript": "^4.1.3"
},
"dependencies": {
"fs-extra": "^9.0.1",
"vue": "^2.6.12",
"vue-class-component": "^7.2.6",
"vue-property-decorator": "^9.1.2"
}
}
'use strict';
class Builder {
constructor(private projectPath: string, private configInfo: any) {
}
onServiceStatusChanged() {
if (this.configInfo.enable) {
return this.onEnableService();
} else {
return this.onDisableService();
}
}
async onEnableService() {
}
async onDisableService() {
}
}
let builder: Builder | null = null;
export async function onServiceStatusChanged(
projectPath: string,
configInfo: any
) {
builder = new Builder(projectPath, configInfo);
builder.onServiceStatusChanged();
}
<div :key="forceReRenderKey">
Test
</div>
@import '../global';
'use strict';
import { Component, Mixins } from 'vue-property-decorator';
import { readFile } from '../../lib/file';
import TrMixin from '../mixin/tr-mixin';
@Component({
template: readFile(__dirname, './detail-app.html'),
components: {
},
})
export default class DetailApp extends Mixins(TrMixin) {
forceReRenderKey = 0;
beforeDestroy() {
Editor.Message.removeBroadcastListener(
'i18n:change',
this.onLanguageChanged
);
}
onLanguageChanged() {
this.forceReRenderKey += 1;
}
}
$ns: 'service-tcb';
import { Component, Vue } from 'vue-property-decorator';
import { tr } from '../../lib/translate';
@Component
export default class TrMixin extends Vue {
tr(key: string): string {
return tr(key);
}
}
<div id="detail">
<detail-app v-show="showDetail" :key="forceUpdateKey"></detail-app>
</div>
@import '../component/detail-app/detail-app';
'use strict';
import { readFile } from '../lib/file';
import Vue from 'vue';
import DetailApp from '../component/detail-app/detail-app';
import { getCcService, setCcService } from '../lib/cc-service';
export const template: string = readFile(__dirname, './detail.html');
export const style: string = readFile(__dirname, './detail.css');
interface ThisType {
$: {
detail: HTMLEmbedElement;
};
}
export const $: any = {
detail: '#detail',
};
export const methods = {};
export async function load(this: ThisType, ccService: any) {
setCcService(ccService);
}
let forceUpdateKey = 1;
let app: Vue | null = null;
export async function ready(
this: ThisType,
info: { game: any; service: any; param: any }
) {
if (!app) {
app = new Vue({
el: this.$.detail,
data: {
forceUpdateKey,
showDetail: true,
},
components: {
'detail-app': DetailApp,
},
});
} else {
forceUpdateKey += 1;
Vue.set(app, 'forceUpdateKey', forceUpdateKey);
Vue.set(app, 'showDetail', true);
}
}
export async function close() {
if (app) {
Vue.set(app, 'showDetail', false);
}
}
'use strict';
let cachedCcService: any = null;
declare const ccService: any;
// global variables may expired in the main process, but they won't be expire in
// worker processes. As a workaround, we cache the ccService (passed by the
// detail page) in the main process and use the ccService global variable as a
// fallback.
export function setCcService(service: any) {
cachedCcService = service;
}
export function getCcService() {
return cachedCcService || ccService;
}
'use strict';
import fse from 'fs';
import path from 'path';
export function readFile(...paths: string[]) {
return fse.readFileSync(path.join(...paths), 'utf-8');
}
'use strict';
import { getCcService } from './cc-service';
export function tr(key: string): string {
const ccService = getCcService();
return ccService.pluginTr('service-tcb', key);
}
{
"compilerOptions": {
"target": "ES2017",
"module": "commonjs",
"sourceMap": true,
"strict": true,
"esModuleInterop": true,
"removeComments": true,
"skipLibCheck": true,
"experimentalDecorators": true,
"rootDir": "./",
"outDir": "./dist",
"types": ["node", "./type/index"]
},
"include": ["./i18n/**/*.ts", "./src/**/*.ts"]
}
'use strict';
module.exports = {
zh: `
新增 TCB 服务集成。
`,
en: `
Add integration of TCB.
`,
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment